react-native-bootsplash 4.0.1 → 4.1.2

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
@@ -216,7 +216,7 @@ dependencies {
216
216
  //noinspection GradleDynamicVersion
217
217
  implementation "com.facebook.react:react-native:+" // From node_modules
218
218
 
219
- implementation "androidx.core:core-splashscreen:1.0.0-alpha02" // Add this line
219
+ implementation "androidx.core:core-splashscreen:1.0.0-beta01" // Add this line
220
220
 
221
221
  // …
222
222
  ```
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.authors = package["author"]
12
12
  s.homepage = package["homepage"]
13
13
 
14
- s.platforms = { :ios => "11.0" }
14
+ s.platforms = { :ios => "11.0", :tvos => "11.0" }
15
15
  s.requires_arc = true
16
16
 
17
17
  s.source = { :git => package["repository"]["url"], :tag => s.version }
@@ -49,5 +49,5 @@ repositories {
49
49
  dependencies {
50
50
  //noinspection GradleDynamicVersion
51
51
  implementation "com.facebook.react:react-native:+" // From node_modules
52
- implementation "androidx.core:core-splashscreen:${safeExtGet("androidXSplashScreenVersion", "1.0.0-alpha02")}"
52
+ implementation "androidx.core:core-splashscreen:${safeExtGet("androidXSplashScreenVersion", "1.0.0-beta01")}"
53
53
  }
@@ -21,7 +21,6 @@ import com.facebook.react.bridge.UiThreadUtil;
21
21
  import com.facebook.react.common.ReactConstants;
22
22
  import com.facebook.react.module.annotations.ReactModule;
23
23
 
24
- import java.util.Stack;
25
24
  import java.util.Timer;
26
25
  import java.util.TimerTask;
27
26
 
@@ -40,7 +39,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
40
39
  @Nullable
41
40
  private static SplashScreen mSplashScreen = null;
42
41
 
43
- private static final Stack<RNBootSplashTask> mTaskStack = new Stack<>();
42
+ private static final RNBootSplashQueue<RNBootSplashTask> mTaskQueue = new RNBootSplashQueue<>();
44
43
  private static Status mStatus = Status.HIDDEN;
45
44
  private static boolean mIsAppInForeground = true;
46
45
  private static boolean mShouldFade = false;
@@ -67,7 +66,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
67
66
  mSplashScreen = SplashScreen.installSplashScreen(activity);
68
67
  mStatus = Status.VISIBLE;
69
68
 
70
- mSplashScreen.setKeepVisibleCondition(new SplashScreen.KeepOnScreenCondition() {
69
+ mSplashScreen.setKeepOnScreenCondition(new SplashScreen.KeepOnScreenCondition() {
71
70
  @Override
72
71
  public boolean shouldKeepOnScreen() {
73
72
  return mShouldKeepOnScreen;
@@ -114,11 +113,12 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
114
113
  }
115
114
 
116
115
  private void shiftNextTask() {
117
- if (mStatus != Status.TRANSITIONING &&
118
- mIsAppInForeground &&
119
- mTaskStack.size() > 0) {
120
- RNBootSplashTask task = mTaskStack.pop();
121
- hideWithTask(task);
116
+ if (mStatus != Status.TRANSITIONING && mIsAppInForeground) {
117
+ RNBootSplashTask task = mTaskQueue.shift();
118
+
119
+ if (task != null) {
120
+ hideWithTask(task);
121
+ }
122
122
  }
123
123
  }
124
124
 
@@ -182,7 +182,7 @@ public class RNBootSplashModule extends ReactContextBaseJavaModule implements Li
182
182
  if (mSplashScreen == null || mStatus == Status.HIDDEN) {
183
183
  promise.resolve(true);
184
184
  } else {
185
- mTaskStack.push(new RNBootSplashTask(fade, promise));
185
+ mTaskQueue.push(new RNBootSplashTask(fade, promise));
186
186
  shiftNextTask();
187
187
  }
188
188
  }
@@ -0,0 +1,31 @@
1
+ package com.zoontek.rnbootsplash;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+
6
+ import java.util.Vector;
7
+
8
+ /**
9
+ * Represents a first-in-first-out (FIFO) thread safe queue of objects.
10
+ * Its source code is based on Java internal <code>Stack</code>.
11
+ */
12
+ public class RNBootSplashQueue<E> extends Vector<E> {
13
+
14
+ public RNBootSplashQueue() {}
15
+
16
+ @Nullable
17
+ public synchronized E shift() {
18
+ if (size() == 0) {
19
+ return null;
20
+ }
21
+
22
+ E item = elementAt(0);
23
+ removeElementAt(0);
24
+
25
+ return item;
26
+ }
27
+
28
+ public void push(@NonNull E item) {
29
+ addElement(item);
30
+ }
31
+ }
@@ -1,12 +1,6 @@
1
1
  #import <React/RCTBridgeModule.h>
2
2
  #import <React/RCTRootView.h>
3
3
 
4
- typedef enum {
5
- RNBootSplashStatusVisible = 0,
6
- RNBootSplashStatusHidden = 1,
7
- RNBootSplashStatusTransitioning = 2
8
- } RNBootSplashStatus;
9
-
10
4
  @interface RNBootSplashTask : NSObject
11
5
 
12
6
  @property (nonatomic, readonly) BOOL fade;
@@ -20,6 +14,6 @@ typedef enum {
20
14
  @interface RNBootSplash : NSObject <RCTBridgeModule>
21
15
 
22
16
  + (void)initWithStoryboard:(NSString * _Nonnull)storyboardName
23
- rootView:(RCTRootView * _Nonnull)rootView;
17
+ rootView:(RCTRootView * _Nullable)rootView;
24
18
 
25
19
  @end
@@ -3,9 +3,10 @@
3
3
  #import <React/RCTBridge.h>
4
4
  #import <React/RCTUtils.h>
5
5
 
6
- static NSMutableArray<RNBootSplashTask *> *_taskStack = nil;
6
+ static NSMutableArray<RNBootSplashTask *> *_taskQueue = nil;
7
7
  static RCTRootView *_rootView = nil;
8
- static RNBootSplashStatus _status = RNBootSplashStatusHidden;
8
+ static bool _isTransitioning = false;
9
+ static bool _shouldPreventInit = false;
9
10
 
10
11
  @implementation RNBootSplashTask
11
12
 
@@ -26,7 +27,7 @@ static RNBootSplashStatus _status = RNBootSplashStatusHidden;
26
27
  RCT_EXPORT_MODULE();
27
28
 
28
29
  + (BOOL)requiresMainQueueSetup {
29
- return YES;
30
+ return NO;
30
31
  }
31
32
 
32
33
  - (dispatch_queue_t)methodQueue {
@@ -34,18 +35,24 @@ RCT_EXPORT_MODULE();
34
35
  }
35
36
 
36
37
  + (void)initWithStoryboard:(NSString * _Nonnull)storyboardName
37
- rootView:(RCTRootView * _Nonnull)rootView {
38
- _rootView = rootView;
39
- _status = RNBootSplashStatusVisible;
40
- _taskStack = [[NSMutableArray alloc] init];
38
+ rootView:(RCTRootView * _Nullable)rootView {
39
+ if (rootView == nil || _rootView != nil || RCTRunningInAppExtension())
40
+ return;
41
41
 
42
- UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
43
- [_rootView setLoadingView:[[storyboard instantiateInitialViewController] view]];
42
+ _rootView = rootView;
44
43
 
45
44
  [[NSNotificationCenter defaultCenter] removeObserver:rootView
46
45
  name:RCTContentDidAppearNotification
47
46
  object:rootView];
48
47
 
48
+ UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
49
+ UIView *loadingView = [[storyboard instantiateInitialViewController] view];
50
+
51
+ if (_shouldPreventInit)
52
+ return;
53
+
54
+ [_rootView setLoadingView:loadingView];
55
+
49
56
  [[NSNotificationCenter defaultCenter] addObserver:self
50
57
  selector:@selector(onJavaScriptDidLoad:)
51
58
  name:RCTJavaScriptDidLoadNotification
@@ -73,89 +80,99 @@ RCT_EXPORT_MODULE();
73
80
  }
74
81
 
75
82
  + (void)onJavaScriptDidFailToLoad {
76
- _status = RNBootSplashStatusHidden;
83
+ [self removeLoadingView];
84
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
85
+ }
77
86
 
78
- if (_rootView != nil) {
87
+ + (bool)isHidden {
88
+ return _rootView == nil || _rootView.loadingView == nil || [_rootView.loadingView isHidden];
89
+ }
90
+
91
+ + (void)removeLoadingView {
92
+ if (![self isHidden]) {
79
93
  _rootView.loadingView.hidden = YES;
80
94
  [_rootView.loadingView removeFromSuperview];
81
95
  _rootView.loadingView = nil;
82
96
  }
97
+ }
83
98
 
84
- [[NSNotificationCenter defaultCenter] removeObserver:self];
99
+ + (void)ensureTaskQueue {
100
+ if (_taskQueue == nil)
101
+ _taskQueue = [[NSMutableArray alloc] init];
85
102
  }
86
103
 
87
104
  + (void)shiftNextTask {
88
- if (_status != RNBootSplashStatusTransitioning &&
89
- [_taskStack count] > 0 &&
105
+ [self ensureTaskQueue];
106
+
107
+ if ([_taskQueue count] > 0 &&
108
+ !_isTransitioning &&
90
109
  [[UIApplication sharedApplication] applicationState] != UIApplicationStateBackground) {
91
- RNBootSplashTask *task = [_taskStack objectAtIndex:0];
92
- [_taskStack removeObjectAtIndex:0];
110
+ RNBootSplashTask *task = [_taskQueue objectAtIndex:0];
111
+ [_taskQueue removeObjectAtIndex:0];
93
112
 
94
113
  [self hideWithTask:task];
95
114
  }
96
115
  }
97
116
 
98
117
  + (void)hideWithTask:(RNBootSplashTask *)task {
99
- if (_status == RNBootSplashStatusHidden) {
118
+ if ([self isHidden]) {
100
119
  task.resolve(@(true));
101
120
  return [self shiftNextTask];
102
121
  }
103
122
 
104
123
  if (!task.fade) {
105
- _status = RNBootSplashStatusHidden;
106
-
107
- _rootView.loadingView.hidden = YES;
108
- [_rootView.loadingView removeFromSuperview];
109
- _rootView.loadingView = nil;
110
-
124
+ [self removeLoadingView];
111
125
  task.resolve(@(true));
112
126
  return [self shiftNextTask];
113
127
  }
114
128
 
115
- _status = RNBootSplashStatusTransitioning;
116
-
117
- [UIView transitionWithView:_rootView
118
- duration:0.220
119
- options:UIViewAnimationOptionTransitionCrossDissolve
120
- animations:^{
121
- _rootView.loadingView.hidden = YES;
122
- }
123
- completion:^(__unused BOOL finished) {
124
- _status = RNBootSplashStatusHidden;
125
-
126
- [_rootView.loadingView removeFromSuperview];
127
- _rootView.loadingView = nil;
128
-
129
- task.resolve(@(true));
130
- return [self shiftNextTask];
131
- }];
129
+ dispatch_async(dispatch_get_main_queue(), ^{
130
+ _isTransitioning = true;
131
+
132
+ [UIView transitionWithView:_rootView
133
+ duration:0.220
134
+ options:UIViewAnimationOptionTransitionCrossDissolve
135
+ animations:^{
136
+ _rootView.loadingView.hidden = YES;
137
+ }
138
+ completion:^(__unused BOOL finished) {
139
+ [_rootView.loadingView removeFromSuperview];
140
+ _rootView.loadingView = nil;
141
+
142
+ task.resolve(@(true));
143
+ _isTransitioning = false;
144
+
145
+ return [self shiftNextTask];
146
+ }];
147
+ });
132
148
  }
133
149
 
134
150
  RCT_REMAP_METHOD(hide,
135
151
  hideWithFade:(BOOL)fade
136
152
  resolver:(RCTPromiseResolveBlock)resolve
137
153
  rejecter:(RCTPromiseRejectBlock)reject) {
138
- if (_rootView == nil || _status == RNBootSplashStatusHidden)
154
+ _shouldPreventInit = true;
155
+
156
+ if ([RNBootSplash isHidden] || RCTRunningInAppExtension())
139
157
  return resolve(@(true));
140
158
 
141
159
  RNBootSplashTask *task = [[RNBootSplashTask alloc] initWithFade:fade
142
160
  resolver:resolve];
143
161
 
144
- [_taskStack addObject:task];
162
+ [RNBootSplash ensureTaskQueue];
163
+ [_taskQueue addObject:task];
145
164
  [RNBootSplash shiftNextTask];
146
165
  }
147
166
 
148
167
  RCT_REMAP_METHOD(getVisibilityStatus,
149
168
  getVisibilityStatusWithResolver:(RCTPromiseResolveBlock)resolve
150
169
  rejecter:(RCTPromiseRejectBlock)reject) {
151
- switch (_status) {
152
- case RNBootSplashStatusVisible:
153
- return resolve(@"visible");
154
- case RNBootSplashStatusHidden:
155
- return resolve(@"hidden");
156
- case RNBootSplashStatusTransitioning:
157
- return resolve(@"transitioning");
158
- }
170
+ if ([RNBootSplash isHidden])
171
+ return resolve(@"hidden");
172
+ else if (_isTransitioning)
173
+ return resolve(@"transitioning");
174
+ else
175
+ return resolve(@"visible");
159
176
  }
160
177
 
161
178
  @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-bootsplash",
3
- "version": "4.0.1",
3
+ "version": "4.1.2",
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>",
@@ -65,14 +65,14 @@
65
65
  },
66
66
  "devDependencies": {
67
67
  "@types/fs-extra": "^9.0.13",
68
- "@types/react-native": "^0.66.4",
69
- "lint-staged": "^12.0.2",
70
- "prettier": "^2.4.1",
68
+ "@types/react-native": "^0.66.15",
69
+ "lint-staged": "^12.3.3",
70
+ "prettier": "^2.5.1",
71
71
  "prettier-plugin-organize-imports": "^2.3.4",
72
72
  "react": "^17.0.2",
73
- "react-native": "^0.66.3",
73
+ "react-native": "^0.67.2",
74
74
  "react-native-builder-bob": "^0.18.2",
75
75
  "rescript": "^9.1.4",
76
- "typescript": "^4.4.4"
76
+ "typescript": "^4.5.5"
77
77
  }
78
78
  }