Skip to content

Commit

Permalink
[iOS] Fixes SplashScreenView crash when remove from view hierarchy (f…
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongwuzw authored Jul 29, 2022
1 parent 0113223 commit 260d979
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ FLUTTER_DARWIN_EXPORT

/**
* Specifies the view to use as a splash screen. Flutter's rendering is asynchronous, so the first
* frame rendered by the Flutter application might not immediately appear when theFlutter view is
* frame rendered by the Flutter application might not immediately appear when the Flutter view is
* initially placed in the view hierarchy. The splash screen view will be used as
* a replacement until the first frame is rendered.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,14 +507,15 @@ - (void)callViewRenderedCallback {

- (void)removeSplashScreenView:(dispatch_block_t _Nullable)onComplete {
NSAssert(_splashScreenView, @"The splash screen view must not be null");
UIView* splashScreen = _splashScreenView.get();
UIView* splashScreen = [_splashScreenView.get() retain];
_splashScreenView.reset();
[UIView animateWithDuration:0.2
animations:^{
splashScreen.alpha = 0;
}
completion:^(BOOL finished) {
[splashScreen removeFromSuperview];
[splashScreen release];
if (onComplete) {
onComplete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,15 @@ - (void)testViewDidLoadDoesntInvokeEngineAttachViewWhenEngineNeedsLaunch {
OCMVerify(never(), [mockEngine attachView]);
}

- (void)testSplashScreenViewRemoveNotCrash {
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"engine" project:nil];
[engine runWithEntrypoint:nil];
FlutterViewController* flutterViewController =
[[FlutterViewController alloc] initWithEngine:engine nibName:nil bundle:nil];
[flutterViewController setSplashScreenView:[[UIView alloc] init]];
[flutterViewController setSplashScreenView:nil];
}

- (void)testInternalPluginsWeakPtrNotCrash {
FlutterSendKeyEvent sendEvent;
@autoreleasepool {
Expand Down

0 comments on commit 260d979

Please sign in to comment.