Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In React Native on iOS, is there a way to determine when an app is resumed? Such as an onResume event?

I'm trying to determine when an app is resumed. For instance, when you open the app, press the home button on the device, and then go back into the app.

like image 769
Michael Du Russel Avatar asked Nov 24 '15 23:11

Michael Du Russel


1 Answers

Hope you are looking for this. Documentation Here

getInitialState: function() {
  return {
    currentAppState: AppStateIOS.currentState,
  };
},
componentDidMount: function() {
  AppStateIOS.addEventListener('change', this._handleAppStateChange);
},
componentWillUnmount: function() {
    AppStateIOS.removeEventListener('change', this._handleAppStateChange);
},
_handleAppStateChange: function(currentAppState) {
  this.setState({ currentAppState, });
},
render: function() {
  return (
     <Text>Current state is: {this.state.currentAppState}</Text>
 );
},
like image 108
Phyo Avatar answered Nov 15 '22 07:11

Phyo