Skip to content
This repository was archived by the owner on Oct 7, 2021. It is now read-only.

Commit e86f16a

Browse files
Merge pull request #35 from bamlab/splashscreen-storyboard
Handle splashscreen storyboard for iOS
2 parents 997bda1 + 0de6e19 commit e86f16a

12 files changed

Lines changed: 172 additions & 144 deletions

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ You can get the list of available plugins by running `react-native -h` within yo
3333
- In your React Native project, `yarn link @bam.tech/react-native-make`
3434
- In the package.json of your React Native project, in dependencies add "@bam.tech/react-native-make" : "0.0.0"
3535

36+
## Changes in 3.0.0
37+
38+
Since 3.0.0, splashscreens for iOS are created via Xcode’s storyboard, so as to meet Apple's new requirements as of April 2020.
39+
3640
## 👉 About Bam
3741

3842
We are a 100 people company developing and designing multiplatform applications with [React Native](https://www.bam.tech/agence-react-native-paris) using the Lean & Agile methodology. To get more information on the solutions that would suit your needs, feel free to get in touch by [email](mailto://contact@bam.tech) or through or [contact form](https://www.bam.tech/en/contact)!

docs/set-splash.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ SplashScreen.hide();
1818

1919
- Use a `.png` to preserve background transparency
2020
- **3000px** as min height and/or width
21-
- For **cover** splashscreens, preserve a 1/3 padding for important content to avoid clipping a Logo or Text
21+
- For **cover** splashscreens, preserve a 1/3 padding for important content to avoid clipping a Logo or Text
2222

2323
## Resize modes
2424

@@ -32,14 +32,17 @@ We offer 3 types of Splashcreen image resize modes:
3232

3333
## Generate both splash screen
3434

35+
- open your file `myProject.xcworkspace` in XCode
36+
- right-click on your project folder > "New file..." > "Launch Screen" > "Save as: SplashScreen"
3537
- `react-native set-splash --path <path-to-image> --resize <[contain]|cover|center> --background "<background-color>"`
3638
⚠️ The path option is mandatory.
3739
The background color defaults to white
3840

3941
## Generate iOS splashscreen
4042

41-
- `react-native set-splash --platform ios --path <path-to-image> --resize <[contain]|cover|center> --background ">background-color>"`
42-
⚠️ The path option is mandatory.
43+
- open your file `myProject.xcworkspace` in XCode
44+
- right-click on your project folder > "New file..." > "Launch Screen" > "Save as: SplashScreen"
45+
- `react-native set-splash --platform ios --path <path-to-image>`
4346

4447
## Generate Android splashscreen
4548

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bam.tech/react-native-make",
3-
"version": "2.0.0",
3+
"version": "3.0.0",
44
"main": "modules/index.js",
55
"license": "MIT",
66
"repository": {

src/modules/setSplashScreen/ios/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const iosSplashImage = {
44
backgroundColor: { r: 0, g: 0, b: 0, alpha: 0 },
55
};
66

7+
const iosStoryboardName = 'SplashScreen';
8+
79
export const config = {
810
iosSplashImage,
11+
iosStoryboardName,
912
};

src/modules/setSplashScreen/ios/service.ts

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,78 +2,53 @@ import { addIosImageSetContents, EImageSetType } from '../../../services/ios/ser
22
import { generateResizedAssets } from '../../../services/image.processing';
33
import { config } from './config';
44
import { join } from 'path';
5-
import {
6-
applyPatch,
7-
applyPatchByMatchedGroups,
8-
readFile,
9-
replaceInFile,
10-
} from '../../../services/file.processing';
5+
import { replaceInFile } from '../../../services/file.processing';
116
import { getNormalizedRGBAColors } from '../../../services/color.processing';
127
import { EResizeMode } from '../../../services/type';
138
import { getIosPackageName } from '../../../utils';
149

1510
export const addIosSplashScreen = async (
1611
imageSource: string,
1712
backgroundColor: string,
18-
resizeMode?: EResizeMode
13+
resizeMode: EResizeMode
1914
) => {
2015
try {
21-
addSplashScreenXib(backgroundColor, resizeMode);
22-
configureSplashScreen();
2316
const iosSplashImageFolder = addIosImageSetContents('SplashImage', EImageSetType.IMAGE);
2417
await generateIosSplashImages(imageSource, iosSplashImageFolder);
18+
generateStoryboardFile(backgroundColor, resizeMode);
19+
setNewSplashScreenFileRefInInfoPlist();
2520
} catch (err) {
2621
console.log(err);
2722
}
2823
};
2924

30-
const configureSplashScreen = () => {
31-
const appDelegatePath = `./ios/${getIosPackageName()}/AppDelegate.m`;
32-
applyPatch(appDelegatePath, {
33-
pattern: /^(.+?)(?=\#import)/gs,
34-
patch: '#import "RNSplashScreen.h"\n',
35-
});
36-
const showRNSplashScreen = '[RNSplashScreen show];';
37-
if (!readFile(appDelegatePath).includes(showRNSplashScreen)) {
38-
applyPatchByMatchedGroups(appDelegatePath, {
39-
pattern: /(didFinishLaunchingWithOptions.*)(\n *return YES)/gs,
40-
patch: `$1\n ${showRNSplashScreen}$2`,
41-
});
42-
}
43-
};
44-
45-
const addSplashScreenXib = (
46-
backgroundColor: string,
47-
resizeMode: EResizeMode = EResizeMode.CONTAIN
48-
) => {
25+
const generateStoryboardFile = (backgroundColor: string, resizeMode: EResizeMode) => {
4926
const { red, green, blue, alpha } = getNormalizedRGBAColors(backgroundColor);
50-
5127
replaceInFile(
52-
join(__dirname, `../../../../templates/ios/LaunchScreen.${resizeMode}.xib`),
53-
`./ios/${getIosPackageName()}/Base.lproj/LaunchScreen.xib`,
28+
join(__dirname, `../../../../templates/ios/SplashScreen.${resizeMode}.storyboard`),
29+
`./ios/${config.iosStoryboardName}.storyboard`,
5430
[
5531
{
56-
oldContent: /{{background-rgba-red}}/g,
57-
newContent: `${red}`,
58-
},
59-
{
60-
oldContent: /{{background-rgba-green}}/g,
61-
newContent: `${green}`,
62-
},
63-
{
64-
oldContent: /{{background-rgba-blue}}/g,
65-
newContent: `${blue}`,
66-
},
67-
{
68-
oldContent: /{{background-rgba-alpha}}/g,
69-
newContent: `${alpha}`,
32+
oldContent: /<color.*key="backgroundColor".*\/>/g,
33+
newContent: `<color key="backgroundColor" red="${red}" green="${green}" blue="${blue}" alpha="${alpha}" colorSpace="custom" customColorSpace="sRGB"/>`,
7034
},
7135
]
7236
);
7337
};
7438

39+
const setNewSplashScreenFileRefInInfoPlist = () => {
40+
const infoPlistPath = `./ios/${getIosPackageName()}/Info.plist`;
41+
const UILaunchStoryboardNamePattern = /(<key>UILaunchStoryboardName<\/key>[ \t\n]*<string>)[a-zA-Z]+(<\/string>)/g;
42+
replaceInFile(infoPlistPath, infoPlistPath, [
43+
{
44+
oldContent: UILaunchStoryboardNamePattern,
45+
newContent: `$1${config.iosStoryboardName}$2`,
46+
},
47+
]);
48+
};
49+
7550
const generateIosSplashImages = (imageSource: string, iosSplashImageFolder: string) => {
76-
const { multipliers, size, backgroundColor } = config.iosSplashImage;
51+
const { multipliers, size } = config.iosSplashImage;
7752
return Promise.all(
7853
multipliers.map(multiplier =>
7954
generateResizedAssets(

src/services/file.processing.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ export const applyPatch = (
2424
}
2525
};
2626

27-
export const applyPatchByMatchedGroups = (
28-
path: string,
29-
patch: { patch: string; pattern: string | RegExp }
30-
) => {
31-
writeFileSync(path, readFileSync(path, 'utf8').replace(patch.pattern, patch.patch));
32-
};
33-
3427
export const replaceInFile = (
3528
sourcePath: string,
3629
destinationPath: string,

templates/ios/LaunchScreen.center.xib

Lines changed: 0 additions & 27 deletions
This file was deleted.

templates/ios/LaunchScreen.contain.xib

Lines changed: 0 additions & 29 deletions
This file was deleted.

templates/ios/LaunchScreen.cover.xib

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15705" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
3+
<device id="retina6_1" orientation="portrait" appearance="light"/>
4+
<dependencies>
5+
<deployment identifier="iOS"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15706"/>
7+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
8+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
9+
</dependencies>
10+
<scenes>
11+
<!--View Controller-->
12+
<scene sceneID="EHf-IW-A2E">
13+
<objects>
14+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
15+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
16+
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
17+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18+
<subviews>
19+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="obG-Y5-kRd">
20+
<rect key="frame" x="207" y="876" width="0.0" height="0.0"/>
21+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
22+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
23+
<nil key="highlightedColor"/>
24+
</label>
25+
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="SplashImage" translatesAutoresizingMaskIntoConstraints="NO" id="RL8-Sx-rSy">
26+
<rect key="frame" x="87" y="384" width="240" height="128"/>
27+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
28+
</imageView>
29+
</subviews>
30+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
31+
<constraints>
32+
<constraint firstItem="Bcu-3y-fUS" firstAttribute="centerX" secondItem="obG-Y5-kRd" secondAttribute="centerX" id="5cz-MP-9tL"/>
33+
</constraints>
34+
<viewLayoutGuide key="safeArea" id="Bcu-3y-fUS"/>
35+
</view>
36+
</viewController>
37+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
38+
</objects>
39+
<point key="canvasLocation" x="53" y="375"/>
40+
</scene>
41+
</scenes>
42+
<resources>
43+
<image name="SplashImage" width="896" height="896"/>
44+
</resources>
45+
</document>

0 commit comments

Comments
 (0)