[iOS] Fixes SplashScreenView crash when remove from view hierarchy (flutter/engine#34496)

This commit is contained in:
Wu Zhong
2022-07-29 10:11:04 +08:00
committed by GitHub
parent 38194c973d
commit 42f499b4f0
3 changed files with 12 additions and 2 deletions

View File

@@ -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.
*

View File

@@ -507,7 +507,7 @@ static void SendFakeTouchEvent(FlutterEngine* engine,
- (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:^{
@@ -515,6 +515,7 @@ static void SendFakeTouchEvent(FlutterEngine* engine,
}
completion:^(BOOL finished) {
[splashScreen removeFromSuperview];
[splashScreen release];
if (onComplete) {
onComplete();
}

View File

@@ -433,6 +433,15 @@ extern NSNotificationName const FlutterViewControllerWillDealloc;
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 {