0

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

Derek Wang
  • 10,098
  • 4
  • 18
  • 39
Ce8
  • 1
  • 2

1 Answers1

0

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.

awmidas
  • 653
  • 5
  • 13
  • I had tried to do it, I had create a component and put the code inside to teste. function LogoutAfterTime(TimeToLogout) { console.warn('its works') timeout = setTimeout(() => { Alert.alert('I am appearing...','After 5 second!') }, TimeToLogout); } but when I call the component inside the screen 1 its works, but when I call the component again for the screen 2 it isn't works. The time continue the same of the first screen – Ce8 Oct 13 '20 at 14:44
  • @Ce8 Could you share the full source code, please? so that I can check on my side, there could be other problems related to that issue. – awmidas Oct 13 '20 at 14:49
  • I can't do it because I have others business code inside. My problem is simple. I want to make a logout after 5 minutes, but I have to screens in my app and when the user change the screen I can renew the time. I Follow this example: https://codedaily.io/tutorials/140/How-to-Detect-Touch-Inactivity-with-a-PanResponder-in-React-Native – Ce8 Oct 13 '20 at 17:13