Skip to content

Commit

Permalink
[iOS] Ensure SplashScreenView hides only once for RootViewController (e…
Browse files Browse the repository at this point in the history
  • Loading branch information
bbarthec authored Sep 17, 2020
1 parent bb76ec1 commit 23fc687
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
9 changes: 0 additions & 9 deletions ios/Client/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ class AppDelegate: UMAppDelegateWrapper {

super.application(application, didFinishLaunchingWithOptions: launchOptions)

// SplashScreen module registers SplashScreenView automatically for window.rootViewController (EXRootViewController),
// and we want it to register for EXViewController (that is found in rootViewContrller view hierarchy),
// so we need to hide it for window.rootViewController
let splashScreenService: EXSplashScreenService = UMModuleRegistryProvider.getSingletonModule(for: EXSplashScreenService.self) as! EXSplashScreenService
if let rootViewController = window?.rootViewController {
splashScreenService.hideSplashScreen(for: rootViewController,
successCallback: { (success) in /* empty */ },
failureCallback: { (message) in /* empty */ })
}
return true
}

Expand Down
1 change: 0 additions & 1 deletion ios/Exponent-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@

#import <UMCore/UMAppDelegateWrapper.h>
#import <UMCore/UMModuleRegistryProvider.h>
#import <EXSplashScreen/EXSplashScreenService.h>
19 changes: 13 additions & 6 deletions ios/Exponent/Kernel/Views/EXAppViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,20 @@ - (void)_showSplashScreenWithProvider:(id<EXSplashScreenViewProvider>)provider
// the lifecycle of the splash screen we need to:
// 1. present the splash screen on EXAppViewController
// 2. hide the splash screen of root view controller
// Disclaimer:
// there's only one root view controller, but possibly many EXAppViewControllers
// (in Expo Client: one Experience -> one EXAppViewController)
// and we want to hide SplashScreen only once for the root view controller, hence the "once"
static dispatch_once_t once;
void (^hideRootViewControllerSplashScreen)(void) = ^void() {
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
[splashScreenService hideSplashScreenFor:rootViewController
successCallback:^(BOOL hasEffect){}
failureCallback:^(NSString * _Nonnull message) {
UMLogWarn(@"Hiding splash screen from root view controller did not succeed: %@", message);
}];
dispatch_once(&once, ^{
UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
[splashScreenService hideSplashScreenFor:rootViewController
successCallback:^(BOOL hasEffect){}
failureCallback:^(NSString * _Nonnull message) {
UMLogWarn(@"Hiding splash screen from root view controller did not succeed: %@", message);
}];
});
};

UM_WEAKIFY(self);
Expand Down

0 comments on commit 23fc687

Please sign in to comment.