react-native-custom-splash 3.0.0 → 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.0",
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",
@@ -1,23 +1,14 @@
1
- const { withDangerousMod, withPlugins } = require('@expo/config-plugins');
1
+ const { withDangerousMod } = require('@expo/config-plugins');
2
2
  const path = require('path');
3
3
  const fs = require('fs');
4
4
 
5
- /**
6
- * ULTIMATE iOS Splash Fix - Forceful & Complete
7
- * This DISABLES Expo's splash and FORCES user images
8
- */
9
5
  function withForcediOSSplash(config, pluginConfig) {
10
- // STEP 1: Disable Expo's default splash completely
11
6
  config = {
12
7
  ...config,
13
- splash: undefined, // Remove Expo splash config
14
- ios: {
15
- ...config.ios,
16
- splash: undefined // Remove iOS splash config
17
- }
8
+ splash: undefined,
9
+ ios: { ...config.ios, splash: undefined }
18
10
  };
19
11
 
20
- // STEP 2: Use dangerousMod to forcefully set everything
21
12
  return withDangerousMod(config, [
22
13
  'ios',
23
14
  async (config) => {
@@ -25,218 +16,166 @@ function withForcediOSSplash(config, pluginConfig) {
25
16
  const iosPath = config.modRequest.platformProjectRoot;
26
17
  const projectName = config.modRequest.projectName;
27
18
 
28
- console.log('\nļæ½ FORCING CUSTOM SPLASH SCREEN (FINAL FIX)...\n');
19
+ console.log('\nšŸ”„ Setting up splash screen...\n');
29
20
 
30
- // Wait a bit to ensure Expo is done
31
- await new Promise(resolve => setTimeout(resolve, 100));
32
-
33
- // NUCLEAR OPTION: Delete EVERYTHING splash-related
34
- const filesToDelete = [
35
- path.join(iosPath, projectName, 'SplashScreen.storyboard'),
36
- path.join(iosPath, projectName, 'LaunchScreen.storyboard'),
37
- path.join(iosPath, projectName, 'Images.xcassets', 'SplashScreenLegacy.imageset'),
38
- path.join(iosPath, projectName, 'Images.xcassets', 'SplashScreen.imageset'),
39
- 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',
40
28
  ];
41
29
 
42
- filesToDelete.forEach(filePath => {
30
+ toDelete.forEach(file => {
31
+ const fullPath = path.join(iosPath, projectName, file);
43
32
  try {
44
- if (fs.existsSync(filePath)) {
45
- if (fs.lstatSync(filePath).isDirectory()) {
46
- 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 });
47
36
  } else {
48
- fs.unlinkSync(filePath);
37
+ fs.unlinkSync(fullPath);
49
38
  }
50
- console.log('šŸ—‘ļø Deleted:', path.basename(filePath));
51
39
  }
52
- } catch (e) {
53
- // Ignore errors
54
- }
40
+ } catch (e) { }
55
41
  });
56
42
 
57
- // Force update Info.plist
43
+ // Update Info.plist
58
44
  const plistPath = path.join(iosPath, projectName, 'Info.plist');
59
45
  if (fs.existsSync(plistPath)) {
60
46
  let plist = fs.readFileSync(plistPath, 'utf8');
61
-
62
- // Remove ALL launch screen configurations
63
47
  plist = plist.replace(/<key>UILaunchStoryboardName<\/key>\s*<string>.*?<\/string>/g, '');
64
48
  plist = plist.replace(/<key>UILaunchScreen<\/key>[\s\S]*?<\/dict>/g, '');
65
49
 
66
- // Add our LaunchScreen BEFORE closing dict
67
50
  if (!plist.includes('UILaunchStoryboardName')) {
68
- plist = plist.replace(
69
- '</dict>\n</plist>',
70
- '\t<key>UILaunchStoryboardName</key>\n\t<string>LaunchScreen</string>\n</dict>\n</plist>'
71
- );
51
+ plist = plist.replace('</dict>\n</plist>', '\t<key>UILaunchStoryboardName</key>\n\t<string>LaunchScreen</string>\n</dict>\n</plist>');
72
52
  }
73
53
 
74
54
  fs.writeFileSync(plistPath, plist);
75
- console.log('āœ… Info.plist FORCED');
76
55
  }
77
56
 
78
- // Copy user images with FORCE
79
57
  const assetsPath = path.join(iosPath, projectName, 'Images.xcassets');
80
58
  let hasImage = false;
81
59
  let hasLogo = false;
82
60
 
61
+ // Copy background image
83
62
  if (pluginConfig.image) {
84
- const srcImage = path.join(projectRoot, pluginConfig.image);
85
- if (fs.existsSync(srcImage)) {
86
- const destDir = path.join(assetsPath, 'splash_image.imageset');
63
+ const srcPath = path.join(projectRoot, pluginConfig.image);
64
+ if (fs.existsSync(srcPath)) {
65
+ const imagesetDir = path.join(assetsPath, 'SplashBg.imageset');
87
66
 
88
- // Force delete and recreate
89
- if (fs.existsSync(destDir)) {
90
- fs.rmSync(destDir, { recursive: true, force: true });
91
- }
92
- fs.mkdirSync(destDir, { recursive: true });
93
-
94
- // Copy for all scales
95
- ['', '@2x', '@3x'].forEach(scale => {
96
- fs.copyFileSync(srcImage, path.join(destDir, `splash_image${scale}.png`));
97
- });
98
-
99
- // Force Contents.json
100
- fs.writeFileSync(
101
- path.join(destDir, 'Contents.json'),
102
- JSON.stringify({
103
- images: [
104
- { idiom: 'universal', filename: 'splash_image.png', scale: '1x' },
105
- { idiom: 'universal', filename: 'splash_image@2x.png', scale: '2x' },
106
- { idiom: 'universal', filename: 'splash_image@3x.png', scale: '3x' }
107
- ],
108
- info: { author: 'xcode', version: 1 }
109
- }, null, 2)
110
- );
67
+ if (fs.existsSync(imagesetDir)) fs.rmSync(imagesetDir, { recursive: true, force: true });
68
+ fs.mkdirSync(imagesetDir, { recursive: true });
69
+
70
+ fs.copyFileSync(srcPath, path.join(imagesetDir, 'image.png'));
71
+
72
+ fs.writeFileSync(path.join(imagesetDir, 'Contents.json'), JSON.stringify({
73
+ images: [
74
+ { filename: 'image.png', idiom: 'universal', scale: '1x' },
75
+ { filename: 'image.png', idiom: 'universal', scale: '2x' },
76
+ { filename: 'image.png', idiom: 'universal', scale: '3x' }
77
+ ],
78
+ info: { author: 'xcode', version: 1 }
79
+ }, null, 2));
111
80
 
112
81
  hasImage = true;
113
- console.log('āœ… FORCED: splash_image');
82
+ console.log('āœ… Background copied');
114
83
  }
115
84
  }
116
85
 
86
+ // Copy logo
117
87
  if (pluginConfig.logo) {
118
- const srcLogo = path.join(projectRoot, pluginConfig.logo);
119
- if (fs.existsSync(srcLogo)) {
120
- const destDir = path.join(assetsPath, 'splash_logo.imageset');
88
+ const srcPath = path.join(projectRoot, pluginConfig.logo);
89
+ if (fs.existsSync(srcPath)) {
90
+ const imagesetDir = path.join(assetsPath, 'SplashIcon.imageset');
121
91
 
122
- // Force delete and recreate
123
- if (fs.existsSync(destDir)) {
124
- fs.rmSync(destDir, { recursive: true, force: true });
125
- }
126
- fs.mkdirSync(destDir, { recursive: true });
127
-
128
- // Copy for all scales
129
- ['', '@2x', '@3x'].forEach(scale => {
130
- fs.copyFileSync(srcLogo, path.join(destDir, `splash_logo${scale}.png`));
131
- });
132
-
133
- // Force Contents.json
134
- fs.writeFileSync(
135
- path.join(destDir, 'Contents.json'),
136
- JSON.stringify({
137
- images: [
138
- { idiom: 'universal', filename: 'splash_logo.png', scale: '1x' },
139
- { idiom: 'universal', filename: 'splash_logo@2x.png', scale: '2x' },
140
- { idiom: 'universal', filename: 'splash_logo@3x.png', scale: '3x' }
141
- ],
142
- info: { author: 'xcode', version: 1 }
143
- }, null, 2)
144
- );
92
+ if (fs.existsSync(imagesetDir)) fs.rmSync(imagesetDir, { recursive: true, force: true });
93
+ fs.mkdirSync(imagesetDir, { recursive: true });
145
94
 
146
- hasLogo = true;
147
- console.log('āœ… FORCED: splash_logo');
148
- }
149
- }
95
+ fs.copyFileSync(srcPath, path.join(imagesetDir, 'icon.png'));
150
96
 
151
- // FORCE create LaunchScreen.storyboard
152
- const storyboard = createForcedStoryboard(hasImage, hasLogo, pluginConfig.backgroundColor);
153
- const storyboardPath = path.join(iosPath, projectName, 'LaunchScreen.storyboard');
97
+ fs.writeFileSync(path.join(imagesetDir, 'Contents.json'), JSON.stringify({
98
+ images: [
99
+ { filename: 'icon.png', idiom: 'universal', scale: '1x' },
100
+ { filename: 'icon.png', idiom: 'universal', scale: '2x' },
101
+ { filename: 'icon.png', idiom: 'universal', scale: '3x' }
102
+ ],
103
+ info: { author: 'xcode', version: 1 }
104
+ }, null, 2));
154
105
 
155
- // Delete if exists
156
- if (fs.existsSync(storyboardPath)) {
157
- fs.unlinkSync(storyboardPath);
106
+ hasLogo = true;
107
+ console.log('āœ… Logo copied');
108
+ }
158
109
  }
159
110
 
160
- // Write with force
161
- fs.writeFileSync(storyboardPath, storyboard, { flag: 'w' });
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;
162
116
 
163
- console.log('āœ… FORCED: LaunchScreen.storyboard');
164
- console.log(` šŸ–¼ļø Background: ${hasImage ? 'splash_image' : 'color'}`);
165
- console.log(` šŸŽØ Logo: ${hasLogo ? 'splash_logo' : 'none'}`);
166
- console.log(` 🌈 Color: ${pluginConfig.backgroundColor}`);
167
- console.log('\nāœ… CUSTOM SPLASH FORCED SUCCESSFULLY!\n');
168
-
169
- return config;
170
- },
171
- ]);
172
- }
173
-
174
- function createForcedStoryboard(hasImage, hasLogo, bgColor) {
175
- const color = bgColor.replace('#', '');
176
- const r = parseInt(color.substr(0, 2), 16) / 255;
177
- const g = parseInt(color.substr(2, 2), 16) / 255;
178
- const b = parseInt(color.substr(4, 2), 16) / 255;
179
-
180
- const bgImage = hasImage ? `
181
- <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="splash_image" translatesAutoresizingMaskIntoConstraints="NO" id="BG">
182
- <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
183
- </imageView>` : '';
184
-
185
- const logoImage = hasLogo ? `
186
- <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="splash_logo" translatesAutoresizingMaskIntoConstraints="NO" id="LOGO">
187
- <rect key="frame" x="132" y="348" width="150" height="150"/>
188
- <constraints>
189
- <constraint firstAttribute="width" constant="150" id="LW"/>
190
- <constraint firstAttribute="height" constant="150" id="LH"/>
191
- </constraints>
192
- </imageView>` : '';
193
-
194
- const bgConstraints = hasImage ? `
195
- <constraint firstItem="BG" firstAttribute="top" secondItem="V" secondAttribute="top" id="BT"/>
196
- <constraint firstItem="BG" firstAttribute="leading" secondItem="V" secondAttribute="leading" id="BL"/>
197
- <constraint firstItem="BG" firstAttribute="trailing" secondItem="V" secondAttribute="trailing" id="BR"/>
198
- <constraint firstItem="BG" firstAttribute="bottom" secondItem="V" secondAttribute="bottom" id="BB"/>` : '';
199
-
200
- const logoConstraints = hasLogo ? `
201
- <constraint firstItem="LOGO" firstAttribute="centerX" secondItem="V" secondAttribute="centerX" id="LX"/>
202
- <constraint firstItem="LOGO" firstAttribute="centerY" secondItem="V" secondAttribute="centerY" id="LY"/>` : '';
203
-
204
- const resources = [];
205
- if (hasImage) resources.push(' <image name="splash_image" width="1242" height="2688"/>');
206
- if (hasLogo) resources.push(' <image name="splash_logo" width="512" height="512"/>');
207
-
208
- return `<?xml version="1.0" encoding="UTF-8"?>
209
- <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="VC">
117
+ const storyboard = `<?xml version="1.0" encoding="UTF-8"?>
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">
210
119
  <device id="retina6_1" orientation="portrait" appearance="light"/>
211
120
  <dependencies>
212
121
  <deployment identifier="iOS"/>
213
- <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
122
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21679"/>
214
123
  <capability name="Safe area layout guides" minToolsVersion="9.0"/>
215
124
  <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
216
125
  </dependencies>
217
126
  <scenes>
218
- <scene sceneID="SC">
127
+ <scene sceneID="EHf-IW-A2E">
219
128
  <objects>
220
- <viewController id="VC" sceneMemberID="viewController">
221
- <view key="view" contentMode="scaleToFill" id="V">
129
+ <viewController id="01J-lp-oVM" sceneMemberID="viewController">
130
+ <view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
222
131
  <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
223
132
  <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
224
- <subviews>${bgImage}${logoImage}
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>` : ''}
225
144
  </subviews>
226
- <viewLayoutGuide key="safeArea" id="SA"/>
145
+ <viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
227
146
  <color key="backgroundColor" red="${r}" green="${g}" blue="${b}" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
228
- <constraints>${bgConstraints}${logoConstraints}
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"/>` : ''}
229
154
  </constraints>
230
155
  </view>
231
156
  </viewController>
232
- <placeholder placeholderIdentifier="IBFirstResponder" id="FR" userLabel="First Responder" sceneMemberID="firstResponder"/>
157
+ <placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
233
158
  </objects>
234
159
  <point key="canvasLocation" x="53" y="375"/>
235
160
  </scene>
236
161
  </scenes>
237
- <resources>${resources.join('\n')}
162
+ <resources>${hasImage ? `
163
+ <image name="SplashBg" width="1242" height="2688"/>` : ''}${hasLogo ? `
164
+ <image name="SplashIcon" width="512" height="512"/>` : ''}
238
165
  </resources>
239
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
+ ]);
240
179
  }
241
180
 
242
181
  module.exports = withForcediOSSplash;