我是反应原生的新手,我不知道如何在5秒后改变页面.
我创建了一个android.index.js文件,将导航到LandingPage.js.我想要做的是,当加载LandingPage时,它将等待5秒然后重定向/导航到另一个页面.
index.android.js
export default class DefaultProject extends Component {
render() {
return (
<Navigator
renderScene={(route, navigator) =>
<LandingPage/>
}
/>
)
Run Code Online (Sandbox Code Playgroud)
LandingPage.js
export default class LandingPage extends Component {
render() {
return (
<Image source={require('./images/event3.jpeg')}
style={styles.container} />
//How to redirect to another page from here after 5 secs?
);
}
}
Run Code Online (Sandbox Code Playgroud)
mar*_*oyo 14
您可以使用简单的方法setTimeout,就像在标准JS设置中一样:
export default class LandingPage extends Component {
componentDidMount(){
// Start counting when the page is loaded
this.timeoutHandle = setTimeout(()=>{
// Add your logic for the transition
}, 5000);
}
componentWillUnmount(){
clearTimeout(this.timeoutHandle); // This is just necessary in the case that the screen is closed before the timeout fires, otherwise it would cause a memory leak that would trigger the transition regardless, breaking the user experience.
}
render() {
return (
<Image source={require('./images/event3.jpeg')}
style={styles.container} />
//How to redirect to another page from here after 5 secs?
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9611 次 |
| 最近记录: |