-
Notifications
You must be signed in to change notification settings - Fork 14
/
splashScreenSetup.js
46 lines (43 loc) · 1.7 KB
/
splashScreenSetup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module.exports = function splashScreenSetup() {
// Update MainActivity
const mainActivityContent = this.fs.read(
`${this.projectName}/android/app/src/main/java/com/${this.projectName}/MainActivity.java`
);
let updatedMainActivityContent = mainActivityContent.replace(
'import com.facebook.react.ReactActivity;',
'import android.os.Bundle;\nimport org.devio.rn.splashscreen.SplashScreen;\nimport com.facebook.react.ReactActivity;'
);
updatedMainActivityContent = updatedMainActivityContent.replace(
'public class MainActivity extends ReactActivity {',
'public class MainActivity extends ReactActivity {\n\t@Override\n\tprotected void onCreate(Bundle savedInstanceState) {\n\t\tSplashScreen.show(this);\n\t\tsuper.onCreate(savedInstanceState);\n\t}'
);
this.fs.write(
`${this.projectName}/android/app/src/main/java/com/${this.projectName}/MainActivity.java`,
updatedMainActivityContent
);
// Update AppDelegate
const appDelegateContent = this.fs.read(`${this.projectName}/ios/${this.projectName}/AppDelegate.m`);
let updatedAppDelegateContent = appDelegateContent.replace(
'#import <React/RCTRootView.h>',
'#import <React/RCTRootView.h>\n#import "RNSplashScreen.h"'
);
updatedAppDelegateContent = updatedAppDelegateContent.replace(
'return YES;',
'[RNSplashScreen show];\n\treturn YES;'
);
this.fs.write(`${this.projectName}/ios/${this.projectName}/AppDelegate.m`, updatedAppDelegateContent);
// Add launch_screen.xml
this.fs.copy(
this.templatePath('android', 'launch_screen.xml'),
this.destinationPath(
this.projectName,
'android',
'app',
'src',
'main',
'res',
'layout',
'launch_screen.xml'
)
);
};