@react-native-hero/splash-screen 0.0.1 → 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
@@ -1 +1,86 @@
1
- # testing
1
+ # @react-native-hero/splash-screen
2
+
3
+ ## Getting started
4
+
5
+ Install the library using either Yarn:
6
+
7
+ ```
8
+ yarn add @react-native-hero/splash-screen
9
+ ```
10
+
11
+ or npm:
12
+
13
+ ```
14
+ npm install --save @react-native-hero/splash-screen
15
+ ```
16
+
17
+ ## Link
18
+
19
+ - React Native v0.60+
20
+
21
+ For iOS, use `cocoapods` to link the package.
22
+
23
+ run the following command:
24
+
25
+ ```
26
+ $ cd ios && pod install
27
+ ```
28
+
29
+ For android, the package will be linked automatically on build.
30
+
31
+ - React Native <= 0.59
32
+
33
+ run the following command to link the package:
34
+
35
+ ```
36
+ $ react-native link @react-native-hero/splash-screen
37
+ ```
38
+
39
+ ## Setup
40
+
41
+ Make sure you understand the native layout, this module does not support image as a splash screen.
42
+
43
+ * iOS: LaunchScreen.xib
44
+ * Android: android/app/src/main/res/layout/splash_screen_default.xml
45
+
46
+ ### iOS
47
+
48
+ `AppDelegate.m`
49
+
50
+ ```objective-c
51
+ #import <RNTSplashScreen.h>
52
+
53
+ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
54
+ {
55
+ ...
56
+ [super application:application didFinishLaunchingWithOptions:launchOptions];
57
+ [RNTSplashScreen show:self.window.rootViewController.view storyboardName:@"LaunchScreen"];
58
+ return YES;
59
+ }
60
+ ```
61
+
62
+ ### Android
63
+
64
+ `MainActivity.kt`
65
+
66
+ ```kotlin
67
+ import com.github.reactnativehero.splashscreen.RNTSplashScreenModule
68
+
69
+ class MainActivity : ReactActivity() {
70
+ override fun onCreate(savedInstanceState: Bundle?) {
71
+ super.onCreate(savedInstanceState)
72
+ RNTSplashScreenModule.show(this)
73
+ }
74
+ }
75
+ ```
76
+
77
+ ## Example
78
+
79
+ ```js
80
+ import {
81
+ hide,
82
+ } from '@react-native-hero/splash-screen'
83
+
84
+ // Call hide method after your data or view is ready.
85
+ hide()
86
+ ```
@@ -10,11 +10,6 @@ class RNTSplashScreenModule(private val reactContext: ReactApplicationContext) :
10
10
  return "RNTSplashScreen"
11
11
  }
12
12
 
13
- @ReactMethod
14
- fun show() {
15
- RNTSplashScreenModule.show(reactContext)
16
- }
17
-
18
13
  @ReactMethod
19
14
  fun hide() {
20
15
  RNTSplashScreenModule.hide()
@@ -24,7 +19,7 @@ class RNTSplashScreenModule(private val reactContext: ReactApplicationContext) :
24
19
 
25
20
  private var sharedDialog: Dialog? = null
26
21
 
27
- fun show(context: Context) {
22
+ @JvmStatic fun show(context: Context) {
28
23
 
29
24
  val dialog = Dialog(context, R.style.splash_screen_default)
30
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,67 +1,102 @@
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
+
33
43
  }
34
44
 
45
+ if (isShowing) {
46
+ return;
47
+ }
48
+
49
+ rootView = (RCTRootView *)view;
50
+
51
+ [self showLoadingView:storyboardName];
52
+ isShowing = YES;
53
+
35
54
  }
36
55
 
37
56
  + (void)hide {
38
57
 
39
- if (isShowing) {
58
+ if (!isShowing) {
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 {
58
- [RNTSplashScreen hide];
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
+ });
59
92
  }
60
93
 
61
- RCT_EXPORT_METHOD(show) {
62
- [RNTSplashScreen show];
94
+ + (void)onJavaScriptDidFailToLoad:(NSNotification *)notification {
95
+ [RNTSplashScreen hide];
63
96
  }
64
97
 
98
+ RCT_EXPORT_MODULE(RNTSplashScreen);
99
+
65
100
  RCT_EXPORT_METHOD(hide) {
66
101
  [RNTSplashScreen hide];
67
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-hero/splash-screen",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "react native splash screen",
5
5
  "main": "index.js",
6
6
  "scripts": {