react-native-user-inactivity icon indicating copy to clipboard operation
react-native-user-inactivity copied to clipboard

Using Background timer with user inactivity

Open BobbyCarelse opened this issue 4 years ago • 1 comments

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>

BobbyCarelse avatar Jul 22 '20 13:07 BobbyCarelse

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

jkomyno avatar Feb 02 '21 09:02 jkomyno