簡體   English   中英

React Native - 使用兩個屏幕(組件)在 5 分鍾后注銷

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

我有一個博覽會應用程序,我想在 5 分鍾后實現自動注銷。

在用戶登錄時顯示的第一個組件中,我創建了:

下面的代碼工作正常,但是當我切換到新屏幕(新組件)時,我無法更新注銷時間。

如何在下一個屏幕上更新時間?

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

在屏幕的 ,我已經放了{... this._panResponder.panHandlers}

您應該制作公共組件並繼承公共組件的所有組件。 並且您應該在通用組件中實現上述代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM