
Security News
Static vs. Runtime Reachability: Insights from Latioโs On the Record Podcast
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
react-native-user-activity-detection
Advanced tools
A React Native library for detecting user activity and handling app inactivity with native module support for iOS and Android. Perfect for implementing auto-lock functionality, session management, and security features.
A React Native library for detecting user activity and handling app inactivity with native module support for iOS and Android. Perfect for implementing auto-lock functionality, session management, and security features.
npm install react-native-user-activity-detection
cd ios && pod install
cd android && ./gradlew build
import React from 'react';
import { View, Text, Alert } from 'react-native';
import { useNativeActivityDetection } from 'react-native-user-activity-detection';
const App = () => {
const { triggerActivity, isModuleAvailable, resetTimer } = useNativeActivityDetection({
inactivityTimeout: 300000, // 5 minutes
backgroundTimeout: 120, // 2 minutes
onInactivity: () => {
Alert.alert('Session Expired', 'Please login again');
// Lock the app or navigate to login screen
},
onActivity: () => {
console.log('User is active');
},
onBackground: () => {
console.log('App went to background');
},
onForeground: () => {
console.log('App came to foreground');
},
});
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Native Module Available: {isModuleAvailable ? 'Yes' : 'No'}</Text>
<Text>Activity detection is running...</Text>
</View>
);
};
export default App;
import React from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { useNativeActivityDetection } from 'react-native-user-activity-detection';
import { lockApp, unlockApp } from './store/authSlice';
const AppWithRedux = () => {
const { isAuthenticated, isUnlocked } = useSelector((state) => state.auth);
const dispatch = useDispatch();
const { triggerActivity } = useNativeActivityDetection({
enabled: isAuthenticated && isUnlocked,
inactivityTimeout: 480000, // 8 minutes
backgroundTimeout: 240, // 4 minutes
onInactivity: () => {
dispatch(lockApp());
},
onActivity: () => {
// Reset any warning timers
},
});
// Rest of your component...
};
useNativeActivityDetection(options)
Parameter | Type | Default | Description |
---|---|---|---|
inactivityTimeout | number | 480000 | Inactivity timeout in milliseconds |
backgroundTimeout | number | 240 | Background timeout in seconds |
enabled | boolean | true | Whether to enable activity detection |
onInactivity | () => void | undefined | Callback when user becomes inactive |
onActivity | () => void | undefined | Callback when user activity is detected |
onBackground | () => void | undefined | Callback when app goes to background |
onForeground | () => void | undefined | Callback when app comes to foreground |
Property | Type | Description |
---|---|---|
triggerActivity | () => void | Manually trigger activity detection |
resetTimer | () => void | Reset the inactivity timer |
isModuleAvailable | boolean | Whether the native module is available |
The library uses native modules to detect user interactions at the platform level:
If isModuleAvailable
returns false
:
pod install
and the native files are properly addedMainApplication.java
npx react-native start --reset-cache
enabled: true
)See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library
FAQs
A React Native library for detecting user activity and handling app inactivity with native module support for iOS and Android. Perfect for implementing auto-lock functionality, session management, and security features.
The npm package react-native-user-activity-detection receives a total of 8 weekly downloads. As such, react-native-user-activity-detection popularity was classified as not popular.
We found that react-native-user-activity-detection demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.ย It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.