react-native-user-inactivity
react-native-user-inactivity copied to clipboard
Using Background timer with user inactivity
I have created a component that wraps my app navigator, the problem I am experiencing is that after the onAction callback gets fired the timer seems to carry on counting and therefore, executing the callback function passed to onAction every few seconds
timeForInactivity = 15
InactivityComponent:
import React from 'react';
import UserInactivity from 'react-native-user-inactivity';
import BackgroundTimer from 'react-native-user-inactivity/lib/BackgroundTimer';
export default InActivityContainer = (props) => {
return(
<UserInactivity
timeForInactivity={props.timeForInactivity * 60 * 1000}
onAction={isActive => {
props.onAction(isActive);
}}
style={{ flex: 1 }}
>
{props.children}
</UserInactivity>
)
}
Inactivity wrapping App Navigator inside of App.js
<InactivityContainer
onAction={(isActive) => {
if (!isActive) {
store.dispatch({ type: types.LOGOUT });
navigate("App", {});
}
}}
timeForInactivity={timeForTimeout}
>
{Platform.OS === "ios" && <StatusBar barStyle="default" />}
<AppNavigator
ref={(navigator) => {
nav = navigator;
setNavigator(navigator);
}}
onNavigationStateChange={(prevState, newState) => {
Analytics.setCurrentScreen(getCurrentRoute(newState));
}}
/>
</InactivityContainer>
Hi, sorry for the delay in my reply. I'm currently unable to reproduce the issue, can you please provide a small example without other third-party dependencies (like the react-navigation
or redux
in this case)?