Skip to content

v1.0.0

Choose a tag to compare

@ttwrpz ttwrpz released this 13 Sep 17:46
· 3 commits to main since this release
c66cf25

@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-lock

iOS Setup

cd ios && pod install

Android 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 time
  • batteryThreshold: minimum battery required
  • activateOnCharging: auto-activate when charging
  • respectAppState: deactivate in background
  • reactivateOnTouch: reactivate on interaction
  • debug: enable debug logs
  • onStateChange / 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