[React Navigation中返回主屏幕时如何调用构造函数?

问题描述 投票:0回答:1

我有一个带有createBottomTabNavigatorcreateStackNavigator

const SettingsStack = createStackNavigator({
  SettingsScreen: {
    screen: SettingsClass,  //1st screen
  },
  EditProfile: {
    screen: EditProfileClass . //2nd screen
  },
},

当我从EditProfile屏幕移回主SettingsScreen时,我希望让SettingsScreen中的componentWillMount()再次运行(并且每次我返回)。现在,它只运行一次。或者在SettingsScreen中创建一个功能,该功能在我从EditProfile屏幕导航回到主SettingsScreen时运行。这样一来,我的主设置屏幕现在将刷新最新的配置文件信息。我该如何实现?

reactjs react-native react-native-android react-navigation react-native-ios
1个回答
0
投票
class SettingsScreen extends Component { componentDidMount() { this.focusListener = this.props.navigation.addListener('didFocus', () => { // Call your refresh code here }); } componentWillUnmount() { this.focusListener.remove(); } }
© www.soinside.com 2019 - 2024. All rights reserved.