react-native-bootsplash 4.1.2 → 4.1.5
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 +59 -56
- package/android/.npmignore +11 -0
- package/android/build.gradle +2 -2
- package/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModule.java +40 -72
- package/example/android/app/debug.keystore +0 -0
- package/ios/.npmignore +8 -0
- package/ios/RNBootSplash.h +1 -11
- package/ios/RNBootSplash.m +33 -77
- package/package.json +10 -7
- package/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashTask.java +0 -25
package/README.md
CHANGED
|
@@ -97,6 +97,8 @@ public class MainApplication extends Application implements ReactApplication {
|
|
|
97
97
|
|
|
98
98
|
## Setup
|
|
99
99
|
|
|
100
|
+
ℹ️ For `react-native` < `0.68` documentation, check the [`v4.1.3 README.md`](https://github.com/zoontek/react-native-bootsplash/blob/4.1.3/README.md)
|
|
101
|
+
|
|
100
102
|
### Assets generation
|
|
101
103
|
|
|
102
104
|
In order to speed up the setup, we provide a **CLI** to generate assets, create the Android Drawable XML file and the iOS Storyboard file automatically ✨.
|
|
@@ -132,6 +134,17 @@ yarn react-native generate-bootsplash assets/bootsplash_logo_original.png \
|
|
|
132
134
|
--flavor=main
|
|
133
135
|
```
|
|
134
136
|
|
|
137
|
+
#### Using an SVG
|
|
138
|
+
|
|
139
|
+
You might want to use SVG as input file. For that, you can install a CLI tool to convert your logo first:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
$ brew install librsvg # available on macOS
|
|
143
|
+
$ rsvg-convert -w 3000 bootsplash_logo.svg -o bootsplash_logo.png # create a large PNG with generous leeway for 4x Android xxxhdpi devices
|
|
144
|
+
$ react-native generate-bootsplash bootsplash_logo.png
|
|
145
|
+
$ rm bootsplash_logo.png # optionally, clean up the PNG
|
|
146
|
+
```
|
|
147
|
+
|
|
135
148
|

|
|
136
149
|
|
|
137
150
|
This tool relies on the naming conventions that are used in the `/example` project and will therefore create the following files:
|
|
@@ -159,24 +172,24 @@ ios/YourProjectName/Images.xcassets/BootSplashLogo.imageset/bootsplash_logo@3x.p
|
|
|
159
172
|
|
|
160
173
|
### iOS
|
|
161
174
|
|
|
162
|
-
_⚠️
|
|
175
|
+
_⚠️ Only `.storyboard` files are supported ([Apple has deprecated other methods in April 2020](https://developer.apple.com/news/?id=01132020b))._
|
|
176
|
+
|
|
177
|
+
---
|
|
163
178
|
|
|
164
|
-
Edit the `ios/YourProjectName/AppDelegate.
|
|
179
|
+
Edit the `ios/YourProjectName/AppDelegate.mm` file:
|
|
165
180
|
|
|
166
181
|
```obj-c
|
|
167
182
|
#import "AppDelegate.h"
|
|
168
|
-
|
|
169
|
-
#import <React/RCTBridge.h>
|
|
170
|
-
#import <React/RCTBundleURLProvider.h>
|
|
171
|
-
#import <React/RCTRootView.h>
|
|
172
|
-
|
|
173
183
|
#import "RNBootSplash.h" // <- add the header import
|
|
174
184
|
|
|
185
|
+
// …
|
|
186
|
+
|
|
175
187
|
@implementation AppDelegate
|
|
176
188
|
|
|
177
189
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
|
178
190
|
{
|
|
179
191
|
// …
|
|
192
|
+
|
|
180
193
|
rootViewController.view = rootView;
|
|
181
194
|
self.window.rootViewController = rootViewController;
|
|
182
195
|
[self.window makeKeyAndVisible];
|
|
@@ -195,12 +208,16 @@ Set the `BootSplash.storyboard` as launch screen file:
|
|
|
195
208
|
|
|
196
209
|
### Android
|
|
197
210
|
|
|
211
|
+
_⚠️ On Android 12, the splash screen will not appear if you start your app from the terminal / Android Studio. To see it, kill your app and restart it in normal conditions (tap on your app icon in the app launcher)._
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
198
215
|
1. As this library only support Android 6+, you probably have to edit your `android/build.gradle` file:
|
|
199
216
|
|
|
200
217
|
```gradle
|
|
201
218
|
buildscript {
|
|
202
219
|
ext {
|
|
203
|
-
buildToolsVersion = "
|
|
220
|
+
buildToolsVersion = "31.0.0"
|
|
204
221
|
minSdkVersion = 23 // <- AndroidX splashscreen has basic support for 21 (only the background color), so 23 is best
|
|
205
222
|
compileSdkVersion = 31 // <- set at least 31
|
|
206
223
|
targetSdkVersion = 31 // <- set at least 31
|
|
@@ -212,10 +229,9 @@ buildscript {
|
|
|
212
229
|
|
|
213
230
|
```gradle
|
|
214
231
|
dependencies {
|
|
215
|
-
|
|
216
|
-
//noinspection GradleDynamicVersion
|
|
217
|
-
implementation "com.facebook.react:react-native:+" // From node_modules
|
|
232
|
+
// …
|
|
218
233
|
|
|
234
|
+
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
|
|
219
235
|
implementation "androidx.core:core-splashscreen:1.0.0-beta01" // Add this line
|
|
220
236
|
|
|
221
237
|
// …
|
|
@@ -255,18 +271,7 @@ dependencies {
|
|
|
255
271
|
android:roundIcon="@mipmap/ic_launcher_round"
|
|
256
272
|
android:allowBackup="false"
|
|
257
273
|
android:theme="@style/BootTheme"> <!-- Replace @style/AppTheme with @style/BootTheme -->
|
|
258
|
-
|
|
259
|
-
android:name=".MainActivity"
|
|
260
|
-
android:label="@string/app_name"
|
|
261
|
-
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
|
|
262
|
-
android:launchMode="singleTask"
|
|
263
|
-
android:windowSoftInputMode="adjustResize"
|
|
264
|
-
android:exported="true"> <!-- Add android:exported="true" -->
|
|
265
|
-
<intent-filter>
|
|
266
|
-
<action android:name="android.intent.action.MAIN" />
|
|
267
|
-
<category android:name="android.intent.category.LAUNCHER" />
|
|
268
|
-
</intent-filter>
|
|
269
|
-
</activity>
|
|
274
|
+
<!-- … -->
|
|
270
275
|
</application>
|
|
271
276
|
</manifest>
|
|
272
277
|
|
|
@@ -276,23 +281,23 @@ dependencies {
|
|
|
276
281
|
|
|
277
282
|
```java
|
|
278
283
|
import com.facebook.react.ReactActivity;
|
|
279
|
-
import com.facebook.react.ReactActivityDelegate;
|
|
284
|
+
import com.facebook.react.ReactActivityDelegate;
|
|
285
|
+
import com.facebook.react.ReactRootView;
|
|
280
286
|
import com.zoontek.rnbootsplash.RNBootSplash; // <- add this necessary import
|
|
281
287
|
|
|
282
288
|
public class MainActivity extends ReactActivity {
|
|
283
289
|
|
|
284
290
|
// …
|
|
285
291
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
};
|
|
292
|
+
public static class MainActivityDelegate extends ReactActivityDelegate {
|
|
293
|
+
|
|
294
|
+
// …
|
|
295
|
+
|
|
296
|
+
@Override
|
|
297
|
+
protected void loadApp(String appKey) {
|
|
298
|
+
RNBootSplash.init(getPlainActivity()); // <- initialize the splash screen
|
|
299
|
+
super.loadApp(appKey);
|
|
300
|
+
}
|
|
296
301
|
}
|
|
297
302
|
}
|
|
298
303
|
```
|
|
@@ -316,8 +321,6 @@ RNBootSplash.hide(); // immediate
|
|
|
316
321
|
RNBootSplash.hide({ fade: true }); // fade
|
|
317
322
|
```
|
|
318
323
|
|
|
319
|
-
---
|
|
320
|
-
|
|
321
324
|
### getVisibilityStatus()
|
|
322
325
|
|
|
323
326
|
#### Method type
|
|
@@ -360,7 +363,25 @@ function App() {
|
|
|
360
363
|
|
|
361
364
|
**🤙 A more complex example is available in the [`/example` folder](example).**
|
|
362
365
|
|
|
363
|
-
|
|
366
|
+
## Using React Navigation
|
|
367
|
+
|
|
368
|
+
If you are using React Navigation, you can hide the splash screen once the navigation container and all children have finished mounting by using the `onReady` function.
|
|
369
|
+
|
|
370
|
+
```js
|
|
371
|
+
import React from "react";
|
|
372
|
+
import { NavigationContainer } from "@react-navigation/native";
|
|
373
|
+
import RNBootSplash from "react-native-bootsplash";
|
|
374
|
+
|
|
375
|
+
function App() {
|
|
376
|
+
return (
|
|
377
|
+
<NavigationContainer onReady={() => RNBootSplash.hide()}>
|
|
378
|
+
{/* content */}
|
|
379
|
+
</NavigationContainer>
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
## Testing with Jest
|
|
364
385
|
|
|
365
386
|
Testing code which uses this library requires some setup since we need to mock the native methods.
|
|
366
387
|
|
|
@@ -369,7 +390,7 @@ To add the mocks, create a file _jest/setup.js_ (or any other file name) contain
|
|
|
369
390
|
```js
|
|
370
391
|
jest.mock("react-native-bootsplash", () => {
|
|
371
392
|
return {
|
|
372
|
-
|
|
393
|
+
hide: jest.fn().mockResolvedValueOnce(),
|
|
373
394
|
getVisibilityStatus: jest.fn().mockResolvedValue("hidden"),
|
|
374
395
|
};
|
|
375
396
|
});
|
|
@@ -383,24 +404,6 @@ After that, we need to add the setup file in the jest config. You can add it und
|
|
|
383
404
|
}
|
|
384
405
|
```
|
|
385
406
|
|
|
386
|
-
### Using React Navigation
|
|
387
|
-
|
|
388
|
-
If you are using React Navigation, you can hide the splash screen once the navigation container and all children have finished mounting by using the `onReady` function.
|
|
389
|
-
|
|
390
|
-
```js
|
|
391
|
-
import React from "react";
|
|
392
|
-
import { NavigationContainer } from "@react-navigation/native";
|
|
393
|
-
import RNBootSplash from "react-native-bootsplash";
|
|
394
|
-
|
|
395
|
-
function App() {
|
|
396
|
-
return (
|
|
397
|
-
<NavigationContainer onReady={() => RNBootSplash.hide()}>
|
|
398
|
-
{/* content */}
|
|
399
|
-
</NavigationContainer>
|
|
400
|
-
);
|
|
401
|
-
}
|
|
402
|
-
```
|
|
403
|
-
|
|
404
407
|
## 🕵️♂️ Comparison with [react-native-splash-screen](https://github.com/crazycodeboy/react-native-splash-screen)
|
|
405
408
|
|
|
406
409
|
- If `react-native-splash-screen` encourages you to display an image over your application, `react-native-bootsplash` way-to-go is to design your launch screen using platforms tools.
|
package/android/build.gradle
CHANGED
|
@@ -12,7 +12,7 @@ buildscript {
|
|
|
12
12
|
mavenCentral()
|
|
13
13
|
}
|
|
14
14
|
dependencies {
|
|
15
|
-
classpath("com.android.tools.build:gradle:
|
|
15
|
+
classpath("com.android.tools.build:gradle:7.0.4")
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -21,7 +21,7 @@ apply plugin: "com.android.library"
|
|
|
21
21
|
|
|
22
22
|
android {
|
|
23
23
|
compileSdkVersion safeExtGet("compileSdkVersion", 31)
|
|
24
|
-
buildToolsVersion safeExtGet("buildToolsVersion", "
|
|
24
|
+
buildToolsVersion safeExtGet("buildToolsVersion", "31.0.0")
|
|
25
25
|
defaultConfig {
|
|
26
26
|
minSdkVersion safeExtGet("minSdkVersion", 23)
|
|
27
27
|
targetSdkVersion safeExtGet("targetSdkVersion", 31)
|
|
@@ -12,7 +12,6 @@ import androidx.core.splashscreen.SplashScreen;
|
|
|
12
12
|
import androidx.core.splashscreen.SplashScreenViewProvider;
|
|
13
13
|
|
|
14
14
|
import com.facebook.common.logging.FLog;
|
|
15
|
-
import com.facebook.react.bridge.LifecycleEventListener;
|
|
16
15
|
import com.facebook.react.bridge.Promise;
|
|
17
16
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
18
17
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
@@ -25,7 +24,7 @@ import java.util.Timer;
|
|
|
25
24
|
import java.util.TimerTask;
|
|
26
25
|
|
|
27
26
|
@ReactModule(name = RNBootSplashModule.NAME)
|
|
28
|
-
public class RNBootSplashModule extends ReactContextBaseJavaModule
|
|
27
|
+
public class RNBootSplashModule extends ReactContextBaseJavaModule {
|
|
29
28
|
|
|
30
29
|
public static final String NAME = "RNBootSplash";
|
|
31
30
|
private static final int ANIMATION_DURATION = 220;
|
|
@@ -39,15 +38,13 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
|
|
|
39
38
|
@Nullable
|
|
40
39
|
private static SplashScreen mSplashScreen = null;
|
|
41
40
|
|
|
42
|
-
private static final RNBootSplashQueue<
|
|
41
|
+
private static final RNBootSplashQueue<Promise> mPromiseQueue = new RNBootSplashQueue<>();
|
|
43
42
|
private static Status mStatus = Status.HIDDEN;
|
|
44
|
-
private static boolean mIsAppInForeground = true;
|
|
45
43
|
private static boolean mShouldFade = false;
|
|
46
44
|
private static boolean mShouldKeepOnScreen = true;
|
|
47
45
|
|
|
48
46
|
public RNBootSplashModule(ReactApplicationContext reactContext) {
|
|
49
47
|
super(reactContext);
|
|
50
|
-
reactContext.addLifecycleEventListener(this);
|
|
51
48
|
}
|
|
52
49
|
|
|
53
50
|
@Override
|
|
@@ -96,95 +93,66 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
|
|
|
96
93
|
});
|
|
97
94
|
}
|
|
98
95
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
@Override
|
|
105
|
-
public void onHostPause() {
|
|
106
|
-
mIsAppInForeground = false;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
@Override
|
|
110
|
-
public void onHostResume() {
|
|
111
|
-
mIsAppInForeground = true;
|
|
112
|
-
shiftNextTask();
|
|
113
|
-
}
|
|
96
|
+
private void clearPromiseQueue() {
|
|
97
|
+
while (!mPromiseQueue.isEmpty()) {
|
|
98
|
+
Promise promise = mPromiseQueue.shift();
|
|
114
99
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
RNBootSplashTask task = mTaskQueue.shift();
|
|
118
|
-
|
|
119
|
-
if (task != null) {
|
|
120
|
-
hideWithTask(task);
|
|
121
|
-
}
|
|
100
|
+
if (promise != null)
|
|
101
|
+
promise.resolve(true);
|
|
122
102
|
}
|
|
123
103
|
}
|
|
124
104
|
|
|
125
|
-
private void
|
|
126
|
-
final Timer timer = new Timer();
|
|
127
|
-
|
|
128
|
-
timer.schedule(new TimerTask() {
|
|
129
|
-
@Override
|
|
130
|
-
public void run() {
|
|
131
|
-
shiftNextTask();
|
|
132
|
-
timer.cancel();
|
|
133
|
-
}
|
|
134
|
-
}, 250);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
private void hideWithTask(final RNBootSplashTask task) {
|
|
138
|
-
final Activity activity = getReactApplicationContext().getCurrentActivity();
|
|
139
|
-
final boolean fade = task.getFade();
|
|
140
|
-
final Promise promise = task.getPromise();
|
|
141
|
-
|
|
105
|
+
private void hideAndResolveAll(final boolean fade) {
|
|
142
106
|
if (mSplashScreen == null || mStatus == Status.HIDDEN) {
|
|
143
|
-
|
|
144
|
-
shiftNextTask();
|
|
107
|
+
clearPromiseQueue();
|
|
145
108
|
return;
|
|
146
109
|
}
|
|
147
110
|
|
|
148
111
|
UiThreadUtil.runOnUiThread(new Runnable() {
|
|
149
112
|
@Override
|
|
150
113
|
public void run() {
|
|
114
|
+
final Activity activity = getReactApplicationContext().getCurrentActivity();
|
|
115
|
+
|
|
151
116
|
if (activity == null || activity.isFinishing()) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
117
|
+
// Wait for activity to be ready
|
|
118
|
+
final Timer timer = new Timer();
|
|
155
119
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
120
|
+
timer.schedule(new TimerTask() {
|
|
121
|
+
@Override
|
|
122
|
+
public void run() {
|
|
123
|
+
hideAndResolveAll(fade);
|
|
124
|
+
timer.cancel();
|
|
125
|
+
}
|
|
126
|
+
}, 250);
|
|
127
|
+
} else {
|
|
128
|
+
if (fade) {
|
|
129
|
+
mStatus = Status.TRANSITIONING;
|
|
130
|
+
}
|
|
159
131
|
|
|
160
|
-
|
|
161
|
-
|
|
132
|
+
mShouldFade = fade;
|
|
133
|
+
mShouldKeepOnScreen = false;
|
|
162
134
|
|
|
163
|
-
|
|
135
|
+
final Timer timer = new Timer();
|
|
164
136
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
}
|
|
137
|
+
// We cannot rely on setOnExitAnimationListener
|
|
138
|
+
// See https://issuetracker.google.com/issues/197906327
|
|
139
|
+
timer.schedule(new TimerTask() {
|
|
140
|
+
@Override
|
|
141
|
+
public void run() {
|
|
142
|
+
mStatus = Status.HIDDEN;
|
|
143
|
+
timer.cancel();
|
|
144
|
+
clearPromiseQueue();
|
|
145
|
+
}
|
|
146
|
+
}, ANIMATION_DURATION);
|
|
147
|
+
}
|
|
176
148
|
}
|
|
177
149
|
});
|
|
178
150
|
}
|
|
179
151
|
|
|
180
152
|
@ReactMethod
|
|
181
153
|
public void hide(final boolean fade, final Promise promise) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
} else {
|
|
185
|
-
mTaskQueue.push(new RNBootSplashTask(fade, promise));
|
|
186
|
-
shiftNextTask();
|
|
187
|
-
}
|
|
154
|
+
mPromiseQueue.push(promise);
|
|
155
|
+
hideAndResolveAll(fade);
|
|
188
156
|
}
|
|
189
157
|
|
|
190
158
|
@ReactMethod
|
|
Binary file
|
package/ios/.npmignore
ADDED
package/ios/RNBootSplash.h
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
#import <React/RCTBridgeModule.h>
|
|
2
2
|
#import <React/RCTRootView.h>
|
|
3
3
|
|
|
4
|
-
@interface RNBootSplashTask : NSObject
|
|
5
|
-
|
|
6
|
-
@property (nonatomic, readonly) BOOL fade;
|
|
7
|
-
@property (nonatomic, readonly, strong) RCTPromiseResolveBlock _Nonnull resolve;
|
|
8
|
-
|
|
9
|
-
- (instancetype _Nonnull)initWithFade:(BOOL)fade
|
|
10
|
-
resolver:(RCTPromiseResolveBlock _Nonnull)resolve;
|
|
11
|
-
|
|
12
|
-
@end
|
|
13
|
-
|
|
14
4
|
@interface RNBootSplash : NSObject <RCTBridgeModule>
|
|
15
5
|
|
|
16
6
|
+ (void)initWithStoryboard:(NSString * _Nonnull)storyboardName
|
|
17
|
-
rootView:(
|
|
7
|
+
rootView:(UIView * _Nullable)rootView;
|
|
18
8
|
|
|
19
9
|
@end
|
package/ios/RNBootSplash.m
CHANGED
|
@@ -3,24 +3,9 @@
|
|
|
3
3
|
#import <React/RCTBridge.h>
|
|
4
4
|
#import <React/RCTUtils.h>
|
|
5
5
|
|
|
6
|
-
static NSMutableArray<
|
|
6
|
+
static NSMutableArray<RCTPromiseResolveBlock> *_resolverQueue = nil;
|
|
7
7
|
static RCTRootView *_rootView = nil;
|
|
8
8
|
static bool _isTransitioning = false;
|
|
9
|
-
static bool _shouldPreventInit = false;
|
|
10
|
-
|
|
11
|
-
@implementation RNBootSplashTask
|
|
12
|
-
|
|
13
|
-
- (instancetype)initWithFade:(BOOL)fade
|
|
14
|
-
resolver:(RCTPromiseResolveBlock _Nonnull)resolve {
|
|
15
|
-
if (self = [super init]) {
|
|
16
|
-
_fade = fade;
|
|
17
|
-
_resolve = resolve;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return self;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@end
|
|
24
9
|
|
|
25
10
|
@implementation RNBootSplash
|
|
26
11
|
|
|
@@ -35,11 +20,14 @@ RCT_EXPORT_MODULE();
|
|
|
35
20
|
}
|
|
36
21
|
|
|
37
22
|
+ (void)initWithStoryboard:(NSString * _Nonnull)storyboardName
|
|
38
|
-
rootView:(
|
|
39
|
-
if (rootView == nil ||
|
|
23
|
+
rootView:(UIView * _Nullable)rootView {
|
|
24
|
+
if (rootView == nil ||
|
|
25
|
+
![rootView isKindOfClass:[RCTRootView class]] ||
|
|
26
|
+
_rootView != nil ||
|
|
27
|
+
RCTRunningInAppExtension())
|
|
40
28
|
return;
|
|
41
29
|
|
|
42
|
-
_rootView = rootView;
|
|
30
|
+
_rootView = (RCTRootView *)rootView;
|
|
43
31
|
|
|
44
32
|
[[NSNotificationCenter defaultCenter] removeObserver:rootView
|
|
45
33
|
name:RCTContentDidAppearNotification
|
|
@@ -48,13 +36,13 @@ RCT_EXPORT_MODULE();
|
|
|
48
36
|
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
|
|
49
37
|
UIView *loadingView = [[storyboard instantiateInitialViewController] view];
|
|
50
38
|
|
|
51
|
-
if (
|
|
52
|
-
return;
|
|
39
|
+
if (_resolverQueue != nil)
|
|
40
|
+
return; // hide has already been called, abort init
|
|
53
41
|
|
|
54
42
|
[_rootView setLoadingView:loadingView];
|
|
55
43
|
|
|
56
44
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
57
|
-
selector:@selector(onJavaScriptDidLoad
|
|
45
|
+
selector:@selector(onJavaScriptDidLoad)
|
|
58
46
|
name:RCTJavaScriptDidLoadNotification
|
|
59
47
|
object:nil];
|
|
60
48
|
|
|
@@ -62,21 +50,10 @@ RCT_EXPORT_MODULE();
|
|
|
62
50
|
selector:@selector(onJavaScriptDidFailToLoad)
|
|
63
51
|
name:RCTJavaScriptDidFailToLoadNotification
|
|
64
52
|
object:nil];
|
|
65
|
-
|
|
66
|
-
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
67
|
-
selector:@selector(shiftNextTask)
|
|
68
|
-
name:UIApplicationDidBecomeActiveNotification
|
|
69
|
-
object:nil];
|
|
70
53
|
}
|
|
71
54
|
|
|
72
|
-
+ (void)onJavaScriptDidLoad
|
|
73
|
-
[[NSNotificationCenter defaultCenter] removeObserver:self
|
|
74
|
-
name:RCTJavaScriptDidLoadNotification
|
|
75
|
-
object:nil];
|
|
76
|
-
|
|
77
|
-
[[NSNotificationCenter defaultCenter] removeObserver:self
|
|
78
|
-
name:RCTJavaScriptDidFailToLoadNotification
|
|
79
|
-
object:nil];
|
|
55
|
+
+ (void)onJavaScriptDidLoad {
|
|
56
|
+
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
80
57
|
}
|
|
81
58
|
|
|
82
59
|
+ (void)onJavaScriptDidFailToLoad {
|
|
@@ -91,39 +68,36 @@ RCT_EXPORT_MODULE();
|
|
|
91
68
|
+ (void)removeLoadingView {
|
|
92
69
|
if (![self isHidden]) {
|
|
93
70
|
_rootView.loadingView.hidden = YES;
|
|
71
|
+
|
|
94
72
|
[_rootView.loadingView removeFromSuperview];
|
|
95
73
|
_rootView.loadingView = nil;
|
|
96
74
|
}
|
|
97
75
|
}
|
|
98
76
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
+ (void)shiftNextTask {
|
|
105
|
-
[self ensureTaskQueue];
|
|
77
|
+
- (void)clearResolverQueue {
|
|
78
|
+
while ([_resolverQueue count] > 0) {
|
|
79
|
+
RCTPromiseResolveBlock resolve = [_resolverQueue objectAtIndex:0];
|
|
80
|
+
[_resolverQueue removeObjectAtIndex:0];
|
|
106
81
|
|
|
107
|
-
|
|
108
|
-
!_isTransitioning &&
|
|
109
|
-
[[UIApplication sharedApplication] applicationState] != UIApplicationStateBackground) {
|
|
110
|
-
RNBootSplashTask *task = [_taskQueue objectAtIndex:0];
|
|
111
|
-
[_taskQueue removeObjectAtIndex:0];
|
|
112
|
-
|
|
113
|
-
[self hideWithTask:task];
|
|
82
|
+
resolve(@(true));
|
|
114
83
|
}
|
|
115
84
|
}
|
|
116
85
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
86
|
+
RCT_REMAP_METHOD(hide,
|
|
87
|
+
hideWithFade:(BOOL)fade
|
|
88
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
89
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
90
|
+
if (_resolverQueue == nil)
|
|
91
|
+
_resolverQueue = [[NSMutableArray alloc] init];
|
|
92
|
+
|
|
93
|
+
[_resolverQueue addObject:resolve];
|
|
122
94
|
|
|
123
|
-
if (
|
|
124
|
-
[self
|
|
125
|
-
|
|
126
|
-
|
|
95
|
+
if ([RNBootSplash isHidden] || RCTRunningInAppExtension())
|
|
96
|
+
return [self clearResolverQueue];
|
|
97
|
+
|
|
98
|
+
if (!fade) {
|
|
99
|
+
[RNBootSplash removeLoadingView];
|
|
100
|
+
return [self clearResolverQueue];
|
|
127
101
|
}
|
|
128
102
|
|
|
129
103
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
@@ -139,31 +113,13 @@ RCT_EXPORT_MODULE();
|
|
|
139
113
|
[_rootView.loadingView removeFromSuperview];
|
|
140
114
|
_rootView.loadingView = nil;
|
|
141
115
|
|
|
142
|
-
task.resolve(@(true));
|
|
143
116
|
_isTransitioning = false;
|
|
144
117
|
|
|
145
|
-
return [self
|
|
118
|
+
return [self clearResolverQueue];
|
|
146
119
|
}];
|
|
147
120
|
});
|
|
148
121
|
}
|
|
149
122
|
|
|
150
|
-
RCT_REMAP_METHOD(hide,
|
|
151
|
-
hideWithFade:(BOOL)fade
|
|
152
|
-
resolver:(RCTPromiseResolveBlock)resolve
|
|
153
|
-
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
154
|
-
_shouldPreventInit = true;
|
|
155
|
-
|
|
156
|
-
if ([RNBootSplash isHidden] || RCTRunningInAppExtension())
|
|
157
|
-
return resolve(@(true));
|
|
158
|
-
|
|
159
|
-
RNBootSplashTask *task = [[RNBootSplashTask alloc] initWithFade:fade
|
|
160
|
-
resolver:resolve];
|
|
161
|
-
|
|
162
|
-
[RNBootSplash ensureTaskQueue];
|
|
163
|
-
[_taskQueue addObject:task];
|
|
164
|
-
[RNBootSplash shiftNextTask];
|
|
165
|
-
}
|
|
166
|
-
|
|
167
123
|
RCT_REMAP_METHOD(getVisibilityStatus,
|
|
168
124
|
getVisibilityStatusWithResolver:(RCTPromiseResolveBlock)resolve
|
|
169
125
|
rejecter:(RCTPromiseRejectBlock)reject) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-bootsplash",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Display a bootsplash on your app starts. Hide it when you want.",
|
|
6
6
|
"author": "Mathieu Acthernoene <zoontek@gmail.com>",
|
|
@@ -60,19 +60,22 @@
|
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"chalk": "^4.1.2",
|
|
63
|
-
"fs-extra": "^10.
|
|
63
|
+
"fs-extra": "^10.1.0",
|
|
64
64
|
"jimp": "^0.16.1"
|
|
65
65
|
},
|
|
66
|
+
"resolutions": {
|
|
67
|
+
"@types/react": "^17"
|
|
68
|
+
},
|
|
66
69
|
"devDependencies": {
|
|
67
70
|
"@types/fs-extra": "^9.0.13",
|
|
68
|
-
"@types/react-native": "^0.
|
|
69
|
-
"lint-staged": "^12.
|
|
70
|
-
"prettier": "^2.
|
|
71
|
+
"@types/react-native": "^0.67.6",
|
|
72
|
+
"lint-staged": "^12.4.0",
|
|
73
|
+
"prettier": "^2.6.2",
|
|
71
74
|
"prettier-plugin-organize-imports": "^2.3.4",
|
|
72
75
|
"react": "^17.0.2",
|
|
73
|
-
"react-native": "^0.
|
|
76
|
+
"react-native": "^0.68.1",
|
|
74
77
|
"react-native-builder-bob": "^0.18.2",
|
|
75
78
|
"rescript": "^9.1.4",
|
|
76
|
-
"typescript": "^4.
|
|
79
|
+
"typescript": "^4.6.3"
|
|
77
80
|
}
|
|
78
81
|
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
package com.zoontek.rnbootsplash;
|
|
2
|
-
|
|
3
|
-
import androidx.annotation.NonNull;
|
|
4
|
-
|
|
5
|
-
import com.facebook.react.bridge.Promise;
|
|
6
|
-
|
|
7
|
-
public class RNBootSplashTask {
|
|
8
|
-
|
|
9
|
-
private final boolean mFade;
|
|
10
|
-
@NonNull private final Promise mPromise;
|
|
11
|
-
|
|
12
|
-
public RNBootSplashTask(final boolean fade, @NonNull final Promise promise) {
|
|
13
|
-
mFade = fade;
|
|
14
|
-
mPromise = promise;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public boolean getFade() {
|
|
18
|
-
return mFade;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@NonNull
|
|
22
|
-
public Promise getPromise() {
|
|
23
|
-
return mPromise;
|
|
24
|
-
}
|
|
25
|
-
}
|