Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using native splash screen #1

Merged
merged 2 commits into from
Jun 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ios/SplashScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
* Email:crazycodeboy@gmail.com
*/
#import <React/RCTBridgeModule.h>
#import <UIKit/UIKit.h>

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

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

@implementation SplashScreen
- (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