0
我想做一個應用程序,其中的飛濺顯示爲600毫秒,然後顯示主屏幕。我在componentDidmount中使用了setTimeOut方法,但是我得到的錯誤如here所示。下面還提供了必要的代碼。未定義不是函數:定時器 - 反應本機
import React, { Component } from 'react';
import {Image,Dimensions, Button, Text, StyleSheet, View, TouchableOpacity} from 'react-native';
var timePassed;
class SplashScreen extends Component{
constructor(props){
super(props);
this.state={
timePassed: false
}
}
componentDidMount() {
this.setTimeout(() => {
this.setState({timePassed: true})
},600);
}
render(){
if(!this.state.timePassed){
return(
<View style={styles.container}>
<Image style={styles.logo} source={require('./Images/logo.jpg')} resizeMode="contain" />
<Text style={styles.deadlineFont}>Deadline</Text>
</View>
);
}
else{
return (
<View>
<MainScreen />
</View>
);
}
}
}
感謝您的工作! :) –