Reputation: 662
How do I check for inactivity globally in react native i.e touch events. I tried using https://www.npmjs.com/package/react-native-user-inactivity but it doesn't register touch events. I would prefer pure javascript solutions as apposed to linking native code. A solution for just iOS is fine.
Upvotes: 1
Views: 4031
Reputation: 872
I created module react-native-inactivity
for this purpose. By using this module you can actually get if the app is inactive for X ms. You can use in this way.
import ReactNativeInactivity from "react-native-inactivity";
export default function App() {
return (
<View style={{ flex: 1 }}>
<ReactNativeInactivity
isActive={true}
onInactive={() => {//Do Logout or something like that}}
timeForInactivity={60000} //1 mint in ms
restartTimerOnActivityAfterExpiration={false}
loop={false}
style={{ flex: 1, justifyContent: "center", alignItems: "center", backgroundColor: "grey" }}>
<YOUR_NAV_HERE/>
</ReactNativeInactivity>
</View>
);
}
You can also manage other props according to your requirement.
If this solution helped you just thumbs up and give me a star at repository. For more refer to: https://www.npmjs.com/package/react-native-inactivity
Upvotes: 2
Reputation: 477
You can use the PanResponder from react-native package.
Here you can see a working example, using expo toolkit.
Upvotes: 3