expo-keep-awake
Version: 55.0.3 Provides a React component that prevents the screen from sleeping when rendered. It also exposes static methods to control the behavior imperatively.Installation
Usage
Component-Based
Hook-Based
Imperative API
API Reference
Component
React.Component
Renders a component that prevents screen from sleepingAutomatically activates when mounted and deactivates when unmounted.
Hook
(tag?: string) => void
Hook that keeps screen awake while component is mountedOptional
tag parameter allows multiple independent keep-awake instances.Methods
(tag?: string) => void
Activates keep-awake mode
(tag?: string) => void
Deactivates keep-awake mode
Examples
Video Player
Navigation Screen
Conditional Keep Awake
Imperative Control
Multiple Instances with Tags
Reading Mode
Camera Preview
TypeScript
Platform Support
How It Works
- iOS: Sets
UIApplication.shared.isIdleTimerDisabled = true - Android: Adds
FLAG_KEEP_SCREEN_ONto the window - Web: Uses Wake Lock API or NoSleep.js fallback
Best Practices
- Use Component/Hook: Prefer
<KeepAwake />oruseKeepAwake()for automatic cleanup - Clean Up: Always deactivate when no longer needed to save battery
- Use Tags: Use unique tags for multiple independent instances
- Conditional Usage: Only activate when actually needed (e.g., during video playback)
- User Control: Consider letting users disable keep-awake in settings