[英]How to navigate from splash screen to Onboarding Screens?
这是 SplashScreen.js 页面
我想显示初始屏幕并在超时后不可见,然后导航到入职屏幕(滑动启动屏幕)
import React from 'react';
import { View} from 'react-native';
import LogoImage from './LogoImage.js'
import styles from '../stylesheets/SplashStylesheet.js'
const SplashScreen = ({ navigation }) => {
render() {
let that = this;
setTimeout(function(){that.setState({timePassed: true})}, 1000);
const { navigate } = this.props.navigation;
if (!this.state.timePassed){
return (
<View
style = {styles.splashScreen}>
<LogoImage/>
</View>
);
}
else{
() => navigate('Onboarding);
}
export default SplashScreen;
像这样试试
import React, { useState } from "react";
import { View, Text, StyleSheet } from "react-native";
const SplashScreen = ({ navigation }) => {
const [timePassed, setTimePassed] = useState(false);
setTimeout(function () {
setTimePassed(true);
}, 5000);
if (!timePassed) {
return (
<View style={styles.splash}>
<Text style={styles.text}>Splash Screen</Text>
</View>
);
}
alert("Navigating...");
return null;
};
const styles = StyleSheet.create({
splash: {
display: "flex",
alignItems: "center",
justifyContent: "center",
height: "100vh"
},
text: {
fontSize: 20
}
});
export default SplashScreen;
我现在在导航发生时设置警报。 您可以将其更改为重定向。
代码沙箱 => https://codesandbox.io/s/cool-violet-7lqqr?file=/src/App.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.