react-native-custom-splash 3.0.1 → 3.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-custom-splash",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
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",
@@ -2,18 +2,11 @@ const { withDangerousMod } = require('@expo/config-plugins');
2
2
  const path = require('path');
3
3
  const fs = require('fs');
4
4
 
5
- /**
6
- * FINAL WORKING iOS Splash - Xcode Compatible
7
- */
8
5
  function withForcediOSSplash(config, pluginConfig) {
9
- // Disable Expo's splash
10
6
  config = {
11
7
  ...config,
12
8
  splash: undefined,
13
- ios: {
14
- ...config.ios,
15
- splash: undefined
16
- }
9
+ ios: { ...config.ios, splash: undefined }
17
10
  };
18
11
 
19
12
  return withDangerousMod(config, [
@@ -23,29 +16,28 @@ function withForcediOSSplash(config, pluginConfig) {
23
16
  const iosPath = config.modRequest.platformProjectRoot;
24
17
  const projectName = config.modRequest.projectName;
25
18
 
26
- console.log('\nšŸ”„ SETTING UP CUSTOM SPLASH...\n');
19
+ console.log('\nšŸ”„ Setting up splash screen...\n');
27
20
 
28
- // Delete ALL old splash files
29
- const filesToDelete = [
30
- path.join(iosPath, projectName, 'SplashScreen.storyboard'),
31
- path.join(iosPath, projectName, 'LaunchScreen.storyboard'),
32
- path.join(iosPath, projectName, 'Images.xcassets', 'SplashScreenLegacy.imageset'),
33
- path.join(iosPath, projectName, 'Images.xcassets', 'SplashScreen.imageset'),
34
- path.join(iosPath, projectName, 'Images.xcassets', 'SplashScreenBackground.imageset'),
21
+ // Delete old files
22
+ const toDelete = [
23
+ 'SplashScreen.storyboard',
24
+ 'LaunchScreen.storyboard',
25
+ 'Images.xcassets/SplashScreenLegacy.imageset',
26
+ 'Images.xcassets/SplashScreen.imageset',
27
+ 'Images.xcassets/SplashScreenBackground.imageset',
35
28
  ];
36
29
 
37
- filesToDelete.forEach(filePath => {
30
+ toDelete.forEach(file => {
31
+ const fullPath = path.join(iosPath, projectName, file);
38
32
  try {
39
- if (fs.existsSync(filePath)) {
40
- if (fs.lstatSync(filePath).isDirectory()) {
41
- fs.rmSync(filePath, { recursive: true, force: true });
33
+ if (fs.existsSync(fullPath)) {
34
+ if (fs.lstatSync(fullPath).isDirectory()) {
35
+ fs.rmSync(fullPath, { recursive: true, force: true });
42
36
  } else {
43
- fs.unlinkSync(filePath);
37
+ fs.unlinkSync(fullPath);
44
38
  }
45
39
  }
46
- } catch (e) {
47
- // Ignore
48
- }
40
+ } catch (e) { }
49
41
  });
50
42
 
51
43
  // Update Info.plist
@@ -56,184 +48,73 @@ function withForcediOSSplash(config, pluginConfig) {
56
48
  plist = plist.replace(/<key>UILaunchScreen<\/key>[\s\S]*?<\/dict>/g, '');
57
49
 
58
50
  if (!plist.includes('UILaunchStoryboardName')) {
59
- plist = plist.replace(
60
- '</dict>\n</plist>',
61
- '\t<key>UILaunchStoryboardName</key>\n\t<string>LaunchScreen</string>\n</dict>\n</plist>'
62
- );
51
+ plist = plist.replace('</dict>\n</plist>', '\t<key>UILaunchStoryboardName</key>\n\t<string>LaunchScreen</string>\n</dict>\n</plist>');
63
52
  }
64
53
 
65
54
  fs.writeFileSync(plistPath, plist);
66
- console.log('āœ… Info.plist updated');
67
55
  }
68
56
 
69
57
  const assetsPath = path.join(iosPath, projectName, 'Images.xcassets');
70
58
  let hasImage = false;
71
59
  let hasLogo = false;
72
60
 
73
- // Copy splash_image
61
+ // Copy background image
74
62
  if (pluginConfig.image) {
75
- const srcImage = path.join(projectRoot, pluginConfig.image);
76
- if (fs.existsSync(srcImage)) {
77
- const destDir = path.join(assetsPath, 'SplashImage.imageset');
63
+ const srcPath = path.join(projectRoot, pluginConfig.image);
64
+ if (fs.existsSync(srcPath)) {
65
+ const imagesetDir = path.join(assetsPath, 'SplashBg.imageset');
78
66
 
79
- if (fs.existsSync(destDir)) {
80
- fs.rmSync(destDir, { recursive: true, force: true });
81
- }
82
- fs.mkdirSync(destDir, { recursive: true });
67
+ if (fs.existsSync(imagesetDir)) fs.rmSync(imagesetDir, { recursive: true, force: true });
68
+ fs.mkdirSync(imagesetDir, { recursive: true });
83
69
 
84
- // Copy image
85
- fs.copyFileSync(srcImage, path.join(destDir, 'splash.png'));
70
+ fs.copyFileSync(srcPath, path.join(imagesetDir, 'image.png'));
86
71
 
87
- // Create Contents.json
88
- const contents = {
72
+ fs.writeFileSync(path.join(imagesetDir, 'Contents.json'), JSON.stringify({
89
73
  images: [
90
- {
91
- filename: 'splash.png',
92
- idiom: 'universal',
93
- scale: '1x'
94
- },
95
- {
96
- filename: 'splash.png',
97
- idiom: 'universal',
98
- scale: '2x'
99
- },
100
- {
101
- filename: 'splash.png',
102
- idiom: 'universal',
103
- scale: '3x'
104
- }
74
+ { filename: 'image.png', idiom: 'universal', scale: '1x' },
75
+ { filename: 'image.png', idiom: 'universal', scale: '2x' },
76
+ { filename: 'image.png', idiom: 'universal', scale: '3x' }
105
77
  ],
106
- info: {
107
- author: 'xcode',
108
- version: 1
109
- }
110
- };
111
-
112
- fs.writeFileSync(
113
- path.join(destDir, 'Contents.json'),
114
- JSON.stringify(contents, null, 2)
115
- );
78
+ info: { author: 'xcode', version: 1 }
79
+ }, null, 2));
116
80
 
117
81
  hasImage = true;
118
- console.log('āœ… Background image copied: SplashImage');
82
+ console.log('āœ… Background copied');
119
83
  }
120
84
  }
121
85
 
122
- // Copy splash_logo
86
+ // Copy logo
123
87
  if (pluginConfig.logo) {
124
- const srcLogo = path.join(projectRoot, pluginConfig.logo);
125
- if (fs.existsSync(srcLogo)) {
126
- const destDir = path.join(assetsPath, 'SplashLogo.imageset');
88
+ const srcPath = path.join(projectRoot, pluginConfig.logo);
89
+ if (fs.existsSync(srcPath)) {
90
+ const imagesetDir = path.join(assetsPath, 'SplashIcon.imageset');
127
91
 
128
- if (fs.existsSync(destDir)) {
129
- fs.rmSync(destDir, { recursive: true, force: true });
130
- }
131
- fs.mkdirSync(destDir, { recursive: true });
92
+ if (fs.existsSync(imagesetDir)) fs.rmSync(imagesetDir, { recursive: true, force: true });
93
+ fs.mkdirSync(imagesetDir, { recursive: true });
132
94
 
133
- // Copy logo
134
- fs.copyFileSync(srcLogo, path.join(destDir, 'logo.png'));
95
+ fs.copyFileSync(srcPath, path.join(imagesetDir, 'icon.png'));
135
96
 
136
- // Create Contents.json
137
- const contents = {
97
+ fs.writeFileSync(path.join(imagesetDir, 'Contents.json'), JSON.stringify({
138
98
  images: [
139
- {
140
- filename: 'logo.png',
141
- idiom: 'universal',
142
- scale: '1x'
143
- },
144
- {
145
- filename: 'logo.png',
146
- idiom: 'universal',
147
- scale: '2x'
148
- },
149
- {
150
- filename: 'logo.png',
151
- idiom: 'universal',
152
- scale: '3x'
153
- }
99
+ { filename: 'icon.png', idiom: 'universal', scale: '1x' },
100
+ { filename: 'icon.png', idiom: 'universal', scale: '2x' },
101
+ { filename: 'icon.png', idiom: 'universal', scale: '3x' }
154
102
  ],
155
- info: {
156
- author: 'xcode',
157
- version: 1
158
- }
159
- };
160
-
161
- fs.writeFileSync(
162
- path.join(destDir, 'Contents.json'),
163
- JSON.stringify(contents, null, 2)
164
- );
103
+ info: { author: 'xcode', version: 1 }
104
+ }, null, 2));
165
105
 
166
106
  hasLogo = true;
167
- console.log('āœ… Logo image copied: SplashLogo');
107
+ console.log('āœ… Logo copied');
168
108
  }
169
109
  }
170
110
 
171
- // Create LaunchScreen.storyboard
172
- const storyboard = createXcodeStoryboard(hasImage, hasLogo, pluginConfig.backgroundColor);
173
- const storyboardPath = path.join(iosPath, projectName, 'LaunchScreen.storyboard');
174
-
175
- if (fs.existsSync(storyboardPath)) {
176
- fs.unlinkSync(storyboardPath);
177
- }
178
-
179
- fs.writeFileSync(storyboardPath, storyboard);
180
-
181
- console.log('āœ… LaunchScreen.storyboard created!');
182
- console.log(` Background: ${hasImage ? 'SplashImage āœ“' : 'Color only'}`);
183
- console.log(` Logo: ${hasLogo ? 'SplashLogo āœ“' : 'None'}`);
184
- console.log(` Color: ${pluginConfig.backgroundColor}\n`);
185
-
186
- return config;
187
- },
188
- ]);
189
- }
190
-
191
- function createXcodeStoryboard(hasImage, hasLogo, bgColor) {
192
- const color = bgColor.replace('#', '');
193
- const r = parseInt(color.substr(0, 2), 16) / 255;
194
- const g = parseInt(color.substr(2, 2), 16) / 255;
195
- const b = parseInt(color.substr(4, 2), 16) / 255;
196
-
197
- // Build subviews
198
- let subviews = '';
199
- let constraints = '';
200
- let resources = '';
201
-
202
- if (hasImage) {
203
- subviews += `
204
- <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="SplashImage" translatesAutoresizingMaskIntoConstraints="NO" id="splash-bg">
205
- <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
206
- </imageView>`;
207
-
208
- constraints += `
209
- <constraint firstItem="splash-bg" firstAttribute="top" secondItem="Ze5-6b-2t3" secondAttribute="top" id="bg-top"/>
210
- <constraint firstItem="splash-bg" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading" id="bg-leading"/>
211
- <constraint firstItem="splash-bg" firstAttribute="trailing" secondItem="Ze5-6b-2t3" secondAttribute="trailing" id="bg-trailing"/>
212
- <constraint firstItem="splash-bg" firstAttribute="bottom" secondItem="Ze5-6b-2t3" secondAttribute="bottom" id="bg-bottom"/>`;
213
-
214
- resources += `
215
- <image name="SplashImage" width="1242" height="2688"/>`;
216
- }
111
+ // Create storyboard
112
+ const color = pluginConfig.backgroundColor.replace('#', '');
113
+ const r = parseInt(color.substr(0, 2), 16) / 255;
114
+ const g = parseInt(color.substr(2, 2), 16) / 255;
115
+ const b = parseInt(color.substr(4, 2), 16) / 255;
217
116
 
218
- if (hasLogo) {
219
- subviews += `
220
- <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="SplashLogo" translatesAutoresizingMaskIntoConstraints="NO" id="splash-logo">
221
- <rect key="frame" x="132" y="373" width="150" height="150"/>
222
- <constraints>
223
- <constraint firstAttribute="width" constant="150" id="logo-width"/>
224
- <constraint firstAttribute="height" constant="150" id="logo-height"/>
225
- </constraints>
226
- </imageView>`;
227
-
228
- constraints += `
229
- <constraint firstItem="splash-logo" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="logo-centerx"/>
230
- <constraint firstItem="splash-logo" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="logo-centery"/>`;
231
-
232
- resources += `
233
- <image name="SplashLogo" width="512" height="512"/>`;
234
- }
235
-
236
- return `<?xml version="1.0" encoding="UTF-8"?>
117
+ const storyboard = `<?xml version="1.0" encoding="UTF-8"?>
237
118
  <document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
238
119
  <device id="retina6_1" orientation="portrait" appearance="light"/>
239
120
  <dependencies>
@@ -243,18 +124,33 @@ function createXcodeStoryboard(hasImage, hasLogo, bgColor) {
243
124
  <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
244
125
  </dependencies>
245
126
  <scenes>
246
- <!--View Controller-->
247
127
  <scene sceneID="EHf-IW-A2E">
248
128
  <objects>
249
129
  <viewController id="01J-lp-oVM" sceneMemberID="viewController">
250
130
  <view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
251
131
  <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
252
132
  <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
253
- <subviews>${subviews}
133
+ <subviews>${hasImage ? `
134
+ <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="SplashBg" translatesAutoresizingMaskIntoConstraints="NO" id="bg-img">
135
+ <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
136
+ </imageView>` : ''}${hasLogo ? `
137
+ <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="SplashIcon" translatesAutoresizingMaskIntoConstraints="NO" id="logo-img">
138
+ <rect key="frame" x="132" y="373" width="150" height="150"/>
139
+ <constraints>
140
+ <constraint firstAttribute="width" constant="150" id="w"/>
141
+ <constraint firstAttribute="height" constant="150" id="h"/>
142
+ </constraints>
143
+ </imageView>` : ''}
254
144
  </subviews>
255
145
  <viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
256
146
  <color key="backgroundColor" red="${r}" green="${g}" blue="${b}" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
257
- <constraints>${constraints}
147
+ <constraints>${hasImage ? `
148
+ <constraint firstItem="bg-img" firstAttribute="top" secondItem="Ze5-6b-2t3" secondAttribute="top"/>
149
+ <constraint firstItem="bg-img" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leading"/>
150
+ <constraint firstItem="bg-img" firstAttribute="trailing" secondItem="Ze5-6b-2t3" secondAttribute="trailing"/>
151
+ <constraint firstItem="bg-img" firstAttribute="bottom" secondItem="Ze5-6b-2t3" secondAttribute="bottom"/>` : ''}${hasLogo ? `
152
+ <constraint firstItem="logo-img" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX"/>
153
+ <constraint firstItem="logo-img" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY"/>` : ''}
258
154
  </constraints>
259
155
  </view>
260
156
  </viewController>
@@ -263,9 +159,23 @@ function createXcodeStoryboard(hasImage, hasLogo, bgColor) {
263
159
  <point key="canvasLocation" x="53" y="375"/>
264
160
  </scene>
265
161
  </scenes>
266
- <resources>${resources}
162
+ <resources>${hasImage ? `
163
+ <image name="SplashBg" width="1242" height="2688"/>` : ''}${hasLogo ? `
164
+ <image name="SplashIcon" width="512" height="512"/>` : ''}
267
165
  </resources>
268
166
  </document>`;
167
+
168
+ const storyboardPath = path.join(iosPath, projectName, 'LaunchScreen.storyboard');
169
+ if (fs.existsSync(storyboardPath)) fs.unlinkSync(storyboardPath);
170
+ fs.writeFileSync(storyboardPath, storyboard);
171
+
172
+ console.log('āœ… LaunchScreen.storyboard created!');
173
+ console.log(` Background: ${hasImage ? 'YES' : 'NO'}`);
174
+ console.log(` Logo: ${hasLogo ? 'YES' : 'NO'}\n`);
175
+
176
+ return config;
177
+ },
178
+ ]);
269
179
  }
270
180
 
271
181
  module.exports = withForcediOSSplash;