如何在应用程序加载到反应本机后隐藏启动画面 反应本机 使用反应本机路由器通量



我的应用程序中有启动画面,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;

我已经使用反应原生路由器通量进行导航

请帮助我如何在加载应用程序后隐藏初始屏幕。

这是您使用的解决方法。尝试使用 npm 包来获得完美的结果,最好的 npm 包是疯狂的 codeboy/react-native-splash-screen

在那里,您可以使用Splashscreen.hide()函数隐藏组件DidMount方法中的SplashScreen。

但是,如果您仍然想使用此方法,则可以尝试

componentDidMount() {
setTimeout( () => {this.load()}, 2500);       
}
load = () => {
Actions.StartOrder()   //Go to StartOrder screen in 2500ms or 2.5secs
}

在这里,JS的setTimeout()方法将帮助您在提到的间隔内重定向到特定屏幕!

最新更新