Skip to content

Commit 54c9eb6

Browse files
authored
Using splash screen as rootViewController as clean up (#8134)
* fix for temporary black screen after launchscreen * comments added * Even better solution, set the splash screen as the rootviewcontroller
1 parent 45538b3 commit 54c9eb6

File tree

3 files changed

+14
-24
lines changed

3 files changed

+14
-24
lines changed

lib/ios/RNNSplashScreenViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
@interface RNNSplashScreenViewController : UIViewController
55

66
+ (void)showOnWindow:(UIWindow *)window;
7-
7+
+ (UIViewController*)getSplashScreenVC;
88
@end

lib/ios/RNNSplashScreenViewController.mm

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
@implementation RNNSplashScreenViewController
66

77
+ (void)showOnWindow:(UIWindow *)window {
8+
UIViewController *viewController = [self getSplashScreenVC];
9+
if (viewController != nil) {
10+
id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
11+
appDelegate.window.rootViewController = viewController;
12+
[appDelegate.window makeKeyAndVisible];
13+
}
14+
}
15+
16+
+ (UIViewController*)getSplashScreenVC {
817
CGRect screenBounds = [UIScreen mainScreen].bounds;
918
CGFloat screenScale = [UIScreen mainScreen].scale;
1019
UIViewController *viewController = nil;
@@ -82,11 +91,7 @@ + (void)showOnWindow:(UIWindow *)window {
8291
}
8392
}
8493

85-
if (viewController != nil) {
86-
id<UIApplicationDelegate> appDelegate = [UIApplication sharedApplication].delegate;
87-
appDelegate.window.rootViewController = viewController;
88-
[appDelegate.window makeKeyAndVisible];
89-
}
94+
return viewController;
9095
}
9196

9297
- (UIStatusBarStyle)preferredStatusBarStyle {

lib/ios/TurboModules/RNNTurboManager.mm

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#import "RNNReactRootViewCreator.h"
1111
#import "RNNTurboCommandsHandler.h"
1212
#import <React-RuntimeApple/ReactCommon/RCTHost.h>
13-
13+
#import "RNNSplashScreenViewController.h"
1414

1515
@interface RNNTurboManager ()
1616
@property(nonatomic, strong, readwrite) RNNExternalComponentStore *store;
@@ -25,13 +25,11 @@ @interface RNNTurboManager ()
2525

2626
@implementation RNNTurboManager {
2727
UIWindow *_mainWindow;
28-
BOOL _isInitialRun;
2928
}
3029

3130
- (instancetype)initWithHost:(RCTHost *)host mainWindow:(UIWindow *)mainWindow {
3231
if (self = [super init]) {
33-
_isInitialRun = YES;
34-
_host = host;
32+
_host = host;
3533
_mainWindow = mainWindow;
3634
_overlayManager = [RNNOverlayManager new];
3735
_store = [RNNExternalComponentStore new];
@@ -41,11 +39,6 @@ - (instancetype)initWithHost:(RCTHost *)host mainWindow:(UIWindow *)mainWindow {
4139
name:@"RCTInstanceDidLoadBundle"
4240
object:nil];
4341

44-
[[NSNotificationCenter defaultCenter] addObserver:self
45-
selector:@selector(onReload)
46-
name:@"RCTTriggerReloadCommandNotification"
47-
object:nil];
48-
4942
// TODO: investigate which new event is fired
5043
[[NSNotificationCenter defaultCenter] addObserver:self
5144
selector:@selector(onJavaScriptWillLoad)
@@ -106,12 +99,7 @@ - (void)onJavaScriptWillLoad {
10699

107100
- (void)onJavaScriptLoaded {
108101
RCTExecuteOnMainQueue(^{
109-
// TODO: the isInitialRun is the right and final answer for this, this will stop a blackscreen appearing after the splashscreen on startup. OnReload this will still happen because of the rootViewController = nil; which is needed to clean up what is already appearing.
110-
if (!self->_isInitialRun) {
111-
UIApplication.sharedApplication.delegate.window.rootViewController = nil;
112-
}
113-
114-
self-> _isInitialRun = NO;
102+
UIApplication.sharedApplication.delegate.window.rootViewController = [RNNSplashScreenViewController getSplashScreenVC];
115103

116104
[self->_commandsHandler setReadyToReceiveCommands:true];
117105
// TODO: Refactor
@@ -122,8 +110,5 @@ - (void)onJavaScriptLoaded {
122110
});
123111
}
124112

125-
- (void)onReload {
126-
}
127-
128113
@end
129114
#endif

0 commit comments

Comments
 (0)