reactjs - 在 iOS 上的 React Native 中,有没有办法确定应用程序何时恢复?例如 onResume 事件?

标签 reactjs react-native

我正在尝试确定应用程序何时恢复。例如,当您打开应用程序时,按设备上的主页按钮,然后返回应用程序。

最佳答案

希望您正在寻找这个。 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>
 );
},

关于reactjs - 在 iOS 上的 React Native 中,有没有办法确定应用程序何时恢复?例如 onResume 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33905840/

相关文章:

javascript - 带有 redux 和 React 的 webpack-dev-server 阻止了我的输入

javascript - 在一个函数中同时处理 React.KeyboardEvent 或 React.MouseEvent

javascript - 为数据分配颜色

ios - 如何阻止 react-native 链接将库与具有 podspec 的 CocoaPods 链接起来?

javascript - Next JS npm start app load 404 page not found 物理页面错误

reactjs - React hooks,如何在组件卸载时触发一些逻辑

javascript - 如何使用 GraphQL POST 请求进行授权获取?

reactjs - 与 ComponentWillMount 等效的 React 钩子(Hook)

android - 样式在 React Native 中无法正常工作

reactjs - 在 Jest : NavigationContainer causes console error 中异步测试 React Navigation 5