@react-native-hero/splash-screen 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ $ react-native link @react-native-hero/splash-screen
|
|
|
38
38
|
|
|
39
39
|
## Setup
|
|
40
40
|
|
|
41
|
-
Make sure you understand the native layout, this module does not support image as a
|
|
41
|
+
Make sure you understand the native layout, this module does not support image as a splash screen.
|
|
42
42
|
|
|
43
43
|
* iOS: LaunchScreen.xib
|
|
44
44
|
* Android: android/app/src/main/res/layout/splash_screen_default.xml
|
|
@@ -53,7 +53,8 @@ Make sure you understand the native layout, this module does not support image a
|
|
|
53
53
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
|
54
54
|
{
|
|
55
55
|
...
|
|
56
|
-
[
|
|
56
|
+
[super application:application didFinishLaunchingWithOptions:launchOptions];
|
|
57
|
+
[RNTSplashScreen show:self.window.rootViewController.view storyboardName:@"LaunchScreen"];
|
|
57
58
|
return YES;
|
|
58
59
|
}
|
|
59
60
|
```
|
package/android/src/main/java/com/github/reactnativehero/splashscreen/RNTSplashScreenModule.kt
CHANGED
|
@@ -19,7 +19,7 @@ class RNTSplashScreenModule(private val reactContext: ReactApplicationContext) :
|
|
|
19
19
|
|
|
20
20
|
private var sharedDialog: Dialog? = null
|
|
21
21
|
|
|
22
|
-
fun show(context: Context) {
|
|
22
|
+
@JvmStatic fun show(context: Context) {
|
|
23
23
|
|
|
24
24
|
val dialog = Dialog(context, R.style.splash_screen_default)
|
|
25
25
|
dialog.setContentView(R.layout.splash_screen_default)
|
package/index.js
CHANGED
|
@@ -1,37 +1,56 @@
|
|
|
1
1
|
#import "RNTSplashScreen.h"
|
|
2
2
|
#import <React/RCTBridge.h>
|
|
3
|
+
#import <React/RCTRootView.h>
|
|
3
4
|
|
|
4
5
|
@implementation RNTSplashScreen
|
|
5
6
|
|
|
6
|
-
static BOOL
|
|
7
|
-
|
|
7
|
+
static BOOL hasJavaScriptDidFailToLoadObserver = NO;
|
|
8
|
+
static BOOL hasContentDidAppearObserver = YES;
|
|
8
9
|
static BOOL isShowing = NO;
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
static RCTRootView *rootView = nil;
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
+ (BOOL)requiresMainQueueSetup {
|
|
14
|
+
return YES;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
- (dispatch_queue_t)methodQueue {
|
|
18
|
+
return dispatch_queue_create("com.github.reactnativehero.splash_screen", DISPATCH_QUEUE_SERIAL);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
+ (void)show:(UIView *)view storyboardName:(NSString *)storyboardName {
|
|
20
22
|
|
|
21
|
-
if (!
|
|
23
|
+
if (!hasJavaScriptDidFailToLoadObserver) {
|
|
22
24
|
|
|
23
|
-
[NSNotificationCenter.defaultCenter addObserver:self
|
|
24
|
-
|
|
25
|
+
[NSNotificationCenter.defaultCenter addObserver:self
|
|
26
|
+
selector:@selector(onJavaScriptDidFailToLoad:)
|
|
27
|
+
name:RCTJavaScriptDidFailToLoadNotification
|
|
28
|
+
object:nil
|
|
25
29
|
];
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
hasJavaScriptDidFailToLoadObserver = YES;
|
|
28
32
|
|
|
29
33
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
|
|
35
|
+
if (hasContentDidAppearObserver) {
|
|
36
|
+
|
|
37
|
+
[[NSNotificationCenter defaultCenter] removeObserver:view
|
|
38
|
+
name:RCTContentDidAppearNotification
|
|
39
|
+
object:view];
|
|
40
|
+
|
|
41
|
+
hasContentDidAppearObserver = NO;
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (isShowing) {
|
|
46
|
+
return;
|
|
33
47
|
}
|
|
34
48
|
|
|
49
|
+
rootView = (RCTRootView *)view;
|
|
50
|
+
|
|
51
|
+
[self showLoadingView:storyboardName];
|
|
52
|
+
isShowing = YES;
|
|
53
|
+
|
|
35
54
|
}
|
|
36
55
|
|
|
37
56
|
+ (void)hide {
|
|
@@ -40,24 +59,44 @@ RCT_EXPORT_MODULE(RNTSplashScreen);
|
|
|
40
59
|
return;
|
|
41
60
|
}
|
|
42
61
|
|
|
62
|
+
[self hideLoadingView];
|
|
43
63
|
isShowing = NO;
|
|
44
64
|
|
|
45
|
-
if (
|
|
65
|
+
if (hasJavaScriptDidFailToLoadObserver) {
|
|
46
66
|
|
|
47
|
-
[NSNotificationCenter.defaultCenter removeObserver:self
|
|
48
|
-
|
|
67
|
+
[NSNotificationCenter.defaultCenter removeObserver:self
|
|
68
|
+
name:RCTJavaScriptDidFailToLoadNotification
|
|
69
|
+
object:nil
|
|
49
70
|
];
|
|
50
|
-
|
|
51
|
-
|
|
71
|
+
|
|
72
|
+
hasJavaScriptDidFailToLoadObserver = NO;
|
|
52
73
|
|
|
53
74
|
}
|
|
54
75
|
|
|
55
76
|
}
|
|
56
77
|
|
|
57
|
-
+ (void)
|
|
78
|
+
+ (void)showLoadingView:(NSString *)storyboardName {
|
|
79
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
80
|
+
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
|
|
81
|
+
UIView *loadingView = [[storyboard instantiateInitialViewController] view];
|
|
82
|
+
[rootView setLoadingView:loadingView];
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
+ (void)hideLoadingView {
|
|
87
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
88
|
+
rootView.loadingView.hidden = YES;
|
|
89
|
+
[rootView.loadingView removeFromSuperview];
|
|
90
|
+
rootView.loadingView = nil;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
+ (void)onJavaScriptDidFailToLoad:(NSNotification *)notification {
|
|
58
95
|
[RNTSplashScreen hide];
|
|
59
96
|
}
|
|
60
97
|
|
|
98
|
+
RCT_EXPORT_MODULE(RNTSplashScreen);
|
|
99
|
+
|
|
61
100
|
RCT_EXPORT_METHOD(hide) {
|
|
62
101
|
[RNTSplashScreen hide];
|
|
63
102
|
}
|