Skip to content

Commit

Permalink
Merge pull request #234 from binhndicts/master
Browse files Browse the repository at this point in the history
[iOS] Add 1 more solution
  • Loading branch information
crazycodeboy committed Feb 7, 2019
2 parents 52689d0 + 4216409 commit d44ffef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions ios/RNSplashScreen.h
Expand Up @@ -7,8 +7,10 @@
* Email:crazycodeboy@gmail.com
*/
#import <React/RCTBridgeModule.h>
#import <UIKit/UIKit.h>

@interface RNSplashScreen : NSObject<RCTBridgeModule>
+ (void)showSplash:(NSString*)splashScreen inRootView:(UIView*)rootView;
+ (void)show;
+ (void)hide;
@end
26 changes: 22 additions & 4 deletions ios/RNSplashScreen.m
Expand Up @@ -12,6 +12,7 @@

static bool waiting = true;
static bool addedJsLoadErrorObserver = false;
static UIView* loadingView = nil;

@implementation RNSplashScreen
- (dispatch_queue_t)methodQueue{
Expand All @@ -31,11 +32,28 @@ + (void)show {
}
}

+ (void)showSplash:(NSString*)splashScreen inRootView:(UIView*)rootView {
if (!loadingView) {
loadingView = [[[NSBundle mainBundle] loadNibNamed:splashScreen owner:self options:nil] objectAtIndex:0];
CGRect frame = rootView.frame;
frame.origin = CGPointMake(0, 0);
loadingView.frame = frame;
}
waiting = false;

[rootView addSubview:loadingView];
}

+ (void)hide {
dispatch_async(dispatch_get_main_queue(),
^{
waiting = false;
});
if (waiting) {
dispatch_async(dispatch_get_main_queue(), ^{
waiting = false;
});
} else {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[loadingView removeFromSuperview];
});
}
}

+ (void) jsLoadError:(NSNotification*)notification
Expand Down

0 comments on commit d44ffef

Please sign in to comment.