diff --git a/ios/RNSplashScreen.h b/ios/RNSplashScreen.h index dab0939b..5cc9f16a 100644 --- a/ios/RNSplashScreen.h +++ b/ios/RNSplashScreen.h @@ -7,8 +7,10 @@ * Email:crazycodeboy@gmail.com */ #import +#import @interface RNSplashScreen : NSObject ++ (void)showSplash:(NSString*)splashScreen inRootView:(UIView*)rootView; + (void)show; + (void)hide; @end diff --git a/ios/RNSplashScreen.m b/ios/RNSplashScreen.m index 69b45a63..02bf3e51 100644 --- a/ios/RNSplashScreen.m +++ b/ios/RNSplashScreen.m @@ -12,6 +12,7 @@ static bool waiting = true; static bool addedJsLoadErrorObserver = false; +static UIView* loadingView = nil; @implementation RNSplashScreen - (dispatch_queue_t)methodQueue{ @@ -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