diff --git a/Libraries/AppState/AppState.js b/Libraries/AppState/AppState.js index c3f5df27f..c4ad345bc 100644 --- a/Libraries/AppState/AppState.js +++ b/Libraries/AppState/AppState.js @@ -44,25 +44,37 @@ const invariant = require('fbjs/lib/invariant'); * while `AppState` retrieves it over the bridge. * * ``` - * getInitialState: function() { - * return { - * currentAppState: AppState.currentState, - * }; - * }, - * componentDidMount: function() { - * AppState.addEventListener('change', this._handleAppStateChange); - * }, - * componentWillUnmount: function() { - * AppState.removeEventListener('change', this._handleAppStateChange); - * }, - * _handleAppStateChange: function(currentAppState) { - * this.setState({ currentAppState, }); - * }, - * render: function() { - * return ( - * Current state is: {this.state.currentAppState} - * ); - * }, + * 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 ( + * Current state is: {this.state.appState} + * ); + * } + * + * } * ``` * * This example will only ever appear to say "Current state is: active" because