How can I detect native side modal closing in react-native?
I have a native modal open in my application, and I wish to perform a certain operation after it has closed. Im using react-navigation for navigation, but none of its events (willFocus etc..) are not firing when the native side modal closes. The native side modal is notifications settings that are opened by using this library: https://github.com/riwu/react-native-open-notification. From there I open the modal applying the NotificationSetting.open() function. I don't know how can I detect when user returns back to the application from the settings? Tried detecting back button press, but no luck with that.
Figured I could do this with react-native's AppState (https://facebook.github.io/react-native/docs/appstate):
import React, {Component} from 'react';
import {AppState, Text} from 'react-native';
class AppStateExample extends Component {
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!');
}
this.setState({appState: nextAppState});
};
render() {
return <Text>Current state is: {this.state.appState}</Text>;
}
}