react-native-custom-splash 2.0.0 → 2.1.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 +180 -72
- package/example/README.md +175 -0
- package/example/app.json +38 -0
- package/example/app.json.option1-full-image +14 -0
- package/example/app.json.option2-color-logo +16 -0
- package/example/app.json.option3-image-logo +17 -0
- package/example/app.json.option4-color-only +14 -0
- package/package.json +3 -1
- package/plugin/src/index.js +153 -5
package/README.md
CHANGED
|
@@ -37,7 +37,75 @@ your-project/
|
|
|
37
37
|
|
|
38
38
|
### Step 2: Configure in app.json
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
Choose one of the 4 configuration options below based on your needs:
|
|
41
|
+
|
|
42
|
+
## 🎨 Configuration Examples
|
|
43
|
+
|
|
44
|
+
### **Option 1: Single Full Image** (Most Common) ⭐
|
|
45
|
+
|
|
46
|
+
Perfect for a complete branded splash screen with your custom design.
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"expo": {
|
|
51
|
+
"name": "YourApp",
|
|
52
|
+
"plugins": [
|
|
53
|
+
[
|
|
54
|
+
"react-native-custom-splash",
|
|
55
|
+
{
|
|
56
|
+
"image": "./assets/splash.png"
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Project Structure:**
|
|
65
|
+
```
|
|
66
|
+
your-project/
|
|
67
|
+
├── assets/
|
|
68
|
+
│ └── splash.png ← Your full-screen image (1242×2688px)
|
|
69
|
+
└── app.json
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
### **Option 2: Background Color + Center Logo**
|
|
75
|
+
|
|
76
|
+
Great for a clean, minimal look with just your logo.
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"expo": {
|
|
81
|
+
"name": "YourApp",
|
|
82
|
+
"plugins": [
|
|
83
|
+
[
|
|
84
|
+
"react-native-custom-splash",
|
|
85
|
+
{
|
|
86
|
+
"backgroundColor": "#4F46E5",
|
|
87
|
+
"logo": "./assets/logo.png",
|
|
88
|
+
"logoWidth": 180
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**Project Structure:**
|
|
97
|
+
```
|
|
98
|
+
your-project/
|
|
99
|
+
├── assets/
|
|
100
|
+
│ └── logo.png ← Your center logo (512×512px)
|
|
101
|
+
└── app.json
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
### **Option 3: Background Image + Center Logo**
|
|
107
|
+
|
|
108
|
+
Maximum customization - background image with logo on top.
|
|
41
109
|
|
|
42
110
|
```json
|
|
43
111
|
{
|
|
@@ -48,7 +116,7 @@ Add the plugin configuration to your `app.json`:
|
|
|
48
116
|
"react-native-custom-splash",
|
|
49
117
|
{
|
|
50
118
|
"backgroundColor": "#FFFFFF",
|
|
51
|
-
"image": "./assets/splash-
|
|
119
|
+
"image": "./assets/splash-bg.png",
|
|
52
120
|
"logo": "./assets/logo.png",
|
|
53
121
|
"logoWidth": 150
|
|
54
122
|
}
|
|
@@ -58,6 +126,39 @@ Add the plugin configuration to your `app.json`:
|
|
|
58
126
|
}
|
|
59
127
|
```
|
|
60
128
|
|
|
129
|
+
**Project Structure:**
|
|
130
|
+
```
|
|
131
|
+
your-project/
|
|
132
|
+
├── assets/
|
|
133
|
+
│ ├── splash-bg.png ← Background image
|
|
134
|
+
│ └── logo.png ← Center logo
|
|
135
|
+
└── app.json
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
### **Option 4: Only Background Color**
|
|
141
|
+
|
|
142
|
+
Simple solid color background.
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"expo": {
|
|
147
|
+
"name": "YourApp",
|
|
148
|
+
"plugins": [
|
|
149
|
+
[
|
|
150
|
+
"react-native-custom-splash",
|
|
151
|
+
{
|
|
152
|
+
"backgroundColor": "#FF6B6B"
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
]
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
61
162
|
### Step 3: Run prebuild
|
|
62
163
|
|
|
63
164
|
```bash
|
|
@@ -90,79 +191,15 @@ function App() {
|
|
|
90
191
|
}
|
|
91
192
|
```
|
|
92
193
|
|
|
93
|
-
## ⚙️ Configuration Options
|
|
194
|
+
## ⚙️ Configuration Options Reference
|
|
94
195
|
|
|
95
196
|
| Option | Type | Default | Description |
|
|
96
197
|
|--------|------|---------|-------------|
|
|
97
|
-
| `backgroundColor` | `string` | `#FFFFFF` | Background color
|
|
98
|
-
| `image` | `string` | `null` | Path to full background image (
|
|
99
|
-
| `logo` | `string` | `null` | Path to center logo image (
|
|
198
|
+
| `backgroundColor` | `string` | `#FFFFFF` | Background color (hex format: #RRGGBB) |
|
|
199
|
+
| `image` | `string` | `null` | Path to full background image (optional) |
|
|
200
|
+
| `logo` | `string` | `null` | Path to center logo image (optional) |
|
|
100
201
|
| `logoWidth` | `number` | `150` | Width of the center logo in pixels |
|
|
101
202
|
|
|
102
|
-
### Configuration Examples
|
|
103
|
-
|
|
104
|
-
#### Only Background Color
|
|
105
|
-
```json
|
|
106
|
-
{
|
|
107
|
-
"plugins": [
|
|
108
|
-
[
|
|
109
|
-
"react-native-custom-splash",
|
|
110
|
-
{
|
|
111
|
-
"backgroundColor": "#FF6B6B"
|
|
112
|
-
}
|
|
113
|
-
]
|
|
114
|
-
]
|
|
115
|
-
}
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
#### Background Color + Logo
|
|
119
|
-
```json
|
|
120
|
-
{
|
|
121
|
-
"plugins": [
|
|
122
|
-
[
|
|
123
|
-
"react-native-custom-splash",
|
|
124
|
-
{
|
|
125
|
-
"backgroundColor": "#1E3A8A",
|
|
126
|
-
"logo": "./assets/logo.png",
|
|
127
|
-
"logoWidth": 200
|
|
128
|
-
}
|
|
129
|
-
]
|
|
130
|
-
]
|
|
131
|
-
}
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
#### Full Background Image + Logo
|
|
135
|
-
```json
|
|
136
|
-
{
|
|
137
|
-
"plugins": [
|
|
138
|
-
[
|
|
139
|
-
"react-native-custom-splash",
|
|
140
|
-
{
|
|
141
|
-
"backgroundColor": "#FFFFFF",
|
|
142
|
-
"image": "./assets/splash-bg.png",
|
|
143
|
-
"logo": "./assets/logo.png",
|
|
144
|
-
"logoWidth": 180
|
|
145
|
-
}
|
|
146
|
-
]
|
|
147
|
-
]
|
|
148
|
-
}
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
#### Only Background Image (No Logo)
|
|
152
|
-
```json
|
|
153
|
-
{
|
|
154
|
-
"plugins": [
|
|
155
|
-
[
|
|
156
|
-
"react-native-custom-splash",
|
|
157
|
-
{
|
|
158
|
-
"backgroundColor": "#000000",
|
|
159
|
-
"image": "./assets/splash-full.png"
|
|
160
|
-
}
|
|
161
|
-
]
|
|
162
|
-
]
|
|
163
|
-
}
|
|
164
|
-
```
|
|
165
|
-
|
|
166
203
|
## 📱 API Reference
|
|
167
204
|
|
|
168
205
|
### `SplashScreen.hide(animated)`
|
|
@@ -301,18 +338,89 @@ Add your images to Android resources:
|
|
|
301
338
|
|
|
302
339
|
## ❓ Troubleshooting
|
|
303
340
|
|
|
341
|
+
### ⚠️ Error: "Plugin is an unexpected object"
|
|
342
|
+
|
|
343
|
+
**Full Error:**
|
|
344
|
+
```
|
|
345
|
+
PluginError: Plugin is an unexpected object, with keys: "backgroundColor, image, logoWidth".
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
**Cause:** Your plugin configuration is not properly wrapped in square brackets.
|
|
349
|
+
|
|
350
|
+
**❌ Wrong:**
|
|
351
|
+
```json
|
|
352
|
+
{
|
|
353
|
+
"plugins": [
|
|
354
|
+
"react-native-custom-splash",
|
|
355
|
+
{
|
|
356
|
+
"backgroundColor": "#FF6B6B"
|
|
357
|
+
}
|
|
358
|
+
]
|
|
359
|
+
}
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
**✅ Correct:**
|
|
363
|
+
```json
|
|
364
|
+
{
|
|
365
|
+
"plugins": [
|
|
366
|
+
[
|
|
367
|
+
"react-native-custom-splash",
|
|
368
|
+
{
|
|
369
|
+
"backgroundColor": "#FF6B6B"
|
|
370
|
+
}
|
|
371
|
+
]
|
|
372
|
+
]
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
**Key Point:** When passing configuration to a plugin, wrap BOTH the plugin name and the config object in square brackets `[]`.
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
304
380
|
### Splash screen not showing
|
|
305
381
|
- Make sure you run `npx expo prebuild --clean` after changing configuration
|
|
306
382
|
- Check that your image paths in `app.json` are correct and files exist
|
|
307
|
-
-
|
|
383
|
+
- Verify images are in the `assets/` folder
|
|
384
|
+
- Try cleaning your build:
|
|
385
|
+
- iOS: `cd ios && pod install && cd ..`
|
|
386
|
+
- Android: `cd android && ./gradlew clean && cd ..`
|
|
308
387
|
|
|
309
388
|
### Images not updating
|
|
310
389
|
- Run `npx expo prebuild --clean` to force regeneration of native projects
|
|
311
|
-
-
|
|
390
|
+
- Delete `ios/` and `android/` folders, then run `npx expo prebuild --clean` again
|
|
391
|
+
- Clear build caches:
|
|
392
|
+
- iOS: `rm -rf ios/Pods ios/build`
|
|
393
|
+
- Android: `cd android && ./gradlew clean && cd ..`
|
|
394
|
+
|
|
395
|
+
### Image paths not working
|
|
396
|
+
- Use relative paths from project root: `"./assets/splash.png"` ✅
|
|
397
|
+
- Don't use absolute paths: `"/Users/..."` ❌
|
|
398
|
+
- Make sure the file extension matches (`.png`, `.jpg`)
|
|
399
|
+
- Check file actually exists at that path
|
|
400
|
+
|
|
401
|
+
### Background color not working
|
|
402
|
+
- Use hex format: `"#FF6B6B"` ✅
|
|
403
|
+
- Don't forget the `#`: `"FF6B6B"` ❌
|
|
404
|
+
- Use 6-digit format: `"#FFFFFF"` ✅ not `"#FFF"` ❌
|
|
312
405
|
|
|
313
406
|
### TypeScript errors
|
|
314
407
|
- Make sure you have `@types/react` and `@types/react-native` installed
|
|
315
408
|
- The package includes TypeScript definitions
|
|
409
|
+
- Try: `npm install --save-dev @types/react @types/react-native`
|
|
410
|
+
|
|
411
|
+
### Pod install fails (iOS)
|
|
412
|
+
```bash
|
|
413
|
+
cd ios
|
|
414
|
+
rm -rf Pods Podfile.lock
|
|
415
|
+
pod install --repo-update
|
|
416
|
+
cd ..
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
### Still having issues?
|
|
420
|
+
1. Delete `node_modules/` and reinstall: `npm install` or `yarn install`
|
|
421
|
+
2. Delete `ios/` and `android/` folders
|
|
422
|
+
3. Run `npx expo prebuild --clean`
|
|
423
|
+
4. Check the [GitHub Issues](https://github.com/vijaykishan312/react-native-custom-splash/issues)
|
|
316
424
|
|
|
317
425
|
## 📄 License
|
|
318
426
|
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# react-native-custom-splash Example App
|
|
2
|
+
|
|
3
|
+
This example demonstrates how to use `react-native-custom-splash` in your Expo app.
|
|
4
|
+
|
|
5
|
+
## 📁 Project Structure
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
example/
|
|
9
|
+
├── assets/
|
|
10
|
+
│ ├── splash-bg.png ← Background image for splash
|
|
11
|
+
│ ├── logo.png ← Center logo
|
|
12
|
+
│ ├── icon.png ← App icon
|
|
13
|
+
│ └── ...
|
|
14
|
+
├── app.json ← Configuration with plugin setup
|
|
15
|
+
├── App.tsx ← Main app with SplashScreen usage
|
|
16
|
+
└── package.json
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 🚀 Running the Example
|
|
20
|
+
|
|
21
|
+
### 1. Install Dependencies
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
cd example
|
|
25
|
+
npm install
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2. Run Prebuild
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx expo prebuild --clean
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 3. Run on Device/Simulator
|
|
35
|
+
|
|
36
|
+
**iOS:**
|
|
37
|
+
```bash
|
|
38
|
+
npx expo run:ios
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Android:**
|
|
42
|
+
```bash
|
|
43
|
+
npx expo run:android
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 🎨 Configuration Examples
|
|
47
|
+
|
|
48
|
+
The example `app.json` is configured with **Option 3** (Background Image + Logo):
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"plugins": [
|
|
53
|
+
[
|
|
54
|
+
"react-native-custom-splash",
|
|
55
|
+
{
|
|
56
|
+
"backgroundColor": "#4F46E5",
|
|
57
|
+
"image": "./assets/splash-bg.png",
|
|
58
|
+
"logo": "./assets/logo.png",
|
|
59
|
+
"logoWidth": 180
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Try Different Configurations:
|
|
67
|
+
|
|
68
|
+
#### Option 1: Single Full Image (Simplest)
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"plugins": [
|
|
72
|
+
[
|
|
73
|
+
"react-native-custom-splash",
|
|
74
|
+
{
|
|
75
|
+
"image": "./assets/splash.png"
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
#### Option 2: Color + Logo (Minimal)
|
|
83
|
+
```json
|
|
84
|
+
{
|
|
85
|
+
"plugins": [
|
|
86
|
+
[
|
|
87
|
+
"react-native-custom-splash",
|
|
88
|
+
{
|
|
89
|
+
"backgroundColor": "#4F46E5",
|
|
90
|
+
"logo": "./assets/logo.png",
|
|
91
|
+
"logoWidth": 180
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
]
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### Option 4: Only Color (Fastest)
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"plugins": [
|
|
102
|
+
[
|
|
103
|
+
"react-native-custom-splash",
|
|
104
|
+
{
|
|
105
|
+
"backgroundColor": "#FF6B6B"
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**After changing configuration:**
|
|
113
|
+
```bash
|
|
114
|
+
npx expo prebuild --clean
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## 💡 Usage in Code
|
|
118
|
+
|
|
119
|
+
Check `App.tsx` to see how the splash screen is used:
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import SplashScreen from 'react-native-custom-splash';
|
|
123
|
+
import { useEffect } from 'react';
|
|
124
|
+
|
|
125
|
+
function App() {
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
// Hide splash after 2 seconds
|
|
128
|
+
const timer = setTimeout(() => {
|
|
129
|
+
SplashScreen.hide(true); // true = with animation
|
|
130
|
+
}, 2000);
|
|
131
|
+
|
|
132
|
+
return () => clearTimeout(timer);
|
|
133
|
+
}, []);
|
|
134
|
+
|
|
135
|
+
// Your app content...
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## 🖼️ Image Guidelines
|
|
140
|
+
|
|
141
|
+
### Background Image (`splash-bg.png`)
|
|
142
|
+
- **Size:** 1242 x 2688 px (iPhone 13 Pro Max)
|
|
143
|
+
- **Format:** PNG or JPG
|
|
144
|
+
- **Aspect Ratio:** 9:19.5 (standard phone ratio)
|
|
145
|
+
- **Design:** Center-weighted content
|
|
146
|
+
|
|
147
|
+
### Logo (`logo.png`)
|
|
148
|
+
- **Size:** 512 x 512 px (or your aspect ratio)
|
|
149
|
+
- **Format:** PNG with transparency
|
|
150
|
+
- **Design:** Will be scaled based on `logoWidth`
|
|
151
|
+
|
|
152
|
+
## 🔧 Troubleshooting
|
|
153
|
+
|
|
154
|
+
### Changes not reflecting?
|
|
155
|
+
```bash
|
|
156
|
+
# Clean everything and rebuild
|
|
157
|
+
npx expo prebuild --clean
|
|
158
|
+
cd ios && pod install && cd ..
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Images not showing?
|
|
162
|
+
- Check image paths in `app.json` are correct
|
|
163
|
+
- Ensure images exist in `assets/` folder
|
|
164
|
+
- Run `npx expo prebuild --clean`
|
|
165
|
+
|
|
166
|
+
### TypeScript errors?
|
|
167
|
+
```bash
|
|
168
|
+
npm install --save-dev @types/react @types/react-native
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## 📚 Learn More
|
|
172
|
+
|
|
173
|
+
- [Main README](../README.md)
|
|
174
|
+
- [npm Package](https://www.npmjs.com/package/react-native-custom-splash)
|
|
175
|
+
- [GitHub Repository](https://github.com/vijaykishan312/react-native-custom-splash)
|
package/example/app.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"expo": {
|
|
3
|
+
"name": "SplashScreenExample",
|
|
4
|
+
"slug": "splash-screen-example",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"orientation": "portrait",
|
|
7
|
+
"icon": "./assets/icon.png",
|
|
8
|
+
"userInterfaceStyle": "light",
|
|
9
|
+
"assetBundlePatterns": [
|
|
10
|
+
"**/*"
|
|
11
|
+
],
|
|
12
|
+
"ios": {
|
|
13
|
+
"supportsTablet": true,
|
|
14
|
+
"bundleIdentifier": "com.example.splashscreen"
|
|
15
|
+
},
|
|
16
|
+
"android": {
|
|
17
|
+
"adaptiveIcon": {
|
|
18
|
+
"foregroundImage": "./assets/adaptive-icon.png",
|
|
19
|
+
"backgroundColor": "#ffffff"
|
|
20
|
+
},
|
|
21
|
+
"package": "com.example.splashscreen"
|
|
22
|
+
},
|
|
23
|
+
"web": {
|
|
24
|
+
"favicon": "./assets/favicon.png"
|
|
25
|
+
},
|
|
26
|
+
"plugins": [
|
|
27
|
+
[
|
|
28
|
+
"react-native-custom-splash",
|
|
29
|
+
{
|
|
30
|
+
"backgroundColor": "#4F46E5",
|
|
31
|
+
"image": "./assets/splash-bg.png",
|
|
32
|
+
"logo": "./assets/logo.png",
|
|
33
|
+
"logoWidth": 180
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"expo": {
|
|
3
|
+
"name": "Example - Color + Logo",
|
|
4
|
+
"slug": "splash-example-color-logo",
|
|
5
|
+
"plugins": [
|
|
6
|
+
[
|
|
7
|
+
"react-native-custom-splash",
|
|
8
|
+
{
|
|
9
|
+
"backgroundColor": "#4F46E5",
|
|
10
|
+
"logo": "./assets/logo.png",
|
|
11
|
+
"logoWidth": 180
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"expo": {
|
|
3
|
+
"name": "Example - Image + Logo",
|
|
4
|
+
"slug": "splash-example-image-logo",
|
|
5
|
+
"plugins": [
|
|
6
|
+
[
|
|
7
|
+
"react-native-custom-splash",
|
|
8
|
+
{
|
|
9
|
+
"backgroundColor": "#FFFFFF",
|
|
10
|
+
"image": "./assets/splash-bg.png",
|
|
11
|
+
"logo": "./assets/logo.png",
|
|
12
|
+
"logoWidth": 150
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-custom-splash",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A custom splash screen module for React Native with native iOS and Android support, fully compatible with Expo",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
@@ -44,6 +44,8 @@
|
|
|
44
44
|
"plugin/",
|
|
45
45
|
"app.plugin.js",
|
|
46
46
|
"react-native-custom-splash.podspec",
|
|
47
|
+
"example/app.json*",
|
|
48
|
+
"example/README.md",
|
|
47
49
|
"README.md",
|
|
48
50
|
"LICENSE"
|
|
49
51
|
]
|
package/plugin/src/index.js
CHANGED
|
@@ -8,7 +8,53 @@ const {
|
|
|
8
8
|
} = require('@expo/config-plugins');
|
|
9
9
|
const path = require('path');
|
|
10
10
|
const fs = require('fs');
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Validate and normalize plugin configuration
|
|
14
|
+
*/
|
|
15
|
+
function validateAndNormalizeConfig(props) {
|
|
16
|
+
// Check if props is valid
|
|
17
|
+
if (!props || typeof props !== 'object') {
|
|
18
|
+
console.warn('⚠️ react-native-custom-splash: No configuration provided, using defaults');
|
|
19
|
+
return {
|
|
20
|
+
backgroundColor: '#FFFFFF',
|
|
21
|
+
image: null,
|
|
22
|
+
logo: null,
|
|
23
|
+
logoWidth: 150,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Validate backgroundColor
|
|
28
|
+
if (props.backgroundColor && !/^#[0-9A-Fa-f]{6}$/.test(props.backgroundColor)) {
|
|
29
|
+
console.warn(`⚠️ react-native-custom-splash: Invalid backgroundColor "${props.backgroundColor}", using default #FFFFFF`);
|
|
30
|
+
props.backgroundColor = '#FFFFFF';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Validate logoWidth
|
|
34
|
+
if (props.logoWidth && (typeof props.logoWidth !== 'number' || props.logoWidth <= 0)) {
|
|
35
|
+
console.warn(`⚠️ react-native-custom-splash: Invalid logoWidth "${props.logoWidth}", using default 150`);
|
|
36
|
+
props.logoWidth = 150;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Validate image path
|
|
40
|
+
if (props.image && typeof props.image !== 'string') {
|
|
41
|
+
console.warn(`⚠️ react-native-custom-splash: Invalid image path, must be a string`);
|
|
42
|
+
props.image = null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Validate logo path
|
|
46
|
+
if (props.logo && typeof props.logo !== 'string') {
|
|
47
|
+
console.warn(`⚠️ react-native-custom-splash: Invalid logo path, must be a string`);
|
|
48
|
+
props.logo = null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
backgroundColor: props.backgroundColor || '#FFFFFF',
|
|
53
|
+
image: props.image || null,
|
|
54
|
+
logo: props.logo || null,
|
|
55
|
+
logoWidth: props.logoWidth || 150,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
12
58
|
|
|
13
59
|
/**
|
|
14
60
|
* Get plugin configuration from app.json
|
|
@@ -23,7 +69,7 @@ function getPluginConfig(config) {
|
|
|
23
69
|
});
|
|
24
70
|
|
|
25
71
|
if (Array.isArray(splashPlugin) && splashPlugin[1]) {
|
|
26
|
-
return splashPlugin[1];
|
|
72
|
+
return validateAndNormalizeConfig(splashPlugin[1]);
|
|
27
73
|
}
|
|
28
74
|
|
|
29
75
|
// Default configuration
|
|
@@ -308,6 +354,78 @@ const withSplashScreenAndroid = (config, pluginConfig) => {
|
|
|
308
354
|
return config;
|
|
309
355
|
};
|
|
310
356
|
|
|
357
|
+
/**
|
|
358
|
+
* Create LaunchScreen.storyboard with splash configuration
|
|
359
|
+
*/
|
|
360
|
+
function createLaunchScreenStoryboard(hasImage, hasLogo, backgroundColor) {
|
|
361
|
+
const bgColor = backgroundColor.replace('#', '');
|
|
362
|
+
const r = parseInt(bgColor.substr(0, 2), 16) / 255;
|
|
363
|
+
const g = parseInt(bgColor.substr(2, 2), 16) / 255;
|
|
364
|
+
const b = parseInt(bgColor.substr(4, 2), 16) / 255;
|
|
365
|
+
|
|
366
|
+
const imageViewXML = hasImage ? `
|
|
367
|
+
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="splash_image" translatesAutoresizingMaskIntoConstraints="NO" id="splashBgImage">
|
|
368
|
+
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
|
|
369
|
+
</imageView>` : '';
|
|
370
|
+
|
|
371
|
+
const logoViewXML = hasLogo ? `
|
|
372
|
+
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="splash_logo" translatesAutoresizingMaskIntoConstraints="NO" id="splashLogo">
|
|
373
|
+
<rect key="frame" x="132" y="348" width="150" height="150"/>
|
|
374
|
+
<constraints>
|
|
375
|
+
<constraint firstAttribute="width" constant="150" id="logoWidth"/>
|
|
376
|
+
<constraint firstAttribute="height" constant="150" id="logoHeight"/>
|
|
377
|
+
</constraints>
|
|
378
|
+
</imageView>` : '';
|
|
379
|
+
|
|
380
|
+
const imageConstraints = hasImage ? `
|
|
381
|
+
<constraint firstItem="splashBgImage" firstAttribute="top" secondItem="Ze5-6b-2t3" secondAttribute="top" id="bgTop"/>
|
|
382
|
+
<constraint firstItem="splashBgImage" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" id="bgLeading"/>
|
|
383
|
+
<constraint firstItem="splashBgImage" firstAttribute="trailing" secondItem="Ze5-6b-2t3" secondAttribute="trailing" id="bgTrailing"/>
|
|
384
|
+
<constraint firstItem="splashBgImage" firstAttribute="bottom" secondItem="Ze5-6b-2t3" secondAttribute="bottom" id="bgBottom"/>` : '';
|
|
385
|
+
|
|
386
|
+
const logoConstraints = hasLogo ? `
|
|
387
|
+
<constraint firstItem="splashLogo" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="logoCenterX"/>
|
|
388
|
+
<constraint firstItem="splashLogo" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="logoCenterY"/>` : '';
|
|
389
|
+
|
|
390
|
+
const imageResources = [];
|
|
391
|
+
if (hasImage) imageResources.push('<image name="splash_image" width="1242" height="2688"/>');
|
|
392
|
+
if (hasLogo) imageResources.push('<image name="splash_logo" width="512" height="512"/>');
|
|
393
|
+
|
|
394
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
395
|
+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
|
|
396
|
+
<device id="retina6_1" orientation="portrait" appearance="light"/>
|
|
397
|
+
<dependencies>
|
|
398
|
+
<deployment identifier="iOS"/>
|
|
399
|
+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
|
|
400
|
+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
|
401
|
+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
|
402
|
+
</dependencies>
|
|
403
|
+
<scenes>
|
|
404
|
+
<!--View Controller-->
|
|
405
|
+
<scene sceneID="EHf-IW-A2E">
|
|
406
|
+
<objects>
|
|
407
|
+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
|
|
408
|
+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
|
409
|
+
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
|
|
410
|
+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
|
411
|
+
<subviews>${imageViewXML}${logoViewXML}
|
|
412
|
+
</subviews>
|
|
413
|
+
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
|
|
414
|
+
<color key="backgroundColor" red="${r}" green="${g}" blue="${b}" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
|
415
|
+
<constraints>${imageConstraints}${logoConstraints}
|
|
416
|
+
</constraints>
|
|
417
|
+
</view>
|
|
418
|
+
</viewController>
|
|
419
|
+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
|
420
|
+
</objects>
|
|
421
|
+
<point key="canvasLocation" x="53" y="375"/>
|
|
422
|
+
</scene>
|
|
423
|
+
</scenes>
|
|
424
|
+
<resources>${imageResources.join('\n ')}
|
|
425
|
+
</resources>
|
|
426
|
+
</document>`;
|
|
427
|
+
}
|
|
428
|
+
|
|
311
429
|
/**
|
|
312
430
|
* Plugin to configure iOS splash screen
|
|
313
431
|
*/
|
|
@@ -319,9 +437,12 @@ const withSplashScreenIOS = (config, pluginConfig) => {
|
|
|
319
437
|
const iosProjectPath = config.modRequest.platformProjectRoot;
|
|
320
438
|
const projectName = config.modRequest.projectName;
|
|
321
439
|
|
|
440
|
+
let hasImage = false;
|
|
441
|
+
let hasLogo = false;
|
|
442
|
+
|
|
322
443
|
// Copy images to iOS assets
|
|
323
444
|
if (pluginConfig.image) {
|
|
324
|
-
await copyImageToIOS(
|
|
445
|
+
hasImage = await copyImageToIOS(
|
|
325
446
|
projectRoot,
|
|
326
447
|
pluginConfig.image,
|
|
327
448
|
'splash_image',
|
|
@@ -331,7 +452,7 @@ const withSplashScreenIOS = (config, pluginConfig) => {
|
|
|
331
452
|
}
|
|
332
453
|
|
|
333
454
|
if (pluginConfig.logo) {
|
|
334
|
-
await copyImageToIOS(
|
|
455
|
+
hasLogo = await copyImageToIOS(
|
|
335
456
|
projectRoot,
|
|
336
457
|
pluginConfig.logo,
|
|
337
458
|
'splash_logo',
|
|
@@ -340,6 +461,23 @@ const withSplashScreenIOS = (config, pluginConfig) => {
|
|
|
340
461
|
);
|
|
341
462
|
}
|
|
342
463
|
|
|
464
|
+
// Create LaunchScreen.storyboard
|
|
465
|
+
const launchScreenPath = path.join(
|
|
466
|
+
iosProjectPath,
|
|
467
|
+
projectName,
|
|
468
|
+
'LaunchScreen.storyboard'
|
|
469
|
+
);
|
|
470
|
+
|
|
471
|
+
const storyboardContent = createLaunchScreenStoryboard(
|
|
472
|
+
hasImage,
|
|
473
|
+
hasLogo,
|
|
474
|
+
pluginConfig.backgroundColor
|
|
475
|
+
);
|
|
476
|
+
|
|
477
|
+
fs.writeFileSync(launchScreenPath, storyboardContent);
|
|
478
|
+
|
|
479
|
+
console.log('✅ iOS LaunchScreen.storyboard created with splash images!');
|
|
480
|
+
|
|
343
481
|
return config;
|
|
344
482
|
},
|
|
345
483
|
]);
|
|
@@ -349,7 +487,17 @@ const withSplashScreenIOS = (config, pluginConfig) => {
|
|
|
349
487
|
* Main plugin export
|
|
350
488
|
*/
|
|
351
489
|
module.exports = (config, props = {}) => {
|
|
352
|
-
|
|
490
|
+
// Validate the props parameter
|
|
491
|
+
let pluginConfig;
|
|
492
|
+
|
|
493
|
+
if (props && Object.keys(props).length > 0) {
|
|
494
|
+
// Props provided directly (from array syntax)
|
|
495
|
+
pluginConfig = validateAndNormalizeConfig(props);
|
|
496
|
+
} else {
|
|
497
|
+
// Try to get from config (fallback)
|
|
498
|
+
pluginConfig = getPluginConfig(config);
|
|
499
|
+
}
|
|
500
|
+
|
|
353
501
|
|
|
354
502
|
return withPlugins(config, [
|
|
355
503
|
[withSplashScreenAndroid, pluginConfig],
|