@react-native-hero/splash-screen 0.0.2 → 0.1.1

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 flash screen.
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
- [RNTSplashScreen show];
56
+ [super application:application didFinishLaunchingWithOptions:launchOptions];
57
+ [RNTSplashScreen show:self.window.rootViewController.view storyboardName:@"LaunchScreen"];
57
58
  return YES;
58
59
  }
59
60
  ```
@@ -3,8 +3,8 @@ buildscript {
3
3
  def kotlinVersion = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : '1.3.40'
4
4
 
5
5
  repositories {
6
- jcenter()
7
6
  google()
7
+ mavenCentral()
8
8
  }
9
9
 
10
10
  dependencies {
@@ -38,4 +38,4 @@ dependencies {
38
38
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${safeExtGet('kotlinVersion', '1.3.40')}"
39
39
  }
40
40
 
41
- apply plugin: 'kotlin-android'
41
+ apply plugin: 'kotlin-android'
@@ -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
@@ -3,10 +3,6 @@ import { NativeModules } from 'react-native'
3
3
 
4
4
  const { RNTSplashScreen } = NativeModules
5
5
 
6
- export function show() {
7
- RNTSplashScreen.show()
8
- }
9
-
10
6
  export function hide() {
11
7
  RNTSplashScreen.hide()
12
8
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  @interface RNTSplashScreen : NSObject <RCTBridgeModule>
4
4
 
5
- + (void)show;
5
+ + (void)show:(UIView *)rootView storyboardName:(NSString *)storyboardName;
6
6
  + (void)hide;
7
7
 
8
8
  @end
@@ -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 hasJavaScriptErrorObserver = NO;
7
-
7
+ static BOOL hasJavaScriptDidFailToLoadObserver = NO;
8
+ static BOOL hasContentDidAppearObserver = YES;
8
9
  static BOOL isShowing = NO;
9
10
 
10
- RCT_EXPORT_MODULE(RNTSplashScreen);
11
+ static RCTRootView *rootView = nil;
11
12
 
12
- // 显示默认开屏
13
- + (void)show {
14
-
15
- if (isShowing) {
16
- return;
17
- }
18
-
19
- isShowing = YES;
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 (!hasJavaScriptErrorObserver) {
23
+ if (!hasJavaScriptDidFailToLoadObserver) {
22
24
 
23
- [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(onJavaScriptError:) name:RCTJavaScriptDidFailToLoadNotification
24
- object:nil
25
+ [NSNotificationCenter.defaultCenter addObserver:self
26
+ selector:@selector(onJavaScriptDidFailToLoad:)
27
+ name:RCTJavaScriptDidFailToLoadNotification
28
+ object:nil
25
29
  ];
26
30
 
27
- hasJavaScriptErrorObserver = YES;
31
+ hasJavaScriptDidFailToLoadObserver = YES;
28
32
 
29
33
  }
30
-
31
- while (isShowing) {
32
- [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
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 (hasJavaScriptErrorObserver) {
65
+ if (hasJavaScriptDidFailToLoadObserver) {
46
66
 
47
- [NSNotificationCenter.defaultCenter removeObserver:self name:RCTJavaScriptDidFailToLoadNotification
48
- object:nil
67
+ [NSNotificationCenter.defaultCenter removeObserver:self
68
+ name:RCTJavaScriptDidFailToLoadNotification
69
+ object:nil
49
70
  ];
50
-
51
- hasJavaScriptErrorObserver = NO;
71
+
72
+ hasJavaScriptDidFailToLoadObserver = NO;
52
73
 
53
74
  }
54
75
 
55
76
  }
56
77
 
57
- + (void)onJavaScriptError:(NSNotification *)notification {
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-hero/splash-screen",
3
- "version": "0.0.2",
3
+ "version": "0.1.1",
4
4
  "description": "react native splash screen",
5
5
  "main": "index.js",
6
6
  "scripts": {