javascript - React native - x 秒后更改屏幕

标签 javascript reactjs react-native

我有一个我无法解决的问题。

在我的 React native 应用程序中,我想在开始时显示一个欢迎屏幕。然后 5 秒后关闭它,并显示另一个。两者是完全不同的 2 个屏幕,无需保留“返回”箭头。

我已经搜索了几个小时,但我还没有找到如何去做。

这是我现在的代码:

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 似乎已被弃用。

最佳答案

不使用任何导航器这可以解决您的问题

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
);

关于javascript - React native - x 秒后更改屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44937498/

相关文章:

javascript - 如何使用 javascript API 从 Parse 获取上传的图像

javascript - event.target.value 对于包装图像而不是文本的按钮是未定义的

ios - react-native run-ios 找不到任何模拟器

react-native - React Native Inline 函数理解

php - 提交时用 php 隐藏表单?

javascript - 转到 : regexp to swap cases

javascript - 参数在 RN typescript 中隐式具有任何类型

javascript - React.js、JavaScript 通过单击数组中的父元素获取 Img

javascript - 使用 React Native 的未定义导航器

javascript - javascript中的私有(private)变量意味着