Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Background timer with user inactivity #37

Open
BobbyCarelse opened this issue Jul 22, 2020 · 1 comment
Open

Using Background timer with user inactivity #37

BobbyCarelse opened this issue Jul 22, 2020 · 1 comment

Comments

@BobbyCarelse
Copy link

BobbyCarelse commented Jul 22, 2020

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>
@jkomyno
Copy link
Owner

jkomyno commented Feb 2, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants