diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h b/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h index 49879149129c3..53f3adc855d5d 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h @@ -88,7 +88,7 @@ FLUTTER_EXPORT * * @param asset The name of the asset. The name can be hierarchical. * @param package The name of the package from which the asset originates. - * @returns: The file name to be used for lookup in the main bundle. + * @return The file name to be used for lookup in the main bundle. */ - (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package; @@ -129,15 +129,19 @@ FLUTTER_EXPORT * a replacement until the first frame is rendered. * * The view used should be appropriate for multiple sizes; an autoresizing mask to - * have a flexible - * width and height will be applied automatically. - * - * If not specified, uses a view generated from `UILaunchStoryboardName` from the - * main bundle's - * `Info.plist` file. + * have a flexible width and height will be applied automatically. */ @property(strong, nonatomic) UIView* splashScreenView; +/** + * Attempts to set the `splashScreenView` property from the `UILaunchStoryboardName` from the + * main bundle's `Info.plist` file. This method will not change the value of `splashScreenView` + * if it cannot find a default one from a storyboard or nib. + * + * @return `YES` if successful, `NO` otherwise. + */ +- (BOOL)loadDefaultSplashScreenView; + /** * Controls whether the created view will be opaque or not. * diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 80e03e28bd8bf..3fb58d709f270 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -239,7 +239,7 @@ - (void)loadView { - (void)installSplashScreenViewIfNecessary { // Show the launch screen view again on top of the FlutterView if available. // This launch screen view will be removed once the first Flutter frame is rendered. - if (self.isBeingPresented || self.isMovingToParentViewController) { + if (_splashScreenView && (self.isBeingPresented || self.isMovingToParentViewController)) { [_splashScreenView.get() removeFromSuperview]; _splashScreenView.reset(); return; @@ -305,21 +305,29 @@ - (FlutterView*)flutterView { } - (UIView*)splashScreenView { - if (_splashScreenView == nullptr) { - NSString* launchscreenName = - [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UILaunchStoryboardName"]; - if (launchscreenName == nil) { - return nil; - } - UIView* splashView = [self splashScreenFromStoryboard:launchscreenName]; - if (!splashView) { - splashView = [self splashScreenFromXib:launchscreenName]; - } - self.splashScreenView = splashView; + if (!_splashScreenView) { + return nil; } return _splashScreenView.get(); } +- (BOOL)loadDefaultSplashScreenView { + NSString* launchscreenName = + [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UILaunchStoryboardName"]; + if (launchscreenName == nil) { + return NO; + } + UIView* splashView = [self splashScreenFromStoryboard:launchscreenName]; + if (!splashView) { + splashView = [self splashScreenFromXib:launchscreenName]; + } + if (!splashView) { + return NO; + } + self.splashScreenView = splashView; + return YES; +} + - (UIView*)splashScreenFromStoryboard:(NSString*)name { UIStoryboard* storyboard = nil; @try { @@ -347,16 +355,10 @@ - (void)setSplashScreenView:(UIView*)view { if (!view) { // Special case: user wants to remove the splash screen view. [self removeSplashScreenViewIfPresent]; - } else if (_splashScreenView) { - FML_LOG(ERROR) << "Attempt to set the FlutterViewController's splash screen multiple times was " - "ignored. The FlutterViewController's splash screen can only be set once. " - "This condition can occur if a running FlutterEngine instance has been " - "passed into the FlutterViewController and a consumer later called " - "[FlutterViewController setSplashScreen:]. Setting the splash screen on a " - "FlutterViewController with an already running engine is not supported, as " - "the rasterizer will already be running by the time the view is shown."; + _splashScreenView.reset(); return; } + _splashScreenView.reset([view retain]); _splashScreenView.get().autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;