From b1d23f8ea1de496fa88fe8eccb4f07b0efe0618c Mon Sep 17 00:00:00 2001 From: hasan alnatour Date: Wed, 14 Apr 2021 13:23:29 +0400 Subject: [PATCH] add support for keyboards reset time when the user opens or closes the keyboard --- src/components/IdleTracker.jsx | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/components/IdleTracker.jsx b/src/components/IdleTracker.jsx index a2606ef..1c91359 100644 --- a/src/components/IdleTracker.jsx +++ b/src/components/IdleTracker.jsx @@ -1,5 +1,5 @@ import { createElement, useState, useEffect, useRef } from "react"; -import { View, PanResponder } from "react-native"; +import { View, PanResponder, Keyboard } from "react-native"; import { Alert } from './Alert'; export const IdleTracker = props => { @@ -11,11 +11,25 @@ export const IdleTracker = props => { ) useEffect(() => { - //resetInactivityTimeout(); - + + const keyboardDidShowListener = Keyboard.addListener( + 'keyboardDidShow', + () => { + resetInactivityTimeout() + } + ); + const keyboardDidHideListener = Keyboard.addListener( + 'keyboardDidHide', + () => { + resetInactivityTimeout() + } + ); + return () => { clearTimeout(timerId.current); clearTimeout(warningTimerid.current); + keyboardDidHideListener.remove(); + keyboardDidShowListener.remove(); }; }, []);