react-native-bootsplash 4.1.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.
@@ -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
@@ -5,7 +5,8 @@
5
5
 
6
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
- _taskQueue = [[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,20 +80,32 @@ 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
- [_taskQueue count] > 0 &&
105
+ [self ensureTaskQueue];
106
+
107
+ if ([_taskQueue count] > 0 &&
108
+ !_isTransitioning &&
90
109
  [[UIApplication sharedApplication] applicationState] != UIApplicationStateBackground) {
91
110
  RNBootSplashTask *task = [_taskQueue objectAtIndex:0];
92
111
  [_taskQueue removeObjectAtIndex:0];
@@ -96,51 +115,51 @@ RCT_EXPORT_MODULE();
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
 
162
+ [RNBootSplash ensureTaskQueue];
144
163
  [_taskQueue addObject:task];
145
164
  [RNBootSplash shiftNextTask];
146
165
  }
@@ -148,14 +167,12 @@ RCT_REMAP_METHOD(hide,
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.1.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.12",
69
- "lint-staged": "^12.1.7",
68
+ "@types/react-native": "^0.66.15",
69
+ "lint-staged": "^12.3.3",
70
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.4",
73
+ "react-native": "^0.67.2",
74
74
  "react-native-builder-bob": "^0.18.2",
75
75
  "rescript": "^9.1.4",
76
- "typescript": "^4.5.4"
76
+ "typescript": "^4.5.5"
77
77
  }
78
78
  }