
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
@ttwrpz/react-native-wake-lock
Advanced tools
Wake lock for React Native with battery awareness, auto-timeout, and lifecycle management
Wake lock for React Native with battery awareness, auto-timeout, and lifecycle management.
npm install @ttwrpz/react-native-wake-lock
# or
yarn add @ttwrpz/react-native-wake-lock
cd ios && pod install
No additional setup required for Android.
import { useWakeLock } from '@ttwrpz/react-native-wake-lock';
function VideoPlayer() {
const { activate, deactivate, isActive } = useWakeLock();
return (
<View>
<Text>Wake lock is {isActive ? 'active' : 'inactive'}</Text>
<Button title="Play" onPress={activate} />
<Button title="Pause" onPress={deactivate} />
</View>
);
}
import { useWakeLock } from '@ttwrpz/react-native-wake-lock';
function VideoPlayer() {
const {
isActive,
activate,
deactivate,
toggle,
batteryLevel,
isCharging
} = useWakeLock({
// Auto-deactivate after 30 minutes
timeout: 30 * 60 * 1000,
// Only activate if battery > 20%
batteryThreshold: 0.2,
// Auto-activate when charging
activateOnCharging: true,
// Deactivate when app goes to background
respectAppState: true,
// Reactivate on user touch
reactivateOnTouch: true,
// Enable debug logging
debug: __DEV__,
// Callbacks
onStateChange: (isActive) => {
console.log('Wake lock state:', isActive);
},
onError: (error) => {
console.error('Wake lock error:', error);
}
});
return (
<View>
<Text>Battery: {batteryLevel ? `${(batteryLevel * 100).toFixed(0)}%` : 'Unknown'}</Text>
<Text>Charging: {isCharging ? 'Yes' : 'No'}</Text>
<Text>Wake Lock: {isActive ? 'Active' : 'Inactive'}</Text>
<Button title="Toggle" onPress={toggle} />
</View>
);
}
import wakeLock from '@ttwrpz/react-native-wake-lock';
// Activate with options
await wakeLock.activate({
timeout: 5 * 60 * 1000, // 5 minutes
batteryThreshold: 0.15
});
// Check status
const isActive = await wakeLock.isActive();
// Deactivate
await wakeLock.deactivate();
// Toggle
await wakeLock.toggle();
// Configure globally
wakeLock.configure({
debug: true,
batteryThreshold: 0.25
});
useWakeLock(options?)React hook for managing wake lock.
| Option | Type | Default | Description |
|---|---|---|---|
timeout | number | 0 | Auto-deactivate after milliseconds (0 = no timeout) |
batteryThreshold | number | 0.1 | Minimum battery level (0-1) to activate |
activateOnCharging | boolean | false | Auto-activate when device is charging |
respectAppState | boolean | true | Deactivate when app goes to background |
reactivateOnTouch | boolean | false | Reactivate on user interaction |
debug | boolean | false | Enable debug logging |
onStateChange | function | - | Callback when state changes |
onError | function | - | Error callback |
| Property | Type | Description |
|---|---|---|
isActive | boolean | Current wake lock state |
activate | () => void | Activate wake lock |
deactivate | () => void | Deactivate wake lock |
toggle | () => void | Toggle wake lock state |
batteryLevel | number | null | Current battery level (0-1) |
isCharging | boolean | Whether device is charging |
wakeLockSimple function API for wake lock control.
wakeLock.activate(options?): Promise<boolean>
wakeLock.deactivate(): Promise<boolean>
wakeLock.toggle(): Promise<boolean>
wakeLock.isActive(): Promise<boolean>
wakeLock.getState(): WakeLockState
wakeLock.configure(options): void
function VideoPlayer() {
useWakeLock({
timeout: 0, // No timeout for videos
batteryThreshold: 0.05, // Allow even with low battery
respectAppState: true
});
}
function RecipeView() {
useWakeLock({
timeout: 10 * 60 * 1000, // 10 minutes per recipe step
reactivateOnTouch: true,
batteryThreshold: 0.15
});
}
function Navigation() {
useWakeLock({
activateOnCharging: true, // Usually plugged in car
batteryThreshold: 0.20,
respectAppState: false // Keep active in background
});
}
function Reader() {
const { isActive, onTouchStart, onTouchEnd } = useWakeLockWithTouch({
timeout: 30 * 60 * 1000, // 30 minutes
reactivateOnTouch: true,
batteryThreshold: 0.25,
activateOnCharging: true
});
return (
<TouchableWithoutFeedback onPressIn={onTouchStart} onPressOut={onTouchEnd}>
<View style={{ flex: 1 }}>
<ScrollView>
<Text>Your content here...</Text>
</ScrollView>
</View>
</TouchableWithoutFeedback>
);
}
MIT
FAQs
Wake lock for React Native with battery awareness, auto-timeout, and lifecycle management
We found that @ttwrpz/react-native-wake-lock 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.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.