Repository navigation
v1.0.0
@ttwrpz/react-native-wake-lock brings battery-aware, lifecycle-conscious wake lock management to React Native apps. Keep your screen awake efficiently without draining the battery or interfering with app state.
Features
- Battery-aware – Prevent activation when battery is low
- Auto-timeout – Automatically deactivate after a set time
- Charging detection – Optionally activate only while charging
- App lifecycle aware – Respects foreground/background state
- Touch reactivation – Reactivate on user interaction
- Lightweight & high performance – Small bundle size, debounced calls, and state caching
- TypeScript support – Full type safety and IntelliSense
Installation
npm install @ttwrpz/react-native-wake-lock
# or
yarn add @ttwrpz/react-native-wake-lockiOS Setup
cd ios && pod installAndroid Setup
No additional setup required.
Usage Examples
Basic Hook
import { useWakeLock } from '@ttwrpz/react-native-wake-lock';
const { activate, deactivate, isActive } = useWakeLock();Advanced Hook Options
timeout: auto-deactivate after specified timebatteryThreshold: minimum battery requiredactivateOnCharging: auto-activate when chargingrespectAppState: deactivate in backgroundreactivateOnTouch: reactivate on interactiondebug: enable debug logsonStateChange/onError: callbacks
Function API
import wakeLock from '@ttwrpz/react-native-wake-lock';
await wakeLock.activate({ timeout: 300000, batteryThreshold: 0.15 });
await wakeLock.deactivate();
const isActive = await wakeLock.isActive();Use Cases
- Video Player – Keep screen awake for playback
- Recipe App – Auto-keep awake per step
- Navigation App – Auto-activate while charging
- Reading App – Reactivate on touch
Performance Optimizations
- Debounced activation
- State caching to reduce native bridge calls
- Lazy initialization
- Singleton pattern to manage wake locks
- ~5KB minified + gzipped
Compatibility
- React Native 0.60+
- iOS 10+
- Android 5.0+ (API 21+)
Troubleshooting
- Wake lock not working on iOS → test on real device
- Battery always returns 1.0 → simulators don’t report battery correctly
- Immediate deactivation → check batteryThreshold & debug logs
License
MIT