react-native-bootsplash 3.2.6 → 3.2.7

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.
Files changed (2) hide show
  1. package/ios/RNBootSplash.m +68 -24
  2. package/package.json +1 -1
@@ -8,6 +8,7 @@ static NSString *_storyboardName = @"BootSplash";
8
8
  static RCTRootView *_rootView = nil;
9
9
  static RNBootSplashStatus _status = RNBootSplashStatusHidden;
10
10
  static UIViewController *_splashVC = nil;
11
+ static bool _preventInitialization = false;
11
12
 
12
13
  @implementation RNBootSplashTask
13
14
 
@@ -39,8 +40,36 @@ RCT_EXPORT_MODULE();
39
40
  return dispatch_get_main_queue();
40
41
  }
41
42
 
43
+ - (id)init {
44
+ if (self = [super init]) {
45
+ [[NSNotificationCenter defaultCenter] addObserver:self
46
+ selector:@selector(onContentDidAppear)
47
+ name:RCTContentDidAppearNotification
48
+ object:nil];
49
+
50
+ [[NSNotificationCenter defaultCenter] addObserver:self
51
+ selector:@selector(onJavaScriptDidFailToLoad)
52
+ name:RCTJavaScriptDidFailToLoadNotification
53
+ object:nil];
54
+
55
+ [[NSNotificationCenter defaultCenter] addObserver:self
56
+ selector:@selector(onApplicationDidBecomeActive)
57
+ name:UIApplicationDidBecomeActiveNotification
58
+ object:nil];
59
+ }
60
+
61
+ return self;
62
+ }
63
+
64
+ - (void)dealloc {
65
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
66
+ }
67
+
42
68
  + (void)initWithStoryboard:(NSString * _Nonnull)storyboardName
43
69
  rootView:(RCTRootView * _Nonnull)rootView {
70
+ if (_preventInitialization)
71
+ return; // initWithStoryboard has been called too late
72
+
44
73
  _rootView = rootView;
45
74
  _status = RNBootSplashStatusVisible;
46
75
  _storyboardName = storyboardName;
@@ -65,26 +94,13 @@ RCT_EXPORT_MODULE();
65
94
 
66
95
  [self shiftNextTask]; // JS thread might started pushing tasks
67
96
  }];
68
-
69
- [[NSNotificationCenter defaultCenter] addObserver:self
70
- selector:@selector(onJavaScriptDidLoad:)
71
- name:RCTJavaScriptDidLoadNotification
72
- object:nil];
73
-
74
- [[NSNotificationCenter defaultCenter] addObserver:self
75
- selector:@selector(onJavaScriptDidFailToLoad)
76
- name:RCTJavaScriptDidFailToLoadNotification
77
- object:nil];
78
-
79
- [[NSNotificationCenter defaultCenter] addObserver:self
80
- selector:@selector(shiftNextTask)
81
- name:UIApplicationDidBecomeActiveNotification
82
- object:nil];
83
97
  }
84
98
 
85
- + (void)onJavaScriptDidLoad:(NSNotification *)notification {
99
+ - (void)onContentDidAppear {
100
+ _preventInitialization = true;
101
+
86
102
  [[NSNotificationCenter defaultCenter] removeObserver:self
87
- name:RCTJavaScriptDidLoadNotification
103
+ name:RCTContentDidAppearNotification
88
104
  object:nil];
89
105
 
90
106
  [[NSNotificationCenter defaultCenter] removeObserver:self
@@ -92,7 +108,9 @@ RCT_EXPORT_MODULE();
92
108
  object:nil];
93
109
  }
94
110
 
95
- + (void)onJavaScriptDidFailToLoad {
111
+ - (void)onJavaScriptDidFailToLoad {
112
+ _preventInitialization = true;
113
+
96
114
  if (_splashVC != nil) {
97
115
  [_splashVC dismissViewControllerAnimated:false
98
116
  completion:^{
@@ -103,14 +121,36 @@ RCT_EXPORT_MODULE();
103
121
  [[NSNotificationCenter defaultCenter] removeObserver:self];
104
122
  }
105
123
 
124
+ - (void)onApplicationDidBecomeActive {
125
+ [RNBootSplash shiftNextTask];
126
+ }
127
+
128
+ + (void)retryShiftNextTask:(NSTimer *)timer {
129
+ [timer invalidate];
130
+ [self shiftNextTask];
131
+ }
132
+
106
133
  + (void)shiftNextTask {
134
+ bool hasTasks = [_taskQueue count] > 0;
135
+ bool isActive = [[UIApplication sharedApplication] applicationState] == UIApplicationStateActive;
136
+
107
137
  bool shouldSkipTick = _rootView.loadingView != nil
108
138
  || _status == RNBootSplashStatusTransitioningToVisible
109
139
  || _status == RNBootSplashStatusTransitioningToHidden
110
- || [_taskQueue count] == 0
111
- || [[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground;
112
-
113
- if (shouldSkipTick) return;
140
+ || !hasTasks
141
+ || !isActive;
142
+
143
+ if (shouldSkipTick) {
144
+ if (hasTasks && isActive) {
145
+ [NSTimer scheduledTimerWithTimeInterval:0.1
146
+ target:self
147
+ selector:@selector(retryShiftNextTask:)
148
+ userInfo:nil
149
+ repeats:false];
150
+ }
151
+
152
+ return;
153
+ }
114
154
 
115
155
  RNBootSplashTask *task = [_taskQueue objectAtIndex:0];
116
156
  [_taskQueue removeObjectAtIndex:0];
@@ -167,8 +207,10 @@ RCT_REMAP_METHOD(show,
167
207
  showWithFade:(BOOL)fade
168
208
  resolver:(RCTPromiseResolveBlock)resolve
169
209
  rejecter:(RCTPromiseRejectBlock)reject) {
170
- if (_rootView == nil)
210
+ if (_rootView == nil) {
211
+ _preventInitialization = true;
171
212
  return reject(@"uninitialized_module", @"react-native-bootsplash has not been initialized, or has been too early", nil);
213
+ }
172
214
 
173
215
  RNBootSplashTask *task = [[RNBootSplashTask alloc] initWithType:RNBootSplashTaskTypeShow
174
216
  fade:fade
@@ -183,8 +225,10 @@ RCT_REMAP_METHOD(hide,
183
225
  hideWithFade:(BOOL)fade
184
226
  resolver:(RCTPromiseResolveBlock)resolve
185
227
  rejecter:(RCTPromiseRejectBlock)reject) {
186
- if (_rootView == nil)
228
+ if (_rootView == nil) {
229
+ _preventInitialization = true;
187
230
  return reject(@"uninitialized_module", @"react-native-bootsplash has not been initialized, or has been too early", nil);
231
+ }
188
232
 
189
233
  RNBootSplashTask *task = [[RNBootSplashTask alloc] initWithType:RNBootSplashTaskTypeHide
190
234
  fade:fade
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-bootsplash",
3
- "version": "3.2.6",
3
+ "version": "3.2.7",
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>",