Skip to content

Commit d44ffef

Browse files
authored
Merge pull request #234 from binhndicts/master
[iOS] Add 1 more solution
2 parents 52689d0 + 4216409 commit d44ffef

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

ios/RNSplashScreen.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
* Email:crazycodeboy@gmail.com
88
*/
99
#import <React/RCTBridgeModule.h>
10+
#import <UIKit/UIKit.h>
1011

1112
@interface RNSplashScreen : NSObject<RCTBridgeModule>
13+
+ (void)showSplash:(NSString*)splashScreen inRootView:(UIView*)rootView;
1214
+ (void)show;
1315
+ (void)hide;
1416
@end

ios/RNSplashScreen.m

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
static bool waiting = true;
1414
static bool addedJsLoadErrorObserver = false;
15+
static UIView* loadingView = nil;
1516

1617
@implementation RNSplashScreen
1718
- (dispatch_queue_t)methodQueue{
@@ -31,11 +32,28 @@ + (void)show {
3132
}
3233
}
3334

35+
+ (void)showSplash:(NSString*)splashScreen inRootView:(UIView*)rootView {
36+
if (!loadingView) {
37+
loadingView = [[[NSBundle mainBundle] loadNibNamed:splashScreen owner:self options:nil] objectAtIndex:0];
38+
CGRect frame = rootView.frame;
39+
frame.origin = CGPointMake(0, 0);
40+
loadingView.frame = frame;
41+
}
42+
waiting = false;
43+
44+
[rootView addSubview:loadingView];
45+
}
46+
3447
+ (void)hide {
35-
dispatch_async(dispatch_get_main_queue(),
36-
^{
37-
waiting = false;
38-
});
48+
if (waiting) {
49+
dispatch_async(dispatch_get_main_queue(), ^{
50+
waiting = false;
51+
});
52+
} else {
53+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
54+
[loadingView removeFromSuperview];
55+
});
56+
}
3957
}
4058

4159
+ (void) jsLoadError:(NSNotification*)notification

0 commit comments

Comments
 (0)