【发布时间】:2020-11-25 04:49:55
【问题描述】:
我读了一下,似乎 ComponentDidMount 似乎没有激活的原因是因为它已经在堆栈导航器上。为此,我们必须使用带有 'didFocus' 的 addListener。
假设我有 3 个屏幕 A、B、C。我不明白为什么当我的应用程序加载到屏幕 B 上时,componentDidMount 从 C->B 在屏幕 B 上隐式工作(我不需要'didFocus'),但不能从 A->B 工作
ComponentDidMount()
{
//ComponentDidMount Located in Screen B
execute code1. //works from C->B, Does not work from A->B
this.props.navigation.addListener('didFocus'{
execute code2. //Works for both
})
}
堆栈导航器看起来像这样
createStackNavigator({
FriendsArea: {
screen:B,
navigationOptions:{
header:null
}
},
HostArea: {
screen:C,
navigigationOptions:{
header:null
}
},
Profile: {
screen:A,
navigationOptions:{
header:null
}
},
})
有人可以帮忙吗?如果需要,我可以再澄清一些,谢谢。
【问题讨论】:
-
能贴出stack navigator的创建吗?
-
屏幕A、B、C是否正常?
-
@fxbayuanggara 我包含了堆栈导航器
-
@KushalDesai 屏幕顺序请看添加的代码。
-
有人知道吗?
标签: reactjs react-native