First:
Second step(Plugin Installation):
Automatic installation
react-native link react-native-splash-screen or rnpm link react-native-splash-screen
Manual installation
Android:
1: In your android/settings.gradle
file, make the following additions:
include ':react-native-splash-screen'
project(':react-native-splash-screen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-splash-screen/android')
2:在你的android/app/build中.gradle文件,将:react-native-splash-screen
项目添加为编译时依赖项:
...
dependencies {
...
compile project(':react-native-splash-screen')
}
3:更新主应用程序.java文件通过以下更改使用react-native-splash-screen
:
// react-native-splash-screen >= 0.3.1
import org.devio.rn.splashscreen.SplashScreenReactPackage;
// react-native-splash-screen < 0.3.1
import com.cboy.rn.splashscreen.SplashScreenReactPackage;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new SplashScreenReactPackage() //here
);
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
Example Code:
import React, {Component} from 'react';
import {
StyleSheet,
View,
Text,
TouchableOpacity,
Linking,
} from 'react-native'
import SplashScreen from 'react-native-splash-screen'
export default class example extends Component {
componentDidMount() {
SplashScreen.hide();
}
render() {
return (
<TouchableOpacity
style={styles.container}
onPress={(e)=> {
Linking.openURL('http://www.devio.org/');
}}
>
<View >
<Text style={styles.item}>
SplashScreen 启动屏
</Text>
<Text style={styles.item}>
@:http://www.devio.org/
</Text>
<Text style={styles.item}>
GitHub:https://github.com/crazycodeboy
</Text>
<Text style={styles.item}>
Email:crazycodeboy@gmail.com
</Text>
</View>
</TouchableOpacity>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#f3f2f2',
marginTop: 30
},
item: {
fontSize: 20,
},
line: {
flex: 1,
height: 0.3,
backgroundColor: 'darkgray',
},
})