我的应用程序中有闪屏,5秒后它会导航到另一个屏幕。
我想要的是闪屏应该只显示在第一次时,应用程序被加载,一旦用户出来的应用程序和打开它,然后它不应该显示闪屏。
以下是我的代码
import React, { Component } from 'react';
import { View, ImageBackground, StyleSheet, BackHandler, Alert } from 'react-native';
import { Actions } from 'react-native-router-flux';
import colors from '../styles/colors';
class SplashScreen extends Component {
componentDidMount() {
// Start counting when the page is loaded
this.timeoutHandle = setTimeout(() => {
Actions.welcome()
}, 5000);
}
render() {
return (
<View style={styles.container}>
<ImageBackground
source={require('../assets/BSWH-splash.jpg')}
style={styles.backgroundImage}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
backgroundImage: {
resizeMode: 'stretch',
flex: 1,
},
logoText: {
fontSize: 34,
color: colors.white,
margin: 10,
},
});
export default SplashScreen;我使用了react-native-router-flux进行导航
请告诉我如何隐藏闪屏一旦应用程序被加载。
发布于 2019-04-22 20:21:39
这是你使用的一种变通方法。尝试使用npm包来获得完美的结果,最好的npm包是crazycodeboy/react-native-splash-screen
在这里,你可以使用Splashscreen.hide()函数在componentDidMount方法中隐藏SplashScreen。
但是如果你仍然想使用这种方法,你可以尝试
componentDidMount() {
setTimeout( () => {this.load()}, 2500);
}
load = () => {
Actions.StartOrder() //Go to StartOrder screen in 2500ms or 2.5secs
}这里,JS的setTimeout()方法将帮助您在您提到的时间间隔内重定向到特定的屏幕!!
https://stackoverflow.com/questions/55793688
复制相似问题