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

475 Views Asked by At

I have an expo application and I want to implement automatic logout after 5 minutes.

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}.

1

There are 1 best solutions below

3
On

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.