This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Expo KeepAwake
A React component that prevents the screen from sleeping when rendered.
expo-keep-awake provides a React hook that prevents the screen from sleeping and a pair of functions to enable this behavior imperatively.
Installation
If you are installing this in an existing React Native app, make sure to install expo in your project.
Usage
Example: hook
Example: functions
API
import * as KeepAwake from 'expo-keep-awake';
Constants
Type: 'ExpoKeepAwakeDefaultTag'
Default tag, used when no tag has been specified in keep awake method calls.
Hooks
A React hook to keep the screen awake for as long as the owner component is mounted.
The optionally provided tag argument is used when activating and deactivating the keep-awake
feature. If unspecified, an ID unique to the owner component is used. See the documentation for
activateKeepAwakeAsync below to learn more about the tag argument.
voidMethods
Deprecated: use
activateKeepAwakeAsyncinstead.
Prevents the screen from sleeping until deactivateKeepAwake is called with the same tag value.
If the tag argument is specified, the screen will not sleep until you call deactivateKeepAwake
with the same tag argument. When using multiple tags for activation you'll have to deactivate
each one in order to re-enable screen sleep. If tag is unspecified, the default tag is used.
Web support is limited.
Promise<void>Prevents the screen from sleeping until deactivateKeepAwake is called with the same tag value.
If the tag argument is specified, the screen will not sleep until you call deactivateKeepAwake
with the same tag argument. When using multiple tags for activation you'll have to deactivate
each one in order to re-enable screen sleep. If tag is unspecified, the default tag is used.
Web support is limited.
Promise<void>Releases the lock on screen-sleep prevention associated with the given tag value. If tag
is unspecified, it defaults to the same default tag that activateKeepAwake uses.
Promise<void>Promise<boolean>true on all platforms except unsupported web browsers.
Event subscriptions
Observe changes to the keep awake timer. On web, this changes when navigating away from the active window/tab. No-op on native.
EventSubscriptionExample
KeepAwake.addListener(({ state }) => { // ... });