React Native - 在 x 秒后更改屏幕 [英] React native - Change screen after x seconds
本文介绍了React Native - 在 x 秒后更改屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个我无法解决的问题.
I have a problem that I haven't been able to solve.
在我的 React 原生应用程序中,我想在开始时显示一个欢迎屏幕.然后 5 秒后关闭它,并显示另一个.两者都是两个完全不同的屏幕,无需保留返回"箭头.
In my React native application, I would like to display a welcome screen at the start. Then 5 seconds later just close it, and display another one. Both are 2 entirely different screens, no need to keep the "come back" arrow.
我已经搜索了几个小时,但我还没有找到方法.
I have been searching for hours, but I haven't found out how to do it.
这是我现在的代码:
import Defis from './components/defis'
import Quote from './components/quote'
export default class Betty extends Component {
componentDidMount(){
// Start counting when the page is loaded
this.timeoutHandle = setTimeout(()=>{
// Add your logic for the transition
this.props.navigation.navigate('Defis') // what to push here?
}, 5000);
}
componentWillUnmount(){
clearTimeout(this.timeoutHandle);
}
render() {
return (
<Quote/>
);
}
}
有人知道怎么做吗?
我无法使用 Navigator.push
,而且 Navigator 似乎已被弃用.
I'm not able to use Navigator.push
, moreover Navigator seems deprecated.
推荐答案
不使用任何导航器就可以解决您的问题
Not Using any navigator this can solve your problem
import Defis from './components/defis'
import Quote from './components/quote'
export default class Betty extends Component {
constructor(props){
super(props)
this.state = {
component : <Quote />
}
}
componentDidMount(){
// Start counting when the page is loaded
this.timeoutHandle = setTimeout(()=>{
// Add your logic for the transition
this.setState({ component: <Defis /> })
}, 5000);
}
componentWillUnmount(){
clearTimeout(this.timeoutHandle);
}
render() {
return (
this.state.component
);
这篇关于React Native - 在 x 秒后更改屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文