以下代码是我的启动画面,如果设置了位置,则必须显示此屏幕,否则我需要导航到AuthSplashScreen。
componentDidUpdate () {
debugger;
if(this.props.location){
return this.props.navigation.dispatch(NavigationActions.reset(
{
index: 0,
actions: [
NavigationActions.navigate({ routeName: 'Home'})
]
}));
}else{
setTimeout(function(){
return this.props.navigation.dispatch(NavigationActions.reset(
{
index: 0,
actions: [
NavigationActions.navigate({ routeName: 'AuthSplashScreen'})
]
}));
}, 1000)
}
}
这里的问题是: 1)如果我使用settimeout,则输出无法读取属性' naviagtion'未定义的。 2)如果我删除它将完美运行的settimeout并根据需要导航 AuthSplashScreen (当未设置位置时)/ 主页(当设置位置时)。但是,在将屏幕从SplashScreen更改为AuthSplashScreen时,它会显示闪烁状态。
那么如何解决这种眨眼的影响呢?或者我是否需要更改管理屏幕的逻辑。
答案 0 :(得分:0)
只需要保留对象的参考。
componentDidUpdate () {
debugger;
if(this.props.location){
return this.props.navigation.dispatch(NavigationActions.reset(
{
index: 0,
actions: [
NavigationActions.navigate({ routeName: 'Home'})
]
}));
}else{
var thisObj = this;
setTimeout(function(){
return thisObj.props.navigation.dispatch(NavigationActions.reset(
{
index: 0,
actions: [
NavigationActions.navigate({ routeName: 'AuthSplashScreen'})
]
}));
}, 1000)
}
}