react-native-bootsplash 3.2.5 → 4.0.0-beta.1

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.
@@ -5,22 +5,16 @@
5
5
  #import <React/RCTUtils.h>
6
6
 
7
7
  static NSMutableArray<RNBootSplashTask *> *_taskQueue = nil;
8
- static NSString *_storyboardName = @"BootSplash";
9
8
  static RCTRootView *_rootView = nil;
10
9
  static RNBootSplashStatus _status = RNBootSplashStatusHidden;
11
- static UIViewController *_splashVC = nil;
12
10
 
13
11
  @implementation RNBootSplashTask
14
12
 
15
- - (instancetype)initWithType:(RNBootSplashTaskType)type
16
- fade:(BOOL)fade
17
- resolver:(RCTPromiseResolveBlock _Nonnull)resolve
18
- rejecter:(RCTPromiseRejectBlock _Nonnull)reject {
13
+ - (instancetype)initWithFade:(BOOL)fade
14
+ resolver:(RCTPromiseResolveBlock _Nonnull)resolve {
19
15
  if (self = [super init]) {
20
- _type = type;
21
16
  _fade = fade;
22
17
  _resolve = resolve;
23
- _reject = reject;
24
18
  }
25
19
 
26
20
  return self;
@@ -42,36 +36,17 @@ RCT_EXPORT_MODULE();
42
36
 
43
37
  + (void)initWithStoryboard:(NSString * _Nonnull)storyboardName
44
38
  rootView:(RCTRootView * _Nonnull)rootView {
45
- UIViewController *rootVC = RCTPresentedViewController();
46
-
47
- if (!rootVC) {
48
- RCTLogWarn(@"react-native-bootsplash has been initialized too early: rootViewController must be set");
49
- return;
50
- }
51
-
52
39
  _rootView = rootView;
53
40
  _status = RNBootSplashStatusVisible;
54
- _storyboardName = storyboardName;
55
41
  _taskQueue = [[NSMutableArray alloc] init];
56
42
 
57
- UIStoryboard *storyboard = [UIStoryboard storyboardWithName:_storyboardName bundle:nil];
43
+ UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
58
44
  [_rootView setLoadingView:[[storyboard instantiateInitialViewController] view]];
59
45
 
60
46
  [[NSNotificationCenter defaultCenter] removeObserver:rootView
61
47
  name:RCTContentDidAppearNotification
62
48
  object:rootView];
63
49
 
64
- _splashVC = [storyboard instantiateInitialViewController];
65
- [_splashVC setModalPresentationStyle:UIModalPresentationOverFullScreen];
66
- [_splashVC setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
67
-
68
- [rootVC presentViewController:_splashVC animated:false completion:^{
69
- [_rootView.loadingView removeFromSuperview];
70
- _rootView.loadingView = nil;
71
-
72
- [self shiftNextTask]; // JS thread might started pushing tasks
73
- }];
74
-
75
50
  [[NSNotificationCenter defaultCenter] addObserver:self
76
51
  selector:@selector(onJavaScriptDidLoad:)
77
52
  name:RCTJavaScriptDidLoadNotification
@@ -99,20 +74,19 @@ RCT_EXPORT_MODULE();
99
74
  }
100
75
 
101
76
  + (void)onJavaScriptDidFailToLoad {
102
- if (_splashVC != nil) {
103
- [_splashVC dismissViewControllerAnimated:false
104
- completion:^{
105
- _splashVC = nil;
106
- }];
77
+ _status = RNBootSplashStatusHidden;
78
+
79
+ if (_rootView != nil) {
80
+ _rootView.loadingView.hidden = YES;
81
+ [_rootView.loadingView removeFromSuperview];
82
+ _rootView.loadingView = nil;
107
83
  }
108
84
 
109
85
  [[NSNotificationCenter defaultCenter] removeObserver:self];
110
86
  }
111
87
 
112
88
  + (void)shiftNextTask {
113
- bool shouldSkipTick = _rootView.loadingView != nil
114
- || _status == RNBootSplashStatusTransitioningToVisible
115
- || _status == RNBootSplashStatusTransitioningToHidden
89
+ bool shouldSkipTick = _status == RNBootSplashStatusTransitioning
116
90
  || [_taskQueue count] == 0
117
91
  || [[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground;
118
92
 
@@ -121,81 +95,54 @@ RCT_EXPORT_MODULE();
121
95
  RNBootSplashTask *task = [_taskQueue objectAtIndex:0];
122
96
  [_taskQueue removeObjectAtIndex:0];
123
97
 
124
- switch (task.type) {
125
- case RNBootSplashTaskTypeShow:
126
- return [self showWithTask:task];
127
- case RNBootSplashTaskTypeHide:
128
- return [self hideWithTask:task];
129
- }
98
+ return [self hideWithTask:task];
130
99
  }
131
100
 
132
- + (void)showWithTask:(RNBootSplashTask *)task {
133
- if (_splashVC != nil) {
134
- task.resolve(@(true)); // splash screen is already visible
135
- [self shiftNextTask];
136
- } else {
137
- _status = RNBootSplashStatusTransitioningToVisible;
138
-
139
- _splashVC = [[UIStoryboard storyboardWithName:_storyboardName bundle:nil] instantiateInitialViewController];
140
- [_splashVC setModalPresentationStyle:UIModalPresentationOverFullScreen];
141
- [_splashVC setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
142
-
143
- [RCTPresentedViewController() presentViewController:_splashVC
144
- animated:task.fade
145
- completion:^{
146
- _status = RNBootSplashStatusVisible;
147
-
148
- task.resolve(@(true));
149
- [self shiftNextTask];
150
- }];
101
+ + (void)hideWithTask:(RNBootSplashTask *)task {
102
+ if (_status == RNBootSplashStatusHidden) {
103
+ task.resolve(@(true));
104
+ return [self shiftNextTask];
151
105
  }
152
- }
153
106
 
154
- + (void)hideWithTask:(RNBootSplashTask *)task {
155
- if (_splashVC == nil) {
156
- task.resolve(@(true)); // splash screen is already hidden
157
- [self shiftNextTask];
158
- } else {
159
- _status = RNBootSplashStatusTransitioningToHidden;
160
-
161
- [_splashVC dismissViewControllerAnimated:task.fade
162
- completion:^{
163
- _splashVC = nil;
164
- _status = RNBootSplashStatusHidden;
165
-
166
- task.resolve(@(true));
167
- [self shiftNextTask];
168
- }];
107
+ if (!task.fade) {
108
+ _status = RNBootSplashStatusHidden;
109
+
110
+ _rootView.loadingView.hidden = YES;
111
+ [_rootView.loadingView removeFromSuperview];
112
+ _rootView.loadingView = nil;
113
+
114
+ task.resolve(@(true));
115
+ return [self shiftNextTask];
169
116
  }
170
- }
171
117
 
172
- RCT_REMAP_METHOD(show,
173
- showWithFade:(BOOL)fade
174
- resolver:(RCTPromiseResolveBlock)resolve
175
- rejecter:(RCTPromiseRejectBlock)reject) {
176
- if (_rootView == nil)
177
- return reject(@"uninitialized_module", @"react-native-bootsplash has not been initialized, or has been too early", nil);
118
+ _status = RNBootSplashStatusTransitioning;
178
119
 
179
- RNBootSplashTask *task = [[RNBootSplashTask alloc] initWithType:RNBootSplashTaskTypeShow
180
- fade:fade
181
- resolver:resolve
182
- rejecter:reject];
120
+ [UIView transitionWithView:_rootView
121
+ duration:0.220
122
+ options:UIViewAnimationOptionTransitionCrossDissolve
123
+ animations:^{
124
+ _rootView.loadingView.hidden = YES;
125
+ }
126
+ completion:^(__unused BOOL finished) {
127
+ _status = RNBootSplashStatusHidden;
183
128
 
184
- [_taskQueue addObject:task];
185
- [RNBootSplash shiftNextTask];
129
+ [_rootView.loadingView removeFromSuperview];
130
+ _rootView.loadingView = nil;
131
+
132
+ task.resolve(@(true));
133
+ return [self shiftNextTask];
134
+ }];
186
135
  }
187
136
 
188
137
  RCT_REMAP_METHOD(hide,
189
138
  hideWithFade:(BOOL)fade
190
139
  resolver:(RCTPromiseResolveBlock)resolve
191
140
  rejecter:(RCTPromiseRejectBlock)reject) {
192
- if (_rootView == nil)
193
- return reject(@"uninitialized_module", @"react-native-bootsplash has not been initialized, or has been too early", nil);
141
+ if (_rootView == nil || _status == RNBootSplashStatusHidden)
142
+ return resolve(@(true));
194
143
 
195
- RNBootSplashTask *task = [[RNBootSplashTask alloc] initWithType:RNBootSplashTaskTypeHide
196
- fade:fade
197
- resolver:resolve
198
- rejecter:reject];
144
+ RNBootSplashTask *task = [[RNBootSplashTask alloc] initWithFade:fade
145
+ resolver:resolve];
199
146
 
200
147
  [_taskQueue addObject:task];
201
148
  [RNBootSplash shiftNextTask];
@@ -209,8 +156,7 @@ RCT_REMAP_METHOD(getVisibilityStatus,
209
156
  return resolve(@"visible");
210
157
  case RNBootSplashStatusHidden:
211
158
  return resolve(@"hidden");
212
- case RNBootSplashStatusTransitioningToVisible:
213
- case RNBootSplashStatusTransitioningToHidden:
159
+ case RNBootSplashStatusTransitioning:
214
160
  return resolve(@"transitioning");
215
161
  }
216
162
  }
@@ -133,7 +133,7 @@
133
133
  GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
134
134
  GCC_WARN_UNUSED_FUNCTION = YES;
135
135
  GCC_WARN_UNUSED_VARIABLE = YES;
136
- IPHONEOS_DEPLOYMENT_TARGET = 9.0;
136
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
137
137
  MTL_ENABLE_DEBUG_INFO = YES;
138
138
  ONLY_ACTIVE_ARCH = YES;
139
139
  SDKROOT = iphoneos;
@@ -174,7 +174,7 @@
174
174
  GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
175
175
  GCC_WARN_UNUSED_FUNCTION = YES;
176
176
  GCC_WARN_UNUSED_VARIABLE = YES;
177
- IPHONEOS_DEPLOYMENT_TARGET = 9.0;
177
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
178
178
  MTL_ENABLE_DEBUG_INFO = NO;
179
179
  SDKROOT = iphoneos;
180
180
  SKIP_INSTALL = YES;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "react-native-bootsplash",
3
- "version": "3.2.5",
3
+ "version": "4.0.0-beta.1",
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>",
7
7
  "homepage": "https://github.com/zoontek/react-native-bootsplash",
8
- "types": "dist/typescript/index.d.ts",
9
8
  "main": "dist/commonjs/index.js",
10
9
  "module": "dist/module/index.js",
10
+ "types": "dist/typescript/index.d.ts",
11
11
  "files": [
12
12
  "/android",
13
13
  "/dist",
@@ -37,9 +37,10 @@
37
37
  ],
38
38
  "scripts": {
39
39
  "format": "prettier '**/*.{js,json,md,ts,tsx}' --write",
40
- "prepare": "bob build"
40
+ "setup-hooks": "git config --local core.hooksPath .hooks",
41
+ "prepare": "yarn setup-hooks && bob build"
41
42
  },
42
- "@react-native-community/bob": {
43
+ "react-native-builder-bob": {
43
44
  "source": "src",
44
45
  "output": "dist",
45
46
  "targets": [
@@ -48,16 +49,14 @@
48
49
  "typescript"
49
50
  ]
50
51
  },
51
- "husky": {
52
- "hooks": {
53
- "pre-commit": "lint-staged"
54
- }
52
+ "prettier": {
53
+ "trailingComma": "all"
55
54
  },
56
55
  "lint-staged": {
57
56
  "**/*.{js,json,md,ts,tsx}": "prettier --write"
58
57
  },
59
58
  "peerDependencies": {
60
- "react-native": ">=0.60.0"
59
+ "react-native": ">=0.65.0"
61
60
  },
62
61
  "dependencies": {
63
62
  "chalk": "^4.1.2",
@@ -65,16 +64,15 @@
65
64
  "jimp": "^0.16.1"
66
65
  },
67
66
  "devDependencies": {
68
- "@babel/core": "^7.15.0",
69
- "@react-native-community/bob": "^0.17.1",
70
- "@types/fs-extra": "^9.0.12",
71
- "@types/react-native": "^0.64.13",
67
+ "@types/fs-extra": "^9.0.13",
68
+ "@types/react-native": "^0.66.4",
72
69
  "bs-platform": "^9.0.2",
73
- "husky": "^4.3.8",
74
- "lint-staged": "^11.1.2",
75
- "prettier": "^2.3.2",
76
- "react": "17.0.2",
77
- "react-native": "^0.63.4",
78
- "typescript": "^4.3.5"
70
+ "lint-staged": "^11.2.6",
71
+ "prettier": "^2.4.1",
72
+ "prettier-plugin-organize-imports": "^2.3.4",
73
+ "react": "^17.0.2",
74
+ "react-native": "^0.66.3",
75
+ "react-native-builder-bob": "^0.18.2",
76
+ "typescript": "^4.4.4"
79
77
  }
80
78
  }
@@ -37,21 +37,34 @@ module.exports = {
37
37
  { project: { android, ios } },
38
38
  { backgroundColor, logoWidth, assetsPath, flavor },
39
39
  ) => {
40
- const workingDirectory =
40
+ const workingPath =
41
41
  process.env.INIT_CWD || process.env.PWD || process.cwd();
42
42
 
43
+ if (logoWidth > 288) {
44
+ console.log(
45
+ "❌ Logo width can't be superior to 288dp as it will be cropped on Android. Exiting…\n",
46
+ );
47
+
48
+ process.exit(1);
49
+ } else if (logoWidth > 192) {
50
+ console.log(
51
+ "⚠️ As logo width is superior to 192dp, it might be cropped on Android.\n",
52
+ );
53
+ }
54
+
43
55
  return generate({
44
56
  android,
45
57
  ios,
46
58
 
47
- workingDirectory,
48
- logoPath: path.resolve(workingDirectory, logoPath),
49
- backgroundColor,
50
- logoWidth,
51
- flavor,
59
+ workingPath,
60
+ logoPath: path.resolve(workingPath, logoPath),
52
61
  assetsPath: assetsPath
53
- ? path.resolve(workingDirectory, assetsPath)
62
+ ? path.resolve(workingPath, assetsPath)
54
63
  : undefined,
64
+
65
+ backgroundColor,
66
+ flavor,
67
+ logoWidth,
55
68
  }).catch((error) => {
56
69
  console.error(error);
57
70
  });