【发布时间】:2018-10-27 16:06:33
【问题描述】:
我会尝试解释我的情况:
我有 2 个页面/屏幕
SreenA.js:
...
<FlatList>
</FlatList>
...
ScreenB.js:
...
<Button> This button for back to ScreenA </Button>
...
我想要达到的目标:
当我在 screenB 中按下返回按钮时,我的应用程序将返回到 screenA。 当我回到 screenA 时,我需要刷新 FlatList。 (每个 时间我回到屏幕A)。
我如何在 Android Native 中实现这种情况?
我添加此部分是为了帮助您更了解我面临的挑战 脸。在 Android Native 中,我将使用 onResume 刷新列表 (每次调用屏幕/页面时都会调用 onResume)。
我已经尝试过但现在不适合我的方法:
我已经尝试过了,但是当应用程序在后台运行然后在前台显示时我得到它的调用:
state = {
appState: AppState.currentState
}
componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
}
componentWillUnmount() {
AppState.removeEventListener('change', this._handleAppStateChange);
}
_handleAppStateChange = (nextAppState) => {
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
console.log('App has come to the foreground!')
//i place the code here for refresh the flatList. But not work
}
this.setState({appState: nextAppState});
}
【问题讨论】:
-
你用什么导航?
-
我使用 StackNavigator
-
使用
onWillFocusnavigation event -
你能给我举个例子吗?如果有效,我将接受正确答案。
标签: javascript android react-native