expo-splash-screen2 1.0.0 → 1.2.0
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 +34 -825
- package/README.zh.md +38 -825
- package/expo-splash-web/build-splash-web.js +483 -277
- package/ios/SplashScreen2ViewController.swift +77 -10
- package/package.json +3 -2
- package/plugin/build/index.js +132 -118
- package/plugin/build/templates/android.js +9 -7
- package/scripts/postinstall.js +97 -6
- package/scripts/setup.js +100 -0
package/README.md
CHANGED
|
@@ -1,52 +1,37 @@
|
|
|
1
1
|
# expo-splash-screen2
|
|
2
2
|
|
|
3
|
-
`expo-splash-screen2` allows you to customize your app's splash screen with multiple display modes including WebView HTML,
|
|
3
|
+
`expo-splash-screen2` allows you to customize your app's splash screen with multiple display modes including WebView HTML, .9 image, background+WebView blend mode, and icon+background color mode. It supports dark mode and provides a seamless transition experience.
|
|
4
4
|
|
|
5
|
-
>
|
|
5
|
+
> **English** | [中文文档](./README.zh.md)
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- [🚀 Features](#-features)
|
|
9
|
-
- [📚 API](#-api)
|
|
10
|
-
- [🗒 Examples](#-examples)
|
|
11
|
-
- [💻 Installation](#-installation)
|
|
12
|
-
- [Installation in managed Expo projects](#-installation-in-managed-expo-projects)
|
|
13
|
-
- [Installation in bare React Native projects](#-installation-in-bare-react-native-projects)
|
|
14
|
-
- [⚙️ Configuration](#️-configuration)
|
|
15
|
-
- [WebView Mode](#webview-mode)
|
|
16
|
-
- [ResponsiveImage Mode](#responsiveimage-mode)
|
|
17
|
-
- [Normal Mode](#normal-mode)
|
|
18
|
-
- [Dark Mode Support](#dark-mode-support)
|
|
19
|
-
- [📱 Platform-Specific Details](#-platform-specific-details)
|
|
20
|
-
- [iOS Configuration](#-ios-configuration)
|
|
21
|
-
- [Android Configuration](#-android-configuration)
|
|
22
|
-
- [👏 Contributing](#-contributing)
|
|
23
|
-
- [❓ Known Issues](#-known-issues)
|
|
24
|
-
- [📄 License](#-license)
|
|
25
|
-
- [🏅 Hall of Fame](#-hall-of-fame)
|
|
7
|
+
### Key features
|
|
26
8
|
|
|
27
|
-
|
|
9
|
+
- 🎨 **Multiple Display Modes**: WebView HTML, .9 image, background+WebView blend mode, and icon+background color mode
|
|
10
|
+
- 🚀 **Custom Complex Splash**: Use WebView or Blend mode to create complex splash screens (privacy dialogs, animations, etc.)
|
|
11
|
+
- 📦 **Ready-to-Use Templates**: Complete WebView HTML template files with dev and build support
|
|
12
|
+
- 🎯 **Easy Integration**: Simple configuration with automatic native code generation
|
|
28
13
|
|
|
29
|
-
|
|
14
|
+
### Installation
|
|
30
15
|
|
|
31
|
-
|
|
16
|
+
#### Quick Start
|
|
17
|
+
|
|
18
|
+
1. **Install the package:**
|
|
32
19
|
|
|
33
20
|
```bash
|
|
34
21
|
# Remove expo-splash-screen if installed (they are mutually exclusive)
|
|
35
22
|
npm uninstall expo-splash-screen
|
|
36
23
|
|
|
37
24
|
# Install expo-splash-screen2
|
|
25
|
+
yarn add expo-splash-screen2
|
|
26
|
+
# or
|
|
38
27
|
npm install expo-splash-screen2
|
|
39
28
|
# or
|
|
40
29
|
pnpm add expo-splash-screen2
|
|
41
|
-
# or
|
|
42
|
-
yarn add expo-splash-screen2
|
|
43
30
|
```
|
|
44
31
|
|
|
45
|
-
> **Note**: If
|
|
46
|
-
|
|
47
|
-
### Step 2: Configure app.json
|
|
32
|
+
> **Note**: If using `pnpm` and you see a warning about ignored build scripts, run `pnpm approve-builds`.
|
|
48
33
|
|
|
49
|
-
|
|
34
|
+
2. **Configure `app.json`:**
|
|
50
35
|
|
|
51
36
|
```json
|
|
52
37
|
{
|
|
@@ -64,831 +49,55 @@ Add the plugin to your `app.json` or `app.config.js` with WebView mode:
|
|
|
64
49
|
}
|
|
65
50
|
```
|
|
66
51
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
After installation, run prebuild to apply native modifications:
|
|
52
|
+
3. **Run prebuild:**
|
|
70
53
|
|
|
71
54
|
```bash
|
|
72
55
|
npx expo prebuild
|
|
73
56
|
```
|
|
74
57
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
In your main component (e.g., `App.tsx`), prevent the splash screen from auto-hiding and control when to hide it:
|
|
78
|
-
|
|
79
|
-
```tsx
|
|
80
|
-
import React, { useEffect, useState } from 'react';
|
|
81
|
-
import { View, Text } from 'react-native';
|
|
82
|
-
import * as SplashScreen from 'expo-splash-screen2';
|
|
83
|
-
|
|
84
|
-
// Prevent native splash screen from autohiding before App component declaration
|
|
85
|
-
SplashScreen.preventAutoHideAsync();
|
|
86
|
-
|
|
87
|
-
export default function App() {
|
|
88
|
-
const [appIsReady, setAppIsReady] = useState(false);
|
|
89
|
-
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
async function prepare() {
|
|
92
|
-
try {
|
|
93
|
-
// Pre-load fonts, make API calls, etc.
|
|
94
|
-
await loadFonts();
|
|
95
|
-
await loadInitialData();
|
|
96
|
-
} catch (e) {
|
|
97
|
-
console.warn(e);
|
|
98
|
-
} finally {
|
|
99
|
-
setAppIsReady(true);
|
|
100
|
-
await SplashScreen.hideAsync();
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
prepare();
|
|
105
|
-
}, []);
|
|
106
|
-
|
|
107
|
-
if (!appIsReady) {
|
|
108
|
-
return null;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return (
|
|
112
|
-
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
|
|
113
|
-
<Text>Your App Content</Text>
|
|
114
|
-
</View>
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### Step 5: Customize Your Splash Screen HTML
|
|
120
|
-
|
|
121
|
-
The plugin automatically copies the `expo-splash-web` folder to your project root. You can customize the HTML splash screen by editing files in `expo-splash-web/src/`:
|
|
122
|
-
|
|
123
|
-
```bash
|
|
124
|
-
# Build the splash web assets
|
|
125
|
-
npm run build:expo-splash-web
|
|
126
|
-
|
|
127
|
-
# Or run in development mode with hot reload
|
|
128
|
-
npm run dev:expo-splash-web
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
After making changes, rebuild and run prebuild again:
|
|
132
|
-
|
|
133
|
-
```bash
|
|
134
|
-
npm run build:expo-splash-web
|
|
135
|
-
npx expo prebuild
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
### That's It! 🎉
|
|
139
|
-
|
|
140
|
-
Your app now has a custom WebView-based splash screen. For more advanced configurations and other display modes, see the [Configuration](#️-configuration) section below.
|
|
141
|
-
|
|
142
|
-
## 🚀 Features
|
|
143
|
-
|
|
144
|
-
### Display Modes
|
|
145
|
-
|
|
146
|
-
`expo-splash-screen2` provides three splash screen modes to fit different use cases:
|
|
147
|
-
|
|
148
|
-
#### `webview` Mode
|
|
149
|
-
|
|
150
|
-
Display HTML content in a WebView, allowing for complex animations and interactive splash screens.
|
|
151
|
-
|
|
152
|
-
- Full JavaScript/CSS support
|
|
153
|
-
- React component support (with esbuild bundler)
|
|
154
|
-
- Perfect for animated splash screens
|
|
155
|
-
- JavaScript bridge for native communication
|
|
156
|
-
|
|
157
|
-
#### `responsiveImage` Mode
|
|
158
|
-
|
|
159
|
-
Display a full-screen background image that scales to cover the entire screen.
|
|
160
|
-
|
|
161
|
-
- Supports `.9.png` (Nine-patch) format on Android
|
|
162
|
-
- `scaleAspectFill` content mode
|
|
163
|
-
- Best for photographic or detailed backgrounds
|
|
164
|
-
|
|
165
|
-
#### `normal` Mode
|
|
166
|
-
|
|
167
|
-
Display a centered image with fixed width (default 100px), maintaining aspect ratio.
|
|
168
|
-
|
|
169
|
-
- Fixed width, auto height
|
|
170
|
-
- Centered on screen with background color
|
|
171
|
-
- **Supports dark mode** with separate image and background color
|
|
172
|
-
- Best for logo-centric splash screens
|
|
173
|
-
|
|
174
|
-
### Dark Mode Support (Normal Mode)
|
|
175
|
-
|
|
176
|
-
`expo-splash-screen2` supports per-appearance splash screens that respond to system appearance changes on iOS 13+ and Android 10+.
|
|
177
|
-
|
|
178
|
-
<table>
|
|
179
|
-
<thead><tr><td>Light Mode</td><td>Dark Mode</td></tr></thead>
|
|
180
|
-
<tbody><tr>
|
|
181
|
-
<td>Background: Custom color<br>Image: Light mode image</td>
|
|
182
|
-
<td>Background: Custom dark color<br>Image: Dark mode image</td>
|
|
183
|
-
</tr></tbody>
|
|
184
|
-
</table>
|
|
185
|
-
|
|
186
|
-
### Cross-Platform Support
|
|
187
|
-
|
|
188
|
-
- **Android**: Full support for Android 12+ system splash screen, custom activities, and seamless transitions
|
|
189
|
-
- **iOS**: Native UIView integration, storyboard support, and smooth animations
|
|
190
|
-
|
|
191
|
-
### StatusBar Customization
|
|
192
|
-
|
|
193
|
-
`expo-splash-screen2` allows customization of the StatusBar according to the [React Native StatusBar API](https://reactnative.dev/docs/statusbar). You can control StatusBar visibility, style, and background color during the splash screen display.
|
|
194
|
-
|
|
195
|
-
## 📚 API
|
|
196
|
-
|
|
197
|
-
```tsx
|
|
198
|
-
import * as SplashScreen from 'expo-splash-screen2';
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
The native splash screen that is controlled via this module autohides once the React Native-controlled view hierarchy is mounted. This means that when your app first `render`s view component, the native splash screen will hide. This default behavior can be prevented by calling [`SplashScreen.preventAutoHideAsync()`](#splashscreenpreventautohideasync) and later on [`SplashScreen.hideAsync()`](#splashscreenhideasync).
|
|
202
|
-
|
|
203
|
-
### `SplashScreen.preventAutoHideAsync()`
|
|
204
|
-
|
|
205
|
-
This method makes the native splash screen stay visible until [`SplashScreen.hideAsync()`](#splashscreenhideasync) is called. This must be called before any React Native-controlled view hierarchy is rendered (either in the global scope of your main component, or when the component renders `null` at the beginning - see [Examples section](#-examples)).
|
|
206
|
-
|
|
207
|
-
Preventing default autohiding might come in handy if your application needs to prepare/download some resources and/or make some API calls before first rendering some actual view hierarchy.
|
|
208
|
-
|
|
209
|
-
> **Important**: It is recommended to call this in global scope without awaiting, rather than inside React components or hooks.
|
|
210
|
-
|
|
211
|
-
#### Returns
|
|
212
|
-
|
|
213
|
-
A `Promise` that resolves to `true` when preventing autohiding succeeded and to `false` if the native splash screen is already prevented from autohiding (for instance, if you've already called this method). `Promise` rejection most likely means that native splash screen cannot be prevented from autohiding (it's already hidden when this method was executed).
|
|
214
|
-
|
|
215
|
-
### `SplashScreen.hideAsync()`
|
|
216
|
-
|
|
217
|
-
Hides the native splash screen. Only works if the native splash screen has been previously prevented from autohiding by calling [`SplashScreen.preventAutoHideAsync()`](#splashscreenpreventautohideasync) method.
|
|
218
|
-
|
|
219
|
-
#### Returns
|
|
220
|
-
|
|
221
|
-
A `Promise` that resolves to `true` once the splash screen becomes hidden and to `false` if the splash screen is already hidden.
|
|
222
|
-
|
|
223
|
-
## 🗒 Examples
|
|
224
|
-
|
|
225
|
-
### `SplashScreen.preventAutoHideAsync()` in global scope
|
|
226
|
-
|
|
227
|
-
`App.tsx`
|
|
228
|
-
|
|
229
|
-
```tsx
|
|
230
|
-
import React from 'react';
|
|
231
|
-
import { StyleSheet, Text, View } from 'react-native';
|
|
232
|
-
import * as SplashScreen from 'expo-splash-screen2';
|
|
233
|
-
|
|
234
|
-
// Prevent native splash screen from autohiding before App component declaration
|
|
235
|
-
SplashScreen.preventAutoHideAsync()
|
|
236
|
-
.then((result) => console.log(`SplashScreen.preventAutoHideAsync() succeeded: ${result}`))
|
|
237
|
-
.catch(console.warn); // it's good to explicitly catch and inspect any error
|
|
238
|
-
|
|
239
|
-
export default class App extends React.Component {
|
|
240
|
-
componentDidMount() {
|
|
241
|
-
// Hides native splash screen after 2s
|
|
242
|
-
setTimeout(async () => {
|
|
243
|
-
await SplashScreen.hideAsync();
|
|
244
|
-
}, 2000);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
render() {
|
|
248
|
-
return (
|
|
249
|
-
<View style={styles.container}>
|
|
250
|
-
<Text style={styles.text}>SplashScreen Demo! 👋</Text>
|
|
251
|
-
</View>
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
const styles = StyleSheet.create({
|
|
257
|
-
container: {
|
|
258
|
-
flex: 1,
|
|
259
|
-
alignItems: 'center',
|
|
260
|
-
justifyContent: 'center',
|
|
261
|
-
backgroundColor: '#aabbcc',
|
|
262
|
-
},
|
|
263
|
-
text: {
|
|
264
|
-
color: 'white',
|
|
265
|
-
fontWeight: 'bold',
|
|
266
|
-
},
|
|
267
|
-
});
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
### Basic Usage
|
|
58
|
+
4. **Use in your app:**
|
|
271
59
|
|
|
272
60
|
```tsx
|
|
273
61
|
import * as SplashScreen from 'expo-splash-screen2';
|
|
274
62
|
|
|
275
|
-
// Prevent native splash screen from autohiding
|
|
63
|
+
// Prevent native splash screen from autohiding
|
|
276
64
|
SplashScreen.preventAutoHideAsync();
|
|
277
65
|
|
|
278
66
|
export default function App() {
|
|
279
|
-
const [appIsReady, setAppIsReady] = useState(false);
|
|
280
|
-
|
|
281
|
-
useEffect(() => {
|
|
282
|
-
async function prepare() {
|
|
283
|
-
try {
|
|
284
|
-
// Pre-load fonts, make API calls, etc.
|
|
285
|
-
await loadFonts();
|
|
286
|
-
await loadInitialData();
|
|
287
|
-
} catch (e) {
|
|
288
|
-
console.warn(e);
|
|
289
|
-
} finally {
|
|
290
|
-
setAppIsReady(true);
|
|
291
|
-
await SplashScreen.hideAsync();
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
prepare();
|
|
296
|
-
}, []);
|
|
297
|
-
|
|
298
|
-
if (!appIsReady) {
|
|
299
|
-
return null;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
return (
|
|
303
|
-
<View style={styles.container}>
|
|
304
|
-
<Text>Your App Content</Text>
|
|
305
|
-
</View>
|
|
306
|
-
);
|
|
307
|
-
}
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
### With Expo Router
|
|
311
|
-
|
|
312
|
-
```tsx
|
|
313
|
-
// app/_layout.tsx
|
|
314
|
-
import * as SplashScreen from 'expo-splash-screen2';
|
|
315
|
-
import { useEffect } from 'react';
|
|
316
|
-
|
|
317
|
-
SplashScreen.preventAutoHideAsync();
|
|
318
|
-
|
|
319
|
-
export default function RootLayout() {
|
|
320
67
|
useEffect(() => {
|
|
321
|
-
// Hide splash screen
|
|
68
|
+
// Hide splash screen when ready
|
|
322
69
|
SplashScreen.hideAsync();
|
|
323
70
|
}, []);
|
|
324
71
|
|
|
325
|
-
return
|
|
326
|
-
<Stack>
|
|
327
|
-
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
|
|
328
|
-
</Stack>
|
|
329
|
-
);
|
|
72
|
+
return <YourAppContent />;
|
|
330
73
|
}
|
|
331
74
|
```
|
|
332
75
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
See the splash screen modes in action:
|
|
336
|
-
|
|
337
|
-
#### `webview` Mode
|
|
338
|
-
|
|
339
|
-
Display HTML content in a WebView with full JavaScript/CSS support.
|
|
340
|
-
|
|
341
|
-
<table>
|
|
342
|
-
<thead><tr><td>Android</td><td>iOS</td></tr></thead>
|
|
343
|
-
<tbody><tr>
|
|
344
|
-
<td>
|
|
345
|
-
|
|
346
|
-

|
|
347
|
-
|
|
348
|
-
</td>
|
|
349
|
-
<td>
|
|
350
|
-
|
|
351
|
-

|
|
352
|
-
|
|
353
|
-
</td>
|
|
354
|
-
</tr>
|
|
355
|
-
</tbody>
|
|
356
|
-
</table>
|
|
357
|
-
|
|
358
|
-
#### `responsiveImage` Mode
|
|
359
|
-
|
|
360
|
-
Display a full-screen background image that scales to cover the entire screen.
|
|
361
|
-
|
|
362
|
-
<table>
|
|
363
|
-
<thead><tr><td>Android</td><td>iOS</td></tr></thead>
|
|
364
|
-
<tbody><tr>
|
|
365
|
-
<td>
|
|
366
|
-
|
|
367
|
-

|
|
368
|
-
|
|
369
|
-
</td>
|
|
370
|
-
<td>
|
|
371
|
-
|
|
372
|
-

|
|
373
|
-
|
|
374
|
-
</td>
|
|
375
|
-
</tr>
|
|
376
|
-
</tbody>
|
|
377
|
-
</table>
|
|
378
|
-
|
|
379
|
-
#### `normal` Mode
|
|
380
|
-
|
|
381
|
-
Display a centered image with fixed width, maintaining aspect ratio. Supports dark mode.
|
|
382
|
-
|
|
383
|
-
<table>
|
|
384
|
-
<thead><tr><td>Android</td><td>iOS</td></tr></thead>
|
|
385
|
-
<tbody><tr>
|
|
386
|
-
<td>
|
|
387
|
-
|
|
388
|
-

|
|
389
|
-
|
|
390
|
-
</td>
|
|
391
|
-
<td>
|
|
392
|
-
|
|
393
|
-

|
|
394
|
-
|
|
395
|
-
</td>
|
|
396
|
-
</tr>
|
|
397
|
-
</tbody>
|
|
398
|
-
</table>
|
|
399
|
-
|
|
400
|
-
## 💻 Installation
|
|
401
|
-
|
|
402
|
-
### Installation in managed Expo projects
|
|
403
|
-
|
|
404
|
-
For managed Expo projects, follow the standard installation process:
|
|
405
|
-
|
|
406
|
-
```bash
|
|
407
|
-
# Remove expo-splash-screen if installed (they are mutually exclusive)
|
|
408
|
-
npm uninstall expo-splash-screen
|
|
409
|
-
|
|
410
|
-
# Install expo-splash-screen2
|
|
411
|
-
npm install expo-splash-screen2
|
|
412
|
-
# or
|
|
413
|
-
pnpm add expo-splash-screen2
|
|
414
|
-
# or
|
|
415
|
-
yarn add expo-splash-screen2
|
|
416
|
-
```
|
|
417
|
-
|
|
418
|
-
> **Note**: `expo-splash-screen` and `expo-splash-screen2` are mutually exclusive. You can only use one of them in your project.
|
|
76
|
+
For detailed setup instructions and other modes, check out the [installation guide](./docs/installation.md).
|
|
419
77
|
|
|
420
|
-
###
|
|
78
|
+
### Documentation
|
|
421
79
|
|
|
422
|
-
|
|
80
|
+
Full API reference and guides available at:
|
|
423
81
|
|
|
424
|
-
|
|
82
|
+
- [Installation Guide](./docs/installation.md)
|
|
83
|
+
- [Configuration](./docs/configuration.md)
|
|
84
|
+
- [API Reference](./docs/api.md)
|
|
85
|
+
- [Examples](./docs/examples.md)
|
|
86
|
+
- [Platform-Specific Details](./docs/platform-specific.md)
|
|
87
|
+
- [Known Issues](./docs/known-issues.md)
|
|
425
88
|
|
|
426
|
-
|
|
427
|
-
npm install expo-splash-screen2
|
|
428
|
-
# or
|
|
429
|
-
pnpm add expo-splash-screen2
|
|
430
|
-
# or
|
|
431
|
-
yarn add expo-splash-screen2
|
|
432
|
-
```
|
|
433
|
-
|
|
434
|
-
#### iOS Setup
|
|
435
|
-
|
|
436
|
-
Run `npx pod-install` after installing the package:
|
|
437
|
-
|
|
438
|
-
```bash
|
|
439
|
-
npx pod-install
|
|
440
|
-
```
|
|
441
|
-
|
|
442
|
-
#### Android Setup
|
|
443
|
-
|
|
444
|
-
No additional setup required. The plugin will automatically configure Android during prebuild.
|
|
445
|
-
|
|
446
|
-
### pnpm Build Script Approval
|
|
447
|
-
|
|
448
|
-
If you're using `pnpm` and encounter a warning about ignored build scripts:
|
|
449
|
-
|
|
450
|
-
```
|
|
451
|
-
╭ Warning ────────────────────────────────────────────────────────────────────────╮
|
|
452
|
-
│ │
|
|
453
|
-
│ Ignored build scripts: expo-splash-screen2, unrs-resolver. │
|
|
454
|
-
│ Run "pnpm approve-builds" to pick which dependencies should be allowed to │
|
|
455
|
-
│ run scripts. │
|
|
456
|
-
```
|
|
457
|
-
|
|
458
|
-
Follow the prompt and run `pnpm approve-builds` to allow `expo-splash-screen2` to execute its postinstall script:
|
|
459
|
-
|
|
460
|
-
```bash
|
|
461
|
-
pnpm approve-builds
|
|
462
|
-
```
|
|
89
|
+
### Contributing
|
|
463
90
|
|
|
464
|
-
|
|
91
|
+
See the [contributing guide](./CONTRIBUTING.md) to learn how to contribute to the repo and development workflow.
|
|
465
92
|
|
|
466
|
-
###
|
|
93
|
+
### License
|
|
467
94
|
|
|
468
|
-
|
|
469
|
-
1. Copy `expo-splash-web` folder to your project root
|
|
470
|
-
2. Add build commands to your `package.json`
|
|
471
|
-
3. Update your `app.json` with plugin configuration
|
|
472
|
-
4. Remove `expo-splash-screen` dependency from `package.json`
|
|
473
|
-
|
|
474
|
-
**If you're using pnpm and the postinstall script doesn't run automatically**, you can manually run the setup script:
|
|
475
|
-
|
|
476
|
-
```bash
|
|
477
|
-
# From your project root directory
|
|
478
|
-
node node_modules/expo-splash-screen2/scripts/setup.js
|
|
479
|
-
```
|
|
480
|
-
|
|
481
|
-
After installation (or manual setup), run prebuild to apply native modifications:
|
|
482
|
-
|
|
483
|
-
```bash
|
|
484
|
-
npx expo prebuild
|
|
485
|
-
```
|
|
486
|
-
|
|
487
|
-
## ⚙️ Configuration
|
|
488
|
-
|
|
489
|
-
Add the plugin to your `app.json` or `app.config.js`:
|
|
490
|
-
|
|
491
|
-
### WebView Mode
|
|
492
|
-
|
|
493
|
-
Display HTML content with full JavaScript/CSS support:
|
|
494
|
-
|
|
495
|
-
```json
|
|
496
|
-
{
|
|
497
|
-
"expo": {
|
|
498
|
-
"plugins": [
|
|
499
|
-
[
|
|
500
|
-
"expo-splash-screen2",
|
|
501
|
-
{
|
|
502
|
-
"mode": "webview",
|
|
503
|
-
"backgroundColor": "#FFFFFF"
|
|
504
|
-
}
|
|
505
|
-
]
|
|
506
|
-
]
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
```
|
|
510
|
-
|
|
511
|
-
#### WebView Mode Options
|
|
512
|
-
|
|
513
|
-
| Option | Type | Required | Description |
|
|
514
|
-
|--------|------|----------|-------------|
|
|
515
|
-
| `mode` | `"webview"` | Yes | Enable WebView HTML mode |
|
|
516
|
-
| `backgroundColor` | `string` | No | Background color (default: `#ffffff`) |
|
|
517
|
-
| `localHtmlPath` | `string` | No | Path to custom HTML file |
|
|
518
|
-
|
|
519
|
-
### ResponsiveImage Mode
|
|
520
|
-
|
|
521
|
-
Display a full-screen background image:
|
|
522
|
-
|
|
523
|
-
```json
|
|
524
|
-
{
|
|
525
|
-
"expo": {
|
|
526
|
-
"plugins": [
|
|
527
|
-
[
|
|
528
|
-
"expo-splash-screen2",
|
|
529
|
-
{
|
|
530
|
-
"mode": "responsiveImage",
|
|
531
|
-
"backgroundColor": "#FFFFFF",
|
|
532
|
-
"image": "./assets/splash-background.png"
|
|
533
|
-
}
|
|
534
|
-
]
|
|
535
|
-
]
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
```
|
|
539
|
-
|
|
540
|
-
#### ResponsiveImage Mode Options
|
|
541
|
-
|
|
542
|
-
| Option | Type | Required | Description |
|
|
543
|
-
|--------|------|----------|-------------|
|
|
544
|
-
| `mode` | `"responsiveImage"` | Yes | Enable responsive image mode |
|
|
545
|
-
| `backgroundColor` | `string` | No | Background color (default: `#ffffff`) |
|
|
546
|
-
| `image` | `string` | Yes | Path to background image (supports `.9.png`) |
|
|
547
|
-
|
|
548
|
-
### Normal Mode
|
|
549
|
-
|
|
550
|
-
Display a centered image with fixed width:
|
|
551
|
-
|
|
552
|
-
```json
|
|
553
|
-
{
|
|
554
|
-
"expo": {
|
|
555
|
-
"plugins": [
|
|
556
|
-
[
|
|
557
|
-
"expo-splash-screen2",
|
|
558
|
-
{
|
|
559
|
-
"mode": "normal",
|
|
560
|
-
"backgroundColor": "#10021F",
|
|
561
|
-
"image": "./assets/splash-icon.png",
|
|
562
|
-
"imageWidth": 100
|
|
563
|
-
}
|
|
564
|
-
]
|
|
565
|
-
]
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
```
|
|
569
|
-
|
|
570
|
-
#### Normal Mode Options
|
|
571
|
-
|
|
572
|
-
| Option | Type | Required | Description |
|
|
573
|
-
|--------|------|----------|-------------|
|
|
574
|
-
| `mode` | `"normal"` | Yes | Enable normal (centered image) mode |
|
|
575
|
-
| `backgroundColor` | `string` | No | Background color (default: `#ffffff`) |
|
|
576
|
-
| `image` | `string` | Yes | Path to splash icon image |
|
|
577
|
-
| `imageWidth` | `number` | No | Image width in dp/pt (default: `100`) |
|
|
578
|
-
| `dark` | `object` | No | Dark mode configuration |
|
|
579
|
-
|
|
580
|
-
### Dark Mode Support
|
|
581
|
-
|
|
582
|
-
Enable dark mode support in `normal` mode by adding the `dark` configuration:
|
|
583
|
-
|
|
584
|
-
```json
|
|
585
|
-
{
|
|
586
|
-
"expo": {
|
|
587
|
-
"plugins": [
|
|
588
|
-
[
|
|
589
|
-
"expo-splash-screen2",
|
|
590
|
-
{
|
|
591
|
-
"mode": "normal",
|
|
592
|
-
"backgroundColor": "#FFFFFF",
|
|
593
|
-
"image": "./assets/splash-icon.png",
|
|
594
|
-
"imageWidth": 100,
|
|
595
|
-
"dark": {
|
|
596
|
-
"backgroundColor": "#000000",
|
|
597
|
-
"image": "./assets/splash-icon-dark.png"
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
]
|
|
601
|
-
]
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
```
|
|
605
|
-
|
|
606
|
-
#### Dark Mode Options
|
|
607
|
-
|
|
608
|
-
| Option | Type | Required | Description |
|
|
609
|
-
|--------|------|----------|-------------|
|
|
610
|
-
| `dark.backgroundColor` | `string` | No | Dark mode background color |
|
|
611
|
-
| `dark.image` | `string` | No | Dark mode image (can be same as light mode) |
|
|
612
|
-
|
|
613
|
-
When dark mode is enabled:
|
|
614
|
-
- **Android**: Images are placed in `drawable/` and `drawable-night/` directories
|
|
615
|
-
- **iOS**: App detects system appearance and switches colors/images accordingly
|
|
616
|
-
- **Runtime switching**: Both platforms support runtime theme changes
|
|
617
|
-
|
|
618
|
-
## 📱 Platform-Specific Details
|
|
619
|
-
|
|
620
|
-
### 📱 iOS Configuration
|
|
621
|
-
|
|
622
|
-
The plugin automatically:
|
|
623
|
-
|
|
624
|
-
1. Copies splash images to the iOS bundle
|
|
625
|
-
2. Modifies `AppDelegate.swift` to display the splash screen
|
|
626
|
-
3. Sets up dark mode detection using `UITraitCollection`
|
|
627
|
-
4. Adds `UIApplication.didBecomeActiveNotification` observer for runtime theme changes
|
|
628
|
-
|
|
629
|
-
#### Resource Locations
|
|
630
|
-
|
|
631
|
-
- Light mode image: `ios/{projectName}/splash-icon.{ext}`
|
|
632
|
-
- Dark mode image: `ios/{projectName}/splash-icon-dark.{ext}`
|
|
633
|
-
|
|
634
|
-
### Manual iOS Configuration
|
|
635
|
-
|
|
636
|
-
The plugin automatically handles iOS configuration, but if you need to manually configure or understand how it works, here are the details for each mode:
|
|
637
|
-
|
|
638
|
-
#### WebView Mode
|
|
639
|
-
|
|
640
|
-
For WebView mode, the plugin:
|
|
641
|
-
|
|
642
|
-
1. **Modifies `SplashScreen.storyboard`**: Sets background color and optional centered image
|
|
643
|
-
2. **Copies HTML files**: Places HTML files from `expo-splash-web/dist` or `localHtmlPath` to `ios/{projectName}/` directory
|
|
644
|
-
3. **Modifies `AppDelegate.swift`**: Adds code to display WebView overlay with HTML content
|
|
645
|
-
4. **Creates Asset Catalog**: Creates `SplashScreenBackground` colorset for background color
|
|
646
|
-
|
|
647
|
-
**Manual steps** (if needed):
|
|
648
|
-
|
|
649
|
-
1. Copy HTML file to `ios/{projectName}/index.html`
|
|
650
|
-
2. Modify `SplashScreen.storyboard` to set background color using `SplashScreenBackground` colorset
|
|
651
|
-
3. Modify `AppDelegate.swift` to add WebView container code (see plugin source for template)
|
|
652
|
-
4. Ensure `SplashScreen.storyboard` is set as Launch Screen File in Xcode project settings
|
|
653
|
-
|
|
654
|
-
#### ResponsiveImage Mode
|
|
655
|
-
|
|
656
|
-
For ResponsiveImage mode, the plugin:
|
|
657
|
-
|
|
658
|
-
1. **Copies background image**: Places image file as `splash_background_image.{ext}` in `ios/{projectName}/` directory
|
|
659
|
-
2. **Modifies `SplashScreen.storyboard`**: Sets full-screen background image with `scaleAspectFill` content mode
|
|
660
|
-
3. **Modifies `AppDelegate.swift`**: Adds image container view
|
|
661
|
-
4. **Adds file reference**: Adds image file to Xcode project
|
|
662
|
-
|
|
663
|
-
**Manual steps** (if needed):
|
|
664
|
-
|
|
665
|
-
1. Copy background image to `ios/{projectName}/splash_background_image.{ext}`
|
|
666
|
-
2. Modify `SplashScreen.storyboard`:
|
|
667
|
-
- Set Image View to use `splash_background_image` image
|
|
668
|
-
- Set Content Mode to `Aspect Fill` for full-screen coverage
|
|
669
|
-
- Set background color (fallback)
|
|
670
|
-
3. Modify `AppDelegate.swift` to add image container view
|
|
671
|
-
4. Add image file to Xcode project file references
|
|
672
|
-
|
|
673
|
-
#### Normal Mode
|
|
674
|
-
|
|
675
|
-
For Normal mode, the plugin:
|
|
676
|
-
|
|
677
|
-
1. **Creates Asset Catalog imageset**: Creates `splash-icon` imageset in `Images.xcassets` (supports dark mode if configured)
|
|
678
|
-
2. **Creates Asset Catalog colorset**: Creates `SplashScreenBackground` colorset (supports dark mode if configured)
|
|
679
|
-
3. **Modifies `SplashScreen.storyboard`**: Sets background color and centered image with fixed width
|
|
680
|
-
4. **Modifies `AppDelegate.swift`**: Adds image container view with fixed width constraints
|
|
681
|
-
|
|
682
|
-
**Manual steps** (if needed):
|
|
683
|
-
|
|
684
|
-
1. Create `splash-icon` imageset in `Images.xcassets`:
|
|
685
|
-
- Add light mode image
|
|
686
|
-
- If dark mode enabled, add dark mode image in `Any, Dark` appearance
|
|
687
|
-
2. Create `SplashScreenBackground` colorset in `Images.xcassets`:
|
|
688
|
-
- Set light mode color
|
|
689
|
-
- If dark mode enabled, set dark mode color in `Any, Dark` appearance
|
|
690
|
-
3. Modify `SplashScreen.storyboard`:
|
|
691
|
-
- Set Image View to use `splash-icon` image
|
|
692
|
-
- Set Content Mode to `Aspect Fit`
|
|
693
|
-
- Set background to use `SplashScreenBackground` colorset
|
|
694
|
-
- Add width constraint (default 100pt) to Image View
|
|
695
|
-
4. Modify `AppDelegate.swift` to add image container view with width constraints
|
|
696
|
-
|
|
697
|
-
### 🤖 Android Configuration
|
|
698
|
-
|
|
699
|
-
The plugin automatically:
|
|
700
|
-
|
|
701
|
-
1. Copies splash images to Android drawable directories
|
|
702
|
-
2. Modifies `MainActivity.kt` to display the splash screen
|
|
703
|
-
3. Creates `values/colors.xml` and `values-night/colors.xml` for dark mode
|
|
704
|
-
4. Sets up `Configuration.UI_MODE_NIGHT_MASK` detection
|
|
705
|
-
|
|
706
|
-
#### Resource Locations
|
|
707
|
-
|
|
708
|
-
- Light mode image: `android/app/src/main/res/drawable/splash_icon.png`
|
|
709
|
-
- Dark mode image: `android/app/src/main/res/drawable-night/splash_icon.png`
|
|
710
|
-
- Light colors: `android/app/src/main/res/values/colors.xml`
|
|
711
|
-
- Dark colors: `android/app/src/main/res/values-night/colors.xml`
|
|
712
|
-
|
|
713
|
-
### Manual Android Configuration
|
|
714
|
-
|
|
715
|
-
The plugin automatically handles Android configuration, but if you need to manually configure or understand how it works, here are the details for each mode:
|
|
716
|
-
|
|
717
|
-
#### WebView Mode
|
|
718
|
-
|
|
719
|
-
For WebView mode, the plugin:
|
|
720
|
-
|
|
721
|
-
1. **Copies HTML file**: Places HTML file from `expo-splash-web/dist/index.html` or `localHtmlPath` to `android/app/src/main/assets/index.html`
|
|
722
|
-
2. **Copies icon** (optional): If `image` is configured, copies icon to `android/app/src/main/res/drawable-xxhdpi/ic_splash_icon.png`
|
|
723
|
-
3. **Creates CustomSplashActivity**: Generates `SplashScreen2Activity.kt` for displaying WebView
|
|
724
|
-
4. **Modifies AndroidManifest.xml**: Adds `SplashScreen2Activity` as launcher activity
|
|
725
|
-
5. **Modifies MainActivity.kt**: Adds WebView container code and methods
|
|
726
|
-
6. **Modifies styles.xml**: Updates `Theme.App.SplashScreen` and adds `Theme.App.MainActivity`
|
|
727
|
-
7. **Creates colors.xml**: Creates color resources for background color
|
|
728
|
-
8. **Updates build.gradle**: Adds `androidx.core:core-splashscreen` dependency
|
|
729
|
-
|
|
730
|
-
**Manual steps** (if needed):
|
|
731
|
-
|
|
732
|
-
1. Copy HTML file to `android/app/src/main/assets/index.html`
|
|
733
|
-
2. Create `SplashScreen2Activity.kt` in `android/app/src/main/java/{packageName}/` (see plugin templates)
|
|
734
|
-
3. Modify `AndroidManifest.xml`:
|
|
735
|
-
- Add `SplashScreen2Activity` as launcher activity
|
|
736
|
-
- Set `MainActivity` theme to `Theme.App.MainActivity`
|
|
737
|
-
4. Modify `MainActivity.kt` to add WebView container code
|
|
738
|
-
5. Update `res/values/styles.xml` with splash screen themes
|
|
739
|
-
6. Create `res/values/colors.xml` with `splashscreen_background` color
|
|
740
|
-
7. Add `androidx.core:core-splashscreen:1.0.1` dependency to `build.gradle`
|
|
741
|
-
|
|
742
|
-
#### ResponsiveImage Mode
|
|
743
|
-
|
|
744
|
-
For ResponsiveImage mode, the plugin:
|
|
745
|
-
|
|
746
|
-
1. **Copies background image**: Places image as `splash_background_image.{ext}` in `android/app/src/main/res/drawable/` (supports `.9.png`)
|
|
747
|
-
2. **Updates ic_launcher_background.xml**: Modifies to show background image only
|
|
748
|
-
3. **Creates colors.xml**: Creates `splashscreen_background` color resource
|
|
749
|
-
4. **Modifies styles.xml**: Updates `Theme.App.SplashScreen` to use background image
|
|
750
|
-
5. **Modifies MainActivity.kt**: Adds image container view for full-screen display
|
|
751
|
-
|
|
752
|
-
**Manual steps** (if needed):
|
|
753
|
-
|
|
754
|
-
1. Copy background image to `android/app/src/main/res/drawable/splash_background_image.{ext}`
|
|
755
|
-
2. Update `res/drawable/ic_launcher_background.xml`:
|
|
756
|
-
```xml
|
|
757
|
-
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
|
758
|
-
<item android:drawable="@drawable/splash_background_image"/>
|
|
759
|
-
</layer-list>
|
|
760
|
-
```
|
|
761
|
-
3. Create `res/values/colors.xml`:
|
|
762
|
-
```xml
|
|
763
|
-
<resources>
|
|
764
|
-
<color name="splashscreen_background">#FFFFFF</color>
|
|
765
|
-
</resources>
|
|
766
|
-
```
|
|
767
|
-
4. Update `res/values/styles.xml`:
|
|
768
|
-
```xml
|
|
769
|
-
<style name="Theme.App.SplashScreen" parent="Theme.SplashScreen">
|
|
770
|
-
<item name="android:windowBackground">@drawable/ic_launcher_background</item>
|
|
771
|
-
</style>
|
|
772
|
-
```
|
|
773
|
-
5. Modify `MainActivity.kt` to add image container view
|
|
774
|
-
|
|
775
|
-
#### Normal Mode
|
|
776
|
-
|
|
777
|
-
For Normal mode, the plugin:
|
|
778
|
-
|
|
779
|
-
1. **Copies icon image**: Places image as `splash_icon.{ext}` in `android/app/src/main/res/drawable-xxhdpi/`
|
|
780
|
-
2. **Copies dark icon** (if dark mode enabled): Places dark image in `android/app/src/main/res/drawable-night-xxhdpi/`
|
|
781
|
-
3. **Creates splashscreen_logo**: Creates drawable resource for system splash screen
|
|
782
|
-
4. **Creates colors.xml**: Creates `splashscreen_background` color (supports dark mode in `values-night/colors.xml`)
|
|
783
|
-
5. **Modifies MainActivity.kt**: Adds image container view with fixed width constraints
|
|
784
|
-
|
|
785
|
-
**Manual steps** (if needed):
|
|
786
|
-
|
|
787
|
-
1. Copy icon image to `android/app/src/main/res/drawable-xxhdpi/splash_icon.{ext}`
|
|
788
|
-
2. If dark mode enabled, copy dark icon to `android/app/src/main/res/drawable-night-xxhdpi/splash_icon.{ext}`
|
|
789
|
-
3. Create `res/drawable/splashscreen_logo.xml`:
|
|
790
|
-
```xml
|
|
791
|
-
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
|
792
|
-
<item android:drawable="@color/splashscreen_background"/>
|
|
793
|
-
<item>
|
|
794
|
-
<bitmap android:gravity="center" android:src="@drawable/splash_icon"/>
|
|
795
|
-
</item>
|
|
796
|
-
</layer-list>
|
|
797
|
-
```
|
|
798
|
-
4. Create `res/values/colors.xml`:
|
|
799
|
-
```xml
|
|
800
|
-
<resources>
|
|
801
|
-
<color name="splashscreen_background">#FFFFFF</color>
|
|
802
|
-
</resources>
|
|
803
|
-
```
|
|
804
|
-
5. If dark mode enabled, create `res/values-night/colors.xml`:
|
|
805
|
-
```xml
|
|
806
|
-
<resources>
|
|
807
|
-
<color name="splashscreen_background">#000000</color>
|
|
808
|
-
</resources>
|
|
809
|
-
```
|
|
810
|
-
6. Update `res/values/styles.xml`:
|
|
811
|
-
```xml
|
|
812
|
-
<style name="Theme.App.SplashScreen" parent="Theme.SplashScreen">
|
|
813
|
-
<item name="android:windowBackground">@drawable/splashscreen_logo</item>
|
|
814
|
-
</style>
|
|
815
|
-
```
|
|
816
|
-
7. Modify `MainActivity.kt` to add image container view with fixed width (default 100dp)
|
|
817
|
-
|
|
818
|
-
### Manual Regeneration
|
|
819
|
-
|
|
820
|
-
If you need to regenerate native projects with the latest plugin changes:
|
|
821
|
-
|
|
822
|
-
```bash
|
|
823
|
-
# Clean and regenerate
|
|
824
|
-
npx expo prebuild --clean
|
|
825
|
-
|
|
826
|
-
# Or for specific platform
|
|
827
|
-
npx expo prebuild --clean --platform android
|
|
828
|
-
npx expo prebuild --clean --platform ios
|
|
829
|
-
```
|
|
830
|
-
|
|
831
|
-
## 👏 Contributing
|
|
832
|
-
|
|
833
|
-
Contributions are welcome! Please feel free to submit issues and pull requests.
|
|
834
|
-
|
|
835
|
-
## ❓ Known Issues
|
|
836
|
-
|
|
837
|
-
### iOS Caching
|
|
838
|
-
|
|
839
|
-
Splash screens on iOS can sometimes encounter a caching issue where the previous image will flash before showing the new image. When this occurs, try:
|
|
840
|
-
1. Power cycling your device
|
|
841
|
-
2. Uninstalling and re-installing the application
|
|
842
|
-
3. Running `npx expo prebuild --clean`
|
|
843
|
-
|
|
844
|
-
### Node Modules Caching
|
|
845
|
-
|
|
846
|
-
If plugin changes aren't being applied, try:
|
|
847
|
-
|
|
848
|
-
```bash
|
|
849
|
-
cd your-project
|
|
850
|
-
rm -rf node_modules/expo-splash-screen2
|
|
851
|
-
npm install # or pnpm install
|
|
852
|
-
npx expo prebuild --clean
|
|
853
|
-
```
|
|
854
|
-
|
|
855
|
-
### Dark Mode Not Working
|
|
856
|
-
|
|
857
|
-
Ensure:
|
|
858
|
-
1. Your `app.json` has the `dark` configuration in `normal` mode
|
|
859
|
-
2. You've run `npx expo prebuild --clean` after configuration changes
|
|
860
|
-
3. Both light and dark images exist at the specified paths
|
|
861
|
-
|
|
862
|
-
### Android 12+ System Default Splash Screen
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
**Note: Android 12+ System Default Behavior**
|
|
866
|
-
|
|
867
|
-
If your app runs on Android 12 or higher and your `targetSdkVersion` is not below 30, the system will display a default splash screen. This is the default behavior of Android and may result in two splash screens appearing (system default splash + custom splash).
|
|
868
|
-
|
|
869
|
-
If you don't want to show the system default splash screen, you can use either of the following methods:
|
|
870
|
-
|
|
871
|
-
**Method 1: Make the default splash transparent**
|
|
872
|
-
|
|
873
|
-
Add the following to your Activity theme in `AndroidManifest.xml`:
|
|
874
|
-
|
|
875
|
-
```xml
|
|
876
|
-
<item name="android:windowIsTranslucent">true</item>
|
|
877
|
-
```
|
|
878
|
-
|
|
879
|
-
**Method 2: Adjust targetSdkVersion**
|
|
880
|
-
|
|
881
|
-
Set `androidTargetSdkVersion` to 30 or lower to hide the system default splash screen.
|
|
882
|
-
|
|
883
|
-
## 📄 License
|
|
884
|
-
|
|
885
|
-
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
|
|
95
|
+
MIT
|
|
886
96
|
|
|
887
97
|
This module is based on [expo-splash-screen](https://github.com/expo/expo/tree/main/packages/expo-splash-screen), which is also licensed under the MIT License.
|
|
888
98
|
|
|
889
|
-
|
|
99
|
+
### Hall of Fame
|
|
890
100
|
|
|
891
101
|
This module is based on a solid work from (many thanks for that 👏):
|
|
892
102
|
|
|
893
103
|
- [expo-splash-screen](https://github.com/expo/expo/tree/main/packages/expo-splash-screen)
|
|
894
|
-
|