如何检测从后台到前台 es6 的任何方法?
这在 React-native 中可能吗?是否有任何类或工具可以帮助这种方法?
最佳答案
试试这个,它对我有用
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>
);
}
}
关于android - 如何在 React Native Es6 上检测 OnResume 和 onPause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50020342/