Skip to content

Commit 0b36654

Browse files
committed
Hide screen when a js loading error occurs
1 parent 108a5d7 commit 0b36654

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

ios/SplashScreen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111

1212
@interface SplashScreen : NSObject<RCTBridgeModule>
1313
+ (void)show;
14+
+ (void)hide;
1415
@end

ios/SplashScreen.m

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
*/
99

1010
#import "SplashScreen.h"
11+
#import <React/RCTBridge.h>
1112

1213
static bool waiting = true;
14+
static bool addedJsLoadErrorObserver = false;
1315

1416
@implementation SplashScreen
1517
- (dispatch_queue_t)methodQueue{
@@ -18,16 +20,32 @@ - (dispatch_queue_t)methodQueue{
1820
RCT_EXPORT_MODULE()
1921

2022
+ (void)show {
23+
if (!addedJsLoadErrorObserver) {
24+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jsLoadError:) name:RCTJavaScriptDidFailToLoadNotification object:nil];
25+
addedJsLoadErrorObserver = true;
26+
}
27+
2128
while (waiting) {
2229
NSDate* later = [NSDate dateWithTimeIntervalSinceNow:0.1];
2330
[[NSRunLoop mainRunLoop] runUntilDate:later];
2431
}
2532
}
2633

27-
RCT_EXPORT_METHOD(hide) {
34+
+ (void)hide {
2835
dispatch_async(dispatch_get_main_queue(),
2936
^{
3037
waiting = false;
3138
});
3239
}
40+
41+
+ (void) jsLoadError:(NSNotification*)notification
42+
{
43+
// If there was an error loading javascript, hide the splash screen so it can be shown. Otherwise the splash screen will remain forever, which is a hassle to debug.
44+
[SplashScreen hide];
45+
}
46+
47+
RCT_EXPORT_METHOD(hide) {
48+
[SplashScreen hide];
49+
}
50+
3351
@end

0 commit comments

Comments
 (0)