Comments (1)
You have to catch when the screen main component are unfocused. Not unmounted, because it never be really unmounted in React Native actually. Then you should have to return something without the UserInactivity tag, some component different to the original component involve in the UserInactivity tag. Or the same component but without the UserInactivity tag. This is going to discard the timer in the new View of the React Navigation. Don't forget to catch the focus state of the View again and return the original Component involve in the UserInactivity tag to start the timer again.
import React,{useState, useCallback} from 'react';
import {useFocusEffect} from '@react-navigation/native';
import UserInactivity from 'react-native-user-inactivity';
...
const MyComponent = (props)=>{
useFocusEffect(
useCallback(() => {
setIsMounted(true);
console.log('SCREEN IS FOCUS');
return () => {
setIsMounted(false);
console.log('SCREEN IS UNFOCUSED');
};
}, [])
);
...
const [active, setActive] = useState(true);
const [timer, setTimer] = useState(10000);
const [isMounted, setIsMounted] = useState(true);
if(isMounted){
return(
<UserInactivity
isActive={active}
timeForInactivity={timer}
onAction={isActive => setActive(isActive)}
style={{ flex: 1 }}
>
);
}else{
return();
}
export default MyComponent;
from react-native-user-inactivity.
Related Issues (20)
- Using Background timer with user inactivity HOT 1
- Unable to install the package on RN 39.0.4 HOT 2
- react-native-user-inactivity not working in Android 10 HOT 6
- Keeps timing users out while using the app HOT 2
- Is User considered active while watching a video? HOT 2
- getting incorrect values from redux inside onAction HOT 2
- Timer doesnot get inactive once started? How to do it HOT 1
- Keyboard activity outside this App HOT 1
- Congratulations and thank u! HOT 1
- Improve README.md
- Input from keyboard is not considered as an action HOT 4
- Not getting updated values from store inside onAction HOT 2
- ERESOLVE unable to resolve dependency tree HOT 5
- expo demo need update, not working
- Support React 18 HOT 3
- Support changing `onAction` prop HOT 1
- Sometimes does not detect user interaction on android devices HOT 2
- node module download error
- onAction not called when app is in background (Android)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-user-inactivity.