react-native-bootsplash 6.0.0-beta.0 → 6.0.0-beta.10
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/README.md +33 -88
- package/android/src/main/res/values/public.xml +1 -0
- package/android/src/main/res/values/styles.xml +9 -6
- package/android/src/main/res/values-night/styles.xml +1 -1
- package/android/src/main/res/values-v23/styles.xml +6 -1
- package/android/src/main/res/values-v27/styles.xml +1 -1
- package/android/src/main/res/values-v29/styles.xml +1 -1
- package/android/src/main/res/values-v30/styles.xml +1 -1
- package/app.plugin.js +2 -2
- package/dist/commonjs/addon/index.js +43 -38
- package/dist/commonjs/addon/index.js.map +1 -1
- package/dist/commonjs/expo.js +283 -0
- package/dist/commonjs/expo.js.map +1 -0
- package/dist/commonjs/generate.js +165 -323
- package/dist/commonjs/generate.js.map +1 -1
- package/dist/commonjs/index.js +3 -3
- package/dist/commonjs/index.js.map +1 -1
- package/dist/module/addon/index.js +43 -38
- package/dist/module/addon/index.js.map +1 -1
- package/dist/module/expo.js +273 -0
- package/dist/module/expo.js.map +1 -0
- package/dist/module/generate.js +162 -317
- package/dist/module/generate.js.map +1 -1
- package/dist/module/index.js +2 -2
- package/dist/module/index.js.map +1 -1
- package/dist/typescript/addon/index.d.ts.map +1 -1
- package/dist/typescript/expo.d.ts +11 -0
- package/dist/typescript/expo.d.ts.map +1 -0
- package/dist/typescript/generate.d.ts +27 -21
- package/dist/typescript/generate.d.ts.map +1 -1
- package/dist/typescript/index.d.ts +22 -4
- package/dist/typescript/index.d.ts.map +1 -1
- package/ios/RNBootSplash.mm +33 -37
- package/package.json +8 -8
- package/src/expo.ts +368 -0
- package/src/generate.ts +235 -403
- package/src/index.ts +32 -10
package/src/expo.ts
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import * as Expo from "@expo/config-plugins";
|
|
2
|
+
import { assignColorValue } from "@expo/config-plugins/build/android/Colors";
|
|
3
|
+
import { addImports } from "@expo/config-plugins/build/android/codeMod";
|
|
4
|
+
import { mergeContents } from "@expo/config-plugins/build/utils/generateCode";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { dedent } from "ts-dedent";
|
|
7
|
+
import { Manifest } from ".";
|
|
8
|
+
import { cleanIOSAssets, getExpoConfig, hfs } from "./generate";
|
|
9
|
+
|
|
10
|
+
type ExpoPlugin = Expo.ConfigPlugin<{
|
|
11
|
+
assetsDir?: string;
|
|
12
|
+
android?: {
|
|
13
|
+
parentTheme?: "TransparentStatus" | "EdgeToEdge";
|
|
14
|
+
darkContentBarsStyle?: boolean;
|
|
15
|
+
};
|
|
16
|
+
}>;
|
|
17
|
+
|
|
18
|
+
const withExpoVersionCheck =
|
|
19
|
+
(platform: "android" | "ios"): ExpoPlugin =>
|
|
20
|
+
(config) =>
|
|
21
|
+
Expo.withDangerousMod(config, [
|
|
22
|
+
platform,
|
|
23
|
+
(config) => {
|
|
24
|
+
getExpoConfig(config.modRequest.projectRoot); // will exit process if expo < 51.0.20
|
|
25
|
+
return config;
|
|
26
|
+
},
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
const withAndroidAssets: ExpoPlugin = (config, props) =>
|
|
30
|
+
Expo.withDangerousMod(config, [
|
|
31
|
+
"android",
|
|
32
|
+
(config) => {
|
|
33
|
+
const { assetsDir = "assets/bootsplash" } = props;
|
|
34
|
+
const { projectRoot, platformProjectRoot } = config.modRequest;
|
|
35
|
+
|
|
36
|
+
const srcDir = path.resolve(projectRoot, assetsDir, "android");
|
|
37
|
+
|
|
38
|
+
const destDir = path.resolve(
|
|
39
|
+
platformProjectRoot,
|
|
40
|
+
"app",
|
|
41
|
+
"src",
|
|
42
|
+
"main",
|
|
43
|
+
"res",
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
for (const drawableDir of hfs.readDir(srcDir)) {
|
|
47
|
+
const srcDrawableDir = path.join(srcDir, drawableDir);
|
|
48
|
+
const destDrawableDir = path.join(destDir, drawableDir);
|
|
49
|
+
|
|
50
|
+
hfs.ensureDir(destDrawableDir);
|
|
51
|
+
|
|
52
|
+
for (const file of hfs.readDir(srcDrawableDir)) {
|
|
53
|
+
hfs.copy(
|
|
54
|
+
path.join(srcDrawableDir, file),
|
|
55
|
+
path.join(destDrawableDir, file),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return config;
|
|
61
|
+
},
|
|
62
|
+
]);
|
|
63
|
+
|
|
64
|
+
const withAndroidManifest: ExpoPlugin = (config) =>
|
|
65
|
+
Expo.withAndroidManifest(config, (config) => {
|
|
66
|
+
config.modResults.manifest.application?.forEach((application) => {
|
|
67
|
+
if (application.$["android:name"] === ".MainApplication") {
|
|
68
|
+
const { activity } = application;
|
|
69
|
+
|
|
70
|
+
activity?.forEach((activity) => {
|
|
71
|
+
if (activity.$["android:name"] === ".MainActivity") {
|
|
72
|
+
activity.$["android:theme"] = "@style/BootTheme";
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return config;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const withMainActivity: ExpoPlugin = (config) =>
|
|
82
|
+
Expo.withMainActivity(config, (config) => {
|
|
83
|
+
const { modResults } = config;
|
|
84
|
+
const { language } = modResults;
|
|
85
|
+
|
|
86
|
+
const withImports = addImports(
|
|
87
|
+
modResults.contents.replace(
|
|
88
|
+
/(\/\/ )?setTheme\(R\.style\.AppTheme\)/,
|
|
89
|
+
"// setTheme(R.style.AppTheme)",
|
|
90
|
+
),
|
|
91
|
+
["android.os.Bundle", "com.zoontek.rnbootsplash.RNBootSplash"],
|
|
92
|
+
language === "java",
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
// indented with 4 spaces
|
|
96
|
+
const withInit = mergeContents({
|
|
97
|
+
src: withImports,
|
|
98
|
+
comment: " //",
|
|
99
|
+
tag: "bootsplash-init",
|
|
100
|
+
offset: 0,
|
|
101
|
+
anchor: /super\.onCreate\(null\)/,
|
|
102
|
+
newSrc:
|
|
103
|
+
" RNBootSplash.init(this, R.style.BootTheme)" +
|
|
104
|
+
(language === "java" ? ";" : ""),
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
...config,
|
|
109
|
+
modResults: {
|
|
110
|
+
...modResults,
|
|
111
|
+
contents: withInit.contents,
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const withAndroidStyles: ExpoPlugin = (config, props) =>
|
|
117
|
+
Expo.withAndroidStyles(config, async (config) => {
|
|
118
|
+
const { assetsDir = "assets/bootsplash", android = {} } = props;
|
|
119
|
+
const { parentTheme, darkContentBarsStyle } = android;
|
|
120
|
+
|
|
121
|
+
const { modRequest, modResults } = config;
|
|
122
|
+
const { resources } = modResults;
|
|
123
|
+
const { style = [] } = resources;
|
|
124
|
+
|
|
125
|
+
const manifest = (await hfs.json(
|
|
126
|
+
path.resolve(modRequest.projectRoot, assetsDir, "manifest.json"),
|
|
127
|
+
)) as Manifest;
|
|
128
|
+
|
|
129
|
+
const item = [
|
|
130
|
+
{
|
|
131
|
+
$: { name: "postBootSplashTheme" },
|
|
132
|
+
_: "@style/AppTheme",
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
$: { name: "bootSplashBackground" },
|
|
136
|
+
_: "@color/bootsplash_background",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
$: { name: "bootSplashLogo" },
|
|
140
|
+
_: "@drawable/bootsplash_logo",
|
|
141
|
+
},
|
|
142
|
+
];
|
|
143
|
+
|
|
144
|
+
if (manifest.brand != null) {
|
|
145
|
+
item.push({
|
|
146
|
+
$: { name: "bootSplashBrand" },
|
|
147
|
+
_: "@drawable/bootsplash_brand",
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
if (darkContentBarsStyle != null) {
|
|
151
|
+
item.push({
|
|
152
|
+
$: { name: "darkContentBarsStyle" },
|
|
153
|
+
_: String(darkContentBarsStyle),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const withBootTheme = [
|
|
158
|
+
...style.filter(({ $ }) => $.name !== "BootTheme"),
|
|
159
|
+
{
|
|
160
|
+
$: {
|
|
161
|
+
name: "BootTheme",
|
|
162
|
+
parent:
|
|
163
|
+
parentTheme === "TransparentStatus"
|
|
164
|
+
? "Theme.BootSplash.TransparentStatus"
|
|
165
|
+
: parentTheme === "EdgeToEdge"
|
|
166
|
+
? "Theme.BootSplash.EdgeToEdge"
|
|
167
|
+
: "Theme.BootSplash",
|
|
168
|
+
},
|
|
169
|
+
item,
|
|
170
|
+
},
|
|
171
|
+
];
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
...config,
|
|
175
|
+
modResults: {
|
|
176
|
+
...modResults,
|
|
177
|
+
resources: {
|
|
178
|
+
...resources,
|
|
179
|
+
style: withBootTheme,
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const withAndroidColors: ExpoPlugin = (config, props) =>
|
|
186
|
+
Expo.withAndroidColors(config, async (config) => {
|
|
187
|
+
const { assetsDir = "assets/bootsplash" } = props;
|
|
188
|
+
const { projectRoot } = config.modRequest;
|
|
189
|
+
|
|
190
|
+
const manifest = (await hfs.json(
|
|
191
|
+
path.resolve(projectRoot, assetsDir, "manifest.json"),
|
|
192
|
+
)) as Manifest;
|
|
193
|
+
|
|
194
|
+
config.modResults = assignColorValue(config.modResults, {
|
|
195
|
+
name: "bootsplash_background",
|
|
196
|
+
value: manifest.background,
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
return config;
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const withAndroidColorsNight: ExpoPlugin = (config, props) =>
|
|
203
|
+
Expo.withAndroidColorsNight(config, async (config) => {
|
|
204
|
+
const { assetsDir = "assets/bootsplash" } = props;
|
|
205
|
+
const { projectRoot } = config.modRequest;
|
|
206
|
+
|
|
207
|
+
const manifest = (await hfs.json(
|
|
208
|
+
path.resolve(projectRoot, assetsDir, "manifest.json"),
|
|
209
|
+
)) as Manifest;
|
|
210
|
+
|
|
211
|
+
if (manifest.darkBackground != null) {
|
|
212
|
+
config.modResults = assignColorValue(config.modResults, {
|
|
213
|
+
name: "bootsplash_background",
|
|
214
|
+
value: manifest.darkBackground,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return config;
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const withIOSAssets: ExpoPlugin = (config, props) =>
|
|
222
|
+
Expo.withDangerousMod(config, [
|
|
223
|
+
"ios",
|
|
224
|
+
(config) => {
|
|
225
|
+
const { assetsDir = "assets/bootsplash" } = props;
|
|
226
|
+
|
|
227
|
+
const {
|
|
228
|
+
projectRoot,
|
|
229
|
+
platformProjectRoot,
|
|
230
|
+
projectName = "",
|
|
231
|
+
} = config.modRequest;
|
|
232
|
+
|
|
233
|
+
const srcDir = path.resolve(projectRoot, assetsDir, "ios");
|
|
234
|
+
const destDir = path.resolve(platformProjectRoot, projectName);
|
|
235
|
+
|
|
236
|
+
cleanIOSAssets(destDir);
|
|
237
|
+
|
|
238
|
+
hfs.copy(
|
|
239
|
+
path.join(srcDir, "BootSplash.storyboard"),
|
|
240
|
+
path.join(destDir, "BootSplash.storyboard"),
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
for (const xcassetsDir of ["Colors.xcassets", "Images.xcassets"]) {
|
|
244
|
+
const srcXcassetsDir = path.join(srcDir, xcassetsDir);
|
|
245
|
+
const destXcassetsDir = path.join(destDir, xcassetsDir);
|
|
246
|
+
|
|
247
|
+
hfs.ensureDir(destXcassetsDir);
|
|
248
|
+
|
|
249
|
+
for (const file of hfs.readDir(srcXcassetsDir)) {
|
|
250
|
+
hfs.copy(
|
|
251
|
+
path.join(srcXcassetsDir, file),
|
|
252
|
+
path.join(destXcassetsDir, file),
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return config;
|
|
258
|
+
},
|
|
259
|
+
]);
|
|
260
|
+
|
|
261
|
+
const withAppDelegate: ExpoPlugin = (config) =>
|
|
262
|
+
Expo.withAppDelegate(config, (config) => {
|
|
263
|
+
const { modResults } = config;
|
|
264
|
+
const { language } = modResults;
|
|
265
|
+
|
|
266
|
+
if (language !== "objc" && language !== "objcpp") {
|
|
267
|
+
throw new Error(
|
|
268
|
+
`Cannot modify the project AppDelegate as it's not in a supported language: ${language}`,
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const withHeader = mergeContents({
|
|
273
|
+
src: modResults.contents,
|
|
274
|
+
comment: "//",
|
|
275
|
+
tag: "bootsplash-header",
|
|
276
|
+
offset: 1,
|
|
277
|
+
anchor: /#import "AppDelegate\.h"/,
|
|
278
|
+
newSrc: '#import "RNBootSplash.h"',
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
const withRootView = mergeContents({
|
|
282
|
+
src: withHeader.contents,
|
|
283
|
+
comment: "//",
|
|
284
|
+
tag: "bootsplash-init",
|
|
285
|
+
offset: 0,
|
|
286
|
+
anchor: /@end/,
|
|
287
|
+
newSrc: dedent`
|
|
288
|
+
- (void)customizeRootView:(RCTRootView *)rootView {
|
|
289
|
+
[RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView];
|
|
290
|
+
}
|
|
291
|
+
`,
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
return {
|
|
295
|
+
...config,
|
|
296
|
+
modResults: {
|
|
297
|
+
...modResults,
|
|
298
|
+
contents: withRootView.contents,
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
const withInfoPlist: ExpoPlugin = (config) =>
|
|
304
|
+
Expo.withInfoPlist(config, (config) => {
|
|
305
|
+
config.modResults["UILaunchStoryboardName"] = "BootSplash";
|
|
306
|
+
return config;
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
const withXcodeProject: ExpoPlugin = (config) =>
|
|
310
|
+
Expo.withXcodeProject(config, (config) => {
|
|
311
|
+
const { projectName = "" } = config.modRequest;
|
|
312
|
+
|
|
313
|
+
Expo.IOSConfig.XcodeUtils.addResourceFileToGroup({
|
|
314
|
+
filepath: path.join(projectName, "BootSplash.storyboard"),
|
|
315
|
+
groupName: projectName,
|
|
316
|
+
project: config.modResults,
|
|
317
|
+
isBuildFile: true,
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
Expo.IOSConfig.XcodeUtils.addResourceFileToGroup({
|
|
321
|
+
filepath: path.join(projectName, "Colors.xcassets"),
|
|
322
|
+
groupName: projectName,
|
|
323
|
+
project: config.modResults,
|
|
324
|
+
isBuildFile: true,
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
return config;
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
const withoutExpoSplashScreen: ExpoPlugin = Expo.createRunOncePlugin(
|
|
331
|
+
(config) => config,
|
|
332
|
+
"expo-splash-screen",
|
|
333
|
+
"skip",
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
export const withBootSplash: ExpoPlugin = (config, props = {}) => {
|
|
337
|
+
const plugins: ExpoPlugin[] = [];
|
|
338
|
+
const { platforms = [] } = config;
|
|
339
|
+
|
|
340
|
+
plugins.push(withoutExpoSplashScreen);
|
|
341
|
+
|
|
342
|
+
if (platforms.includes("android")) {
|
|
343
|
+
plugins.push(
|
|
344
|
+
withExpoVersionCheck("android"),
|
|
345
|
+
withAndroidAssets,
|
|
346
|
+
withAndroidManifest,
|
|
347
|
+
withMainActivity,
|
|
348
|
+
withAndroidStyles,
|
|
349
|
+
withAndroidColors,
|
|
350
|
+
withAndroidColorsNight,
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (platforms.includes("ios")) {
|
|
355
|
+
plugins.push(
|
|
356
|
+
withExpoVersionCheck("ios"),
|
|
357
|
+
withIOSAssets,
|
|
358
|
+
withAppDelegate,
|
|
359
|
+
withInfoPlist,
|
|
360
|
+
withXcodeProject,
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return Expo.withPlugins(
|
|
365
|
+
config,
|
|
366
|
+
plugins.map((plugin) => [plugin, props]),
|
|
367
|
+
);
|
|
368
|
+
};
|