react-native(리액트 네이티브) API - AppState
import React, {Component} from 'react'
import {AppState, Text} from 'react-native'
export default 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>
);
}
}
'프로그래밍(Programming) > 리액트 네이티브(React Native)' 카테고리의 다른 글
react-native(리액트 네이티브) API - Clipboard (0) | 2019.01.07 |
---|---|
react-native(리액트 네이티브) API - Border (0) | 2019.01.07 |
react-native(리액트 네이티브) API - Alert (0) | 2019.01.07 |
react-native(리액트 네이티브) component -WebView (0) | 2019.01.07 |
react-native(리액트 네이티브) component - ViewPagerAndroid (0) | 2019.01.07 |