react-native-bootsplash 4.0.0-alpha.0 → 4.0.0-beta.3
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/LICENSE +1 -1
- package/README.md +76 -135
- package/RNBootSplash.podspec +1 -1
- package/{ReactNativeBootsplash.res → RNBootsplash.res} +4 -8
- package/android/build.gradle +13 -11
- package/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplash.java +2 -11
- package/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashModule.java +79 -198
- package/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashPackage.java +6 -2
- package/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashTask.java +1 -15
- package/bsconfig.json +0 -1
- package/dist/commonjs/generate.js +118 -110
- package/dist/commonjs/generate.js.map +1 -1
- package/dist/commonjs/index.js +5 -19
- package/dist/commonjs/index.js.map +1 -1
- package/dist/module/generate.js +114 -107
- package/dist/module/generate.js.map +1 -1
- package/dist/module/index.js +3 -13
- package/dist/module/index.js.map +1 -1
- package/dist/typescript/generate.d.ts +4 -4
- package/dist/typescript/index.d.ts +0 -6
- package/ios/RNBootSplash.h +3 -13
- package/ios/RNBootSplash.m +44 -93
- package/ios/RNBootSplash.xcodeproj/project.pbxproj +2 -2
- package/package.json +21 -23
- package/react-native.config.js +21 -8
- package/src/generate.ts +98 -139
- package/src/index.ts +0 -13
- package/android/src/main/java/com/zoontek/rnbootsplash/RNBootSplashDialog.java +0 -36
- package/android/src/main/res/anim/bootsplash_fade_in.xml +0 -7
- package/android/src/main/res/anim/bootsplash_fade_out.xml +0 -7
- package/android/src/main/res/values/styles.xml +0 -13
package/src/generate.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import fs from "fs-extra";
|
|
3
|
-
import
|
|
3
|
+
import Jimp from "jimp";
|
|
4
4
|
import path from "path";
|
|
5
5
|
|
|
6
6
|
const logoFileName = "bootsplash_logo";
|
|
7
7
|
const xcassetName = "BootSplashLogo";
|
|
8
|
+
// https://github.com/androidx/androidx/blob/androidx-main/core/core-splashscreen/src/main/res/values/dimens.xml#L22
|
|
9
|
+
const splashScreenIconSizeNoBackground = 288;
|
|
8
10
|
const androidColorName = "bootsplash_background";
|
|
9
11
|
const androidColorRegex = /<color name="bootsplash_background">#\w+<\/color>/g;
|
|
10
12
|
|
|
@@ -96,17 +98,6 @@ const getStoryboard = ({
|
|
|
96
98
|
`;
|
|
97
99
|
};
|
|
98
100
|
|
|
99
|
-
const bootSplashXml = `<?xml version="1.0" encoding="utf-8"?>
|
|
100
|
-
|
|
101
|
-
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
|
|
102
|
-
<item android:drawable="@color/${androidColorName}" />
|
|
103
|
-
|
|
104
|
-
<item>
|
|
105
|
-
<bitmap android:src="@mipmap/${logoFileName}" android:gravity="center" />
|
|
106
|
-
</item>
|
|
107
|
-
</layer-list>
|
|
108
|
-
`;
|
|
109
|
-
|
|
110
101
|
const log = (text: string, dim = false) => {
|
|
111
102
|
console.log(dim ? chalk.dim(text) : text);
|
|
112
103
|
};
|
|
@@ -127,7 +118,7 @@ export const generate = async ({
|
|
|
127
118
|
android,
|
|
128
119
|
ios,
|
|
129
120
|
|
|
130
|
-
|
|
121
|
+
workingPath,
|
|
131
122
|
logoPath,
|
|
132
123
|
backgroundColor,
|
|
133
124
|
logoWidth,
|
|
@@ -142,12 +133,13 @@ export const generate = async ({
|
|
|
142
133
|
projectPath: string;
|
|
143
134
|
} | null;
|
|
144
135
|
|
|
145
|
-
|
|
136
|
+
workingPath: string;
|
|
146
137
|
logoPath: string;
|
|
138
|
+
assetsPath?: string;
|
|
139
|
+
|
|
147
140
|
backgroundColor: string;
|
|
148
|
-
logoWidth: number;
|
|
149
141
|
flavor: string;
|
|
150
|
-
|
|
142
|
+
logoWidth: number;
|
|
151
143
|
}) => {
|
|
152
144
|
if (!isValidHexadecimal(backgroundColor)) {
|
|
153
145
|
throw new Error(
|
|
@@ -155,61 +147,48 @@ export const generate = async ({
|
|
|
155
147
|
);
|
|
156
148
|
}
|
|
157
149
|
|
|
158
|
-
const image = await
|
|
150
|
+
const image = await Jimp.read(logoPath);
|
|
159
151
|
const backgroundColorHex = toFullHexadecimal(backgroundColor);
|
|
160
152
|
|
|
161
|
-
const images: {
|
|
162
|
-
filePath: string;
|
|
163
|
-
width: number;
|
|
164
|
-
height: number;
|
|
165
|
-
}[] = [];
|
|
166
|
-
|
|
167
153
|
const getHeight = (size: number) =>
|
|
168
154
|
Math.ceil(size * (image.bitmap.height / image.bitmap.width));
|
|
169
155
|
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
"@3x": getHeight(width["@3x"]),
|
|
183
|
-
"@4x": getHeight(width["@4x"]),
|
|
184
|
-
};
|
|
156
|
+
const logWrite = (
|
|
157
|
+
emoji: string,
|
|
158
|
+
filePath: string,
|
|
159
|
+
dimensions?: { width: number; height: number },
|
|
160
|
+
) =>
|
|
161
|
+
log(
|
|
162
|
+
`${emoji} ${path.relative(workingPath, filePath)}` +
|
|
163
|
+
(dimensions != null
|
|
164
|
+
? ` (${dimensions.width}x${dimensions.height})`
|
|
165
|
+
: ""),
|
|
166
|
+
true,
|
|
167
|
+
);
|
|
185
168
|
|
|
186
169
|
if (assetsPath && fs.existsSync(assetsPath)) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
filePath: path.resolve(assetsPath, logoFileName + "@4x.png"),
|
|
210
|
-
width: width["@4x"],
|
|
211
|
-
height: height["@4x"],
|
|
212
|
-
},
|
|
170
|
+
await Promise.all(
|
|
171
|
+
[
|
|
172
|
+
{ ratio: 1, suffix: "" },
|
|
173
|
+
{ ratio: 1.5, suffix: "@1,5x" },
|
|
174
|
+
{ ratio: 2, suffix: "@2x" },
|
|
175
|
+
{ ratio: 3, suffix: "@3x" },
|
|
176
|
+
{ ratio: 4, suffix: "@4x" },
|
|
177
|
+
].map(({ ratio, suffix }) => {
|
|
178
|
+
const fileName = `${logoFileName}${suffix}.png`;
|
|
179
|
+
const filePath = path.resolve(assetsPath, fileName);
|
|
180
|
+
const width = logoWidth * ratio;
|
|
181
|
+
const height = getHeight(width);
|
|
182
|
+
|
|
183
|
+
return image
|
|
184
|
+
.clone()
|
|
185
|
+
.resize(width, height)
|
|
186
|
+
.quality(100)
|
|
187
|
+
.writeAsync(filePath)
|
|
188
|
+
.then(() => {
|
|
189
|
+
logWrite("✨", filePath, { width, height });
|
|
190
|
+
});
|
|
191
|
+
}),
|
|
213
192
|
);
|
|
214
193
|
}
|
|
215
194
|
|
|
@@ -219,16 +198,10 @@ export const generate = async ({
|
|
|
219
198
|
: path.resolve(android.sourceDir); // @react-native-community/cli 2.x & 3.x support
|
|
220
199
|
|
|
221
200
|
const resPath = path.resolve(appPath, "src", flavor, "res");
|
|
222
|
-
const drawablePath = path.resolve(resPath, "drawable");
|
|
223
201
|
const valuesPath = path.resolve(resPath, "values");
|
|
224
202
|
|
|
225
|
-
fs.ensureDirSync(drawablePath);
|
|
226
203
|
fs.ensureDirSync(valuesPath);
|
|
227
204
|
|
|
228
|
-
const bootSplashXmlPath = path.resolve(drawablePath, "bootsplash.xml");
|
|
229
|
-
fs.writeFileSync(bootSplashXmlPath, bootSplashXml, "utf-8");
|
|
230
|
-
log(`✨ ${path.relative(workingDirectory, bootSplashXmlPath)}`, true);
|
|
231
|
-
|
|
232
205
|
const colorsXmlPath = path.resolve(valuesPath, "colors.xml");
|
|
233
206
|
const colorsXmlEntry = `<color name="${androidColorName}">${backgroundColorHex}</color>`;
|
|
234
207
|
|
|
@@ -252,7 +225,7 @@ export const generate = async ({
|
|
|
252
225
|
);
|
|
253
226
|
}
|
|
254
227
|
|
|
255
|
-
|
|
228
|
+
logWrite("✏️ ", colorsXmlPath);
|
|
256
229
|
} else {
|
|
257
230
|
fs.writeFileSync(
|
|
258
231
|
colorsXmlPath,
|
|
@@ -260,39 +233,39 @@ export const generate = async ({
|
|
|
260
233
|
"utf-8",
|
|
261
234
|
);
|
|
262
235
|
|
|
263
|
-
|
|
236
|
+
logWrite("✨", colorsXmlPath);
|
|
264
237
|
}
|
|
265
238
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
},
|
|
239
|
+
await Promise.all(
|
|
240
|
+
[
|
|
241
|
+
{ ratio: 1, directory: "mipmap-mdpi" },
|
|
242
|
+
{ ratio: 1.5, directory: "mipmap-hdpi" },
|
|
243
|
+
{ ratio: 2, directory: "mipmap-xhdpi" },
|
|
244
|
+
{ ratio: 3, directory: "mipmap-xxhdpi" },
|
|
245
|
+
{ ratio: 4, directory: "mipmap-xxxhdpi" },
|
|
246
|
+
].map(({ ratio, directory }) => {
|
|
247
|
+
const fileName = `${logoFileName}.png`;
|
|
248
|
+
const filePath = path.resolve(resPath, directory, fileName);
|
|
249
|
+
const width = logoWidth * ratio;
|
|
250
|
+
const height = getHeight(width);
|
|
251
|
+
|
|
252
|
+
const canvasSize = splashScreenIconSizeNoBackground * ratio;
|
|
253
|
+
|
|
254
|
+
// https://github.com/oliver-moran/jimp/tree/master/packages/jimp#creating-new-images
|
|
255
|
+
const canvas = new Jimp(canvasSize, canvasSize, 0xffffff00);
|
|
256
|
+
const logo = image.clone().resize(width, height);
|
|
257
|
+
|
|
258
|
+
const x = (canvasSize - width) / 2;
|
|
259
|
+
const y = (canvasSize - height) / 2;
|
|
260
|
+
|
|
261
|
+
return canvas
|
|
262
|
+
.blit(logo, x, y)
|
|
263
|
+
.quality(100)
|
|
264
|
+
.writeAsync(filePath)
|
|
265
|
+
.then(() => {
|
|
266
|
+
logWrite("✨", filePath, { width: canvasSize, height: canvasSize });
|
|
267
|
+
});
|
|
268
|
+
}),
|
|
296
269
|
);
|
|
297
270
|
}
|
|
298
271
|
|
|
@@ -306,14 +279,14 @@ export const generate = async ({
|
|
|
306
279
|
fs.writeFileSync(
|
|
307
280
|
storyboardPath,
|
|
308
281
|
getStoryboard({
|
|
309
|
-
height:
|
|
310
|
-
width:
|
|
282
|
+
height: getHeight(logoWidth),
|
|
283
|
+
width: logoWidth,
|
|
311
284
|
backgroundColor: backgroundColorHex,
|
|
312
285
|
}),
|
|
313
286
|
"utf-8",
|
|
314
287
|
);
|
|
315
288
|
|
|
316
|
-
log(`✨ ${path.relative(
|
|
289
|
+
log(`✨ ${path.relative(workingPath, storyboardPath)}`, true);
|
|
317
290
|
} else {
|
|
318
291
|
log(
|
|
319
292
|
`No "${projectPath}" directory found. Skipping iOS storyboard generation…`,
|
|
@@ -330,22 +303,26 @@ export const generate = async ({
|
|
|
330
303
|
"utf-8",
|
|
331
304
|
);
|
|
332
305
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
filePath
|
|
341
|
-
width
|
|
342
|
-
height
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
306
|
+
await Promise.all(
|
|
307
|
+
[
|
|
308
|
+
{ ratio: 1, suffix: "" },
|
|
309
|
+
{ ratio: 2, suffix: "@2x" },
|
|
310
|
+
{ ratio: 3, suffix: "@3x" },
|
|
311
|
+
].map(({ ratio, suffix }) => {
|
|
312
|
+
const fileName = `${logoFileName}${suffix}.png`;
|
|
313
|
+
const filePath = path.resolve(imageSetPath, fileName);
|
|
314
|
+
const width = logoWidth * ratio;
|
|
315
|
+
const height = getHeight(width);
|
|
316
|
+
|
|
317
|
+
return image
|
|
318
|
+
.clone()
|
|
319
|
+
.resize(width, height)
|
|
320
|
+
.quality(100)
|
|
321
|
+
.writeAsync(filePath)
|
|
322
|
+
.then(() => {
|
|
323
|
+
logWrite("✨", filePath, { width, height });
|
|
324
|
+
});
|
|
325
|
+
}),
|
|
349
326
|
);
|
|
350
327
|
} else {
|
|
351
328
|
log(
|
|
@@ -354,24 +331,6 @@ export const generate = async ({
|
|
|
354
331
|
}
|
|
355
332
|
}
|
|
356
333
|
|
|
357
|
-
await Promise.all(
|
|
358
|
-
images.map(({ filePath, width, height }) =>
|
|
359
|
-
image
|
|
360
|
-
.clone()
|
|
361
|
-
.cover(width, height)
|
|
362
|
-
.writeAsync(filePath)
|
|
363
|
-
.then(() => {
|
|
364
|
-
log(
|
|
365
|
-
`✨ ${path.relative(
|
|
366
|
-
workingDirectory,
|
|
367
|
-
filePath,
|
|
368
|
-
)} (${width}x${height})`,
|
|
369
|
-
true,
|
|
370
|
-
);
|
|
371
|
-
}),
|
|
372
|
-
),
|
|
373
|
-
);
|
|
374
|
-
|
|
375
334
|
log(
|
|
376
335
|
`✅ Done! Thanks for using ${chalk.underline("react-native-bootsplash")}.`,
|
|
377
336
|
);
|
package/src/index.ts
CHANGED
|
@@ -4,17 +4,10 @@ export type VisibilityStatus = "visible" | "hidden" | "transitioning";
|
|
|
4
4
|
export type Config = { fade?: boolean };
|
|
5
5
|
|
|
6
6
|
const NativeModule: {
|
|
7
|
-
show: (fade: boolean) => Promise<true>;
|
|
8
7
|
hide: (fade: boolean) => Promise<true>;
|
|
9
8
|
getVisibilityStatus: () => Promise<VisibilityStatus>;
|
|
10
|
-
statusBarHeight: number;
|
|
11
|
-
navigationBarHeight: number;
|
|
12
9
|
} = NativeModules.RNBootSplash;
|
|
13
10
|
|
|
14
|
-
export function show(config: Config = {}): Promise<void> {
|
|
15
|
-
return NativeModule.show({ fade: false, ...config }.fade).then(() => {});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
11
|
export function hide(config: Config = {}): Promise<void> {
|
|
19
12
|
return NativeModule.hide({ fade: false, ...config }.fade).then(() => {});
|
|
20
13
|
}
|
|
@@ -23,13 +16,7 @@ export function getVisibilityStatus(): Promise<VisibilityStatus> {
|
|
|
23
16
|
return NativeModule.getVisibilityStatus();
|
|
24
17
|
}
|
|
25
18
|
|
|
26
|
-
export const statusBarHeight = NativeModule.statusBarHeight;
|
|
27
|
-
export const navigationBarHeight = NativeModule.navigationBarHeight;
|
|
28
|
-
|
|
29
19
|
export default {
|
|
30
|
-
show,
|
|
31
20
|
hide,
|
|
32
21
|
getVisibilityStatus,
|
|
33
|
-
statusBarHeight,
|
|
34
|
-
navigationBarHeight,
|
|
35
22
|
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
package com.zoontek.rnbootsplash;
|
|
2
|
-
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
import android.app.Dialog;
|
|
5
|
-
import android.os.Bundle;
|
|
6
|
-
import android.view.Window;
|
|
7
|
-
import android.widget.LinearLayout.LayoutParams;
|
|
8
|
-
|
|
9
|
-
import androidx.annotation.NonNull;
|
|
10
|
-
import androidx.annotation.StyleRes;
|
|
11
|
-
|
|
12
|
-
public class RNBootSplashDialog extends Dialog {
|
|
13
|
-
|
|
14
|
-
public RNBootSplashDialog(@NonNull final Activity activity,
|
|
15
|
-
@StyleRes final int bootThemeResId) {
|
|
16
|
-
super(activity, bootThemeResId);
|
|
17
|
-
setCancelable(false);
|
|
18
|
-
setCanceledOnTouchOutside(false);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@Override
|
|
22
|
-
public void onBackPressed() {
|
|
23
|
-
// Prevent default behavior
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
@Override
|
|
27
|
-
protected void onCreate(Bundle savedInstanceState) {
|
|
28
|
-
Window window = getWindow();
|
|
29
|
-
|
|
30
|
-
if (window != null) {
|
|
31
|
-
window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
super.onCreate(savedInstanceState);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
-
|
|
3
|
-
<resources>
|
|
4
|
-
<style name="bootsplash_no_animation">
|
|
5
|
-
<item name="android:windowEnterAnimation">@null</item>
|
|
6
|
-
<item name="android:windowExitAnimation">@null</item>
|
|
7
|
-
</style>
|
|
8
|
-
|
|
9
|
-
<style name="bootsplash_fade_animation">
|
|
10
|
-
<item name="android:windowEnterAnimation">@anim/bootsplash_fade_in</item>
|
|
11
|
-
<item name="android:windowExitAnimation">@anim/bootsplash_fade_out</item>
|
|
12
|
-
</style>
|
|
13
|
-
</resources>
|