简体   繁体   English

React Native - 使用两个屏幕(组件)在 5 分钟后注销

[英]React Native - Logout after 5 minutes with two screens (components)

I have an expo application and I want to implement automatic logout after 5 minutes.我有一个博览会应用程序,我想在 5 分钟后实现自动注销。

In the first component that is shown when the user logs in I created:在用户登录时显示的第一个组件中,我创建了:

The code below works fine but when I change to the new screen (new component) I can't renew the time to logout.下面的代码工作正常,但是当我切换到新屏幕(新组件)时,我无法更新注销时间。

How I can renew the time on the next screen?如何在下一个屏幕上更新时间?

componentWillMount() {
  this._panResponder = PanResponder.create({
    onMoveShouldSetPanResponderCapture: () => {
      clearTimeout(this.timeout)

      this.setState((state) => {
        if (state.inactive == false) return null
        return {
          inactive: false
        }
      })

      this.timeout = setTimeout(() => {
        this.setState({
          inactive: true
        })
      }, 300000)

      return false
    }
  })
}

componentWillUnmount() {
  clearTimeout(this.timeout)
}

In the of the screen, I had put {... this._panResponder.panHandlers} .在屏幕的 ,我已经放了{... this._panResponder.panHandlers}

You should make the common component and inherits all the components from the common one.您应该制作公共组件并继承公共组件的所有组件。 And you should implement the above code in common components.并且您应该在通用组件中实现上述代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM