react-native-bootsplash 3.2.6 → 4.0.0-beta.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.
@@ -4,22 +4,16 @@
4
4
  #import <React/RCTUtils.h>
5
5
 
6
6
  static NSMutableArray<RNBootSplashTask *> *_taskQueue = nil;
7
- static NSString *_storyboardName = @"BootSplash";
8
7
  static RCTRootView *_rootView = nil;
9
8
  static RNBootSplashStatus _status = RNBootSplashStatusHidden;
10
- static UIViewController *_splashVC = nil;
11
9
 
12
10
  @implementation RNBootSplashTask
13
11
 
14
- - (instancetype)initWithType:(RNBootSplashTaskType)type
15
- fade:(BOOL)fade
16
- resolver:(RCTPromiseResolveBlock _Nonnull)resolve
17
- rejecter:(RCTPromiseRejectBlock _Nonnull)reject {
12
+ - (instancetype)initWithFade:(BOOL)fade
13
+ resolver:(RCTPromiseResolveBlock _Nonnull)resolve {
18
14
  if (self = [super init]) {
19
- _type = type;
20
15
  _fade = fade;
21
16
  _resolve = resolve;
22
- _reject = reject;
23
17
  }
24
18
 
25
19
  return self;
@@ -43,29 +37,15 @@ RCT_EXPORT_MODULE();
43
37
  rootView:(RCTRootView * _Nonnull)rootView {
44
38
  _rootView = rootView;
45
39
  _status = RNBootSplashStatusVisible;
46
- _storyboardName = storyboardName;
47
40
  _taskQueue = [[NSMutableArray alloc] init];
48
41
 
49
- UIStoryboard *storyboard = [UIStoryboard storyboardWithName:_storyboardName bundle:nil];
42
+ UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
50
43
  [_rootView setLoadingView:[[storyboard instantiateInitialViewController] view]];
51
44
 
52
45
  [[NSNotificationCenter defaultCenter] removeObserver:rootView
53
46
  name:RCTContentDidAppearNotification
54
47
  object:rootView];
55
48
 
56
- _splashVC = [storyboard instantiateInitialViewController];
57
- [_splashVC setModalPresentationStyle:UIModalPresentationOverFullScreen];
58
- [_splashVC setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
59
-
60
- [RCTPresentedViewController() presentViewController:_splashVC
61
- animated:false
62
- completion:^{
63
- [_rootView.loadingView removeFromSuperview];
64
- _rootView.loadingView = nil;
65
-
66
- [self shiftNextTask]; // JS thread might started pushing tasks
67
- }];
68
-
69
49
  [[NSNotificationCenter defaultCenter] addObserver:self
70
50
  selector:@selector(onJavaScriptDidLoad:)
71
51
  name:RCTJavaScriptDidLoadNotification
@@ -93,20 +73,19 @@ RCT_EXPORT_MODULE();
93
73
  }
94
74
 
95
75
  + (void)onJavaScriptDidFailToLoad {
96
- if (_splashVC != nil) {
97
- [_splashVC dismissViewControllerAnimated:false
98
- completion:^{
99
- _splashVC = nil;
100
- }];
76
+ _status = RNBootSplashStatusHidden;
77
+
78
+ if (_rootView != nil) {
79
+ _rootView.loadingView.hidden = YES;
80
+ [_rootView.loadingView removeFromSuperview];
81
+ _rootView.loadingView = nil;
101
82
  }
102
83
 
103
84
  [[NSNotificationCenter defaultCenter] removeObserver:self];
104
85
  }
105
86
 
106
87
  + (void)shiftNextTask {
107
- bool shouldSkipTick = _rootView.loadingView != nil
108
- || _status == RNBootSplashStatusTransitioningToVisible
109
- || _status == RNBootSplashStatusTransitioningToHidden
88
+ bool shouldSkipTick = _status == RNBootSplashStatusTransitioning
110
89
  || [_taskQueue count] == 0
111
90
  || [[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground;
112
91
 
@@ -115,81 +94,54 @@ RCT_EXPORT_MODULE();
115
94
  RNBootSplashTask *task = [_taskQueue objectAtIndex:0];
116
95
  [_taskQueue removeObjectAtIndex:0];
117
96
 
118
- switch (task.type) {
119
- case RNBootSplashTaskTypeShow:
120
- return [self showWithTask:task];
121
- case RNBootSplashTaskTypeHide:
122
- return [self hideWithTask:task];
123
- }
97
+ return [self hideWithTask:task];
124
98
  }
125
99
 
126
- + (void)showWithTask:(RNBootSplashTask *)task {
127
- if (_splashVC != nil) {
128
- task.resolve(@(true)); // splash screen is already visible
129
- [self shiftNextTask];
130
- } else {
131
- _status = RNBootSplashStatusTransitioningToVisible;
132
-
133
- _splashVC = [[UIStoryboard storyboardWithName:_storyboardName bundle:nil] instantiateInitialViewController];
134
- [_splashVC setModalPresentationStyle:UIModalPresentationOverFullScreen];
135
- [_splashVC setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
136
-
137
- [RCTPresentedViewController() presentViewController:_splashVC
138
- animated:task.fade
139
- completion:^{
140
- _status = RNBootSplashStatusVisible;
141
-
142
- task.resolve(@(true));
143
- [self shiftNextTask];
144
- }];
100
+ + (void)hideWithTask:(RNBootSplashTask *)task {
101
+ if (_status == RNBootSplashStatusHidden) {
102
+ task.resolve(@(true));
103
+ return [self shiftNextTask];
145
104
  }
146
- }
147
105
 
148
- + (void)hideWithTask:(RNBootSplashTask *)task {
149
- if (_splashVC == nil) {
150
- task.resolve(@(true)); // splash screen is already hidden
151
- [self shiftNextTask];
152
- } else {
153
- _status = RNBootSplashStatusTransitioningToHidden;
154
-
155
- [_splashVC dismissViewControllerAnimated:task.fade
156
- completion:^{
157
- _splashVC = nil;
158
- _status = RNBootSplashStatusHidden;
159
-
160
- task.resolve(@(true));
161
- [self shiftNextTask];
162
- }];
106
+ if (!task.fade) {
107
+ _status = RNBootSplashStatusHidden;
108
+
109
+ _rootView.loadingView.hidden = YES;
110
+ [_rootView.loadingView removeFromSuperview];
111
+ _rootView.loadingView = nil;
112
+
113
+ task.resolve(@(true));
114
+ return [self shiftNextTask];
163
115
  }
164
- }
165
116
 
166
- RCT_REMAP_METHOD(show,
167
- showWithFade:(BOOL)fade
168
- resolver:(RCTPromiseResolveBlock)resolve
169
- rejecter:(RCTPromiseRejectBlock)reject) {
170
- if (_rootView == nil)
171
- return reject(@"uninitialized_module", @"react-native-bootsplash has not been initialized, or has been too early", nil);
117
+ _status = RNBootSplashStatusTransitioning;
172
118
 
173
- RNBootSplashTask *task = [[RNBootSplashTask alloc] initWithType:RNBootSplashTaskTypeShow
174
- fade:fade
175
- resolver:resolve
176
- rejecter:reject];
119
+ [UIView transitionWithView:_rootView
120
+ duration:0.220
121
+ options:UIViewAnimationOptionTransitionCrossDissolve
122
+ animations:^{
123
+ _rootView.loadingView.hidden = YES;
124
+ }
125
+ completion:^(__unused BOOL finished) {
126
+ _status = RNBootSplashStatusHidden;
177
127
 
178
- [_taskQueue addObject:task];
179
- [RNBootSplash shiftNextTask];
128
+ [_rootView.loadingView removeFromSuperview];
129
+ _rootView.loadingView = nil;
130
+
131
+ task.resolve(@(true));
132
+ return [self shiftNextTask];
133
+ }];
180
134
  }
181
135
 
182
136
  RCT_REMAP_METHOD(hide,
183
137
  hideWithFade:(BOOL)fade
184
138
  resolver:(RCTPromiseResolveBlock)resolve
185
139
  rejecter:(RCTPromiseRejectBlock)reject) {
186
- if (_rootView == nil)
187
- return reject(@"uninitialized_module", @"react-native-bootsplash has not been initialized, or has been too early", nil);
140
+ if (_rootView == nil || _status == RNBootSplashStatusHidden)
141
+ return resolve(@(true));
188
142
 
189
- RNBootSplashTask *task = [[RNBootSplashTask alloc] initWithType:RNBootSplashTaskTypeHide
190
- fade:fade
191
- resolver:resolve
192
- rejecter:reject];
143
+ RNBootSplashTask *task = [[RNBootSplashTask alloc] initWithFade:fade
144
+ resolver:resolve];
193
145
 
194
146
  [_taskQueue addObject:task];
195
147
  [RNBootSplash shiftNextTask];
@@ -203,8 +155,7 @@ RCT_REMAP_METHOD(getVisibilityStatus,
203
155
  return resolve(@"visible");
204
156
  case RNBootSplashStatusHidden:
205
157
  return resolve(@"hidden");
206
- case RNBootSplashStatusTransitioningToVisible:
207
- case RNBootSplashStatusTransitioningToHidden:
158
+ case RNBootSplashStatusTransitioning:
208
159
  return resolve(@"transitioning");
209
160
  }
210
161
  }
@@ -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.6",
3
+ "version": "4.0.0-beta.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>",
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
  }
@@ -16,7 +16,7 @@ module.exports = {
16
16
  {
17
17
  name: "--logo-width <width>",
18
18
  description:
19
- "logo width at @1x (in dp - we recommand approximately ~100)",
19
+ "logo width at @1x (in dp - we recommend approximately ~100)",
20
20
  default: 100,
21
21
  parse: (value) => parseInt(value, 10),
22
22
  },
@@ -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
  });