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