最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - react native. the close event of the application - Stack Overflow

programmeradmin2浏览0评论

On one of the pages of the developed application for ios on react native there is a switch ponents. When interacting with them, the state of the switches is stored in the Redux storage, but when leaving the page or leaving the application, you need to send the state data to the server. Leaving the page is implemented as follows:

props.navigation.addListener('willBlur', async() => {
  props.pushDataOnServer(data, token);
});

We add a navigation handler (StackNavigator) for the willBlur event, thus we can catch the transition to another page, but what about when closing the application directly from the edit page of the switches? Is there any event for this (e.g. willExit, willClose)? Or if you know a more effective way, please tell us

On one of the pages of the developed application for ios on react native there is a switch ponents. When interacting with them, the state of the switches is stored in the Redux storage, but when leaving the page or leaving the application, you need to send the state data to the server. Leaving the page is implemented as follows:

props.navigation.addListener('willBlur', async() => {
  props.pushDataOnServer(data, token);
});

We add a navigation handler (StackNavigator) for the willBlur event, thus we can catch the transition to another page, but what about when closing the application directly from the edit page of the switches? Is there any event for this (e.g. willExit, willClose)? Or if you know a more effective way, please tell us

Share Improve this question asked Jul 5, 2018 at 1:47 Zimovik007Zimovik007 8832 gold badges8 silver badges18 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 12

In your root ponent, you can watch for AppState changes.

ponentDidMount() {
  AppState.addEventListener('change', this.handleAppStateChange);
}

ponentWillUnmount() {
  AppState.removeEventListener('change', this.handleAppStateChange);
}

handleAppStateChange = (nextAppState) => {
  if (nextAppState === 'inactive') {
    console.log('the app is closed');
  }    
}
发布评论

评论列表(0)

  1. 暂无评论