expo-keep-awake
provides a React hook that prevents the screen from sleeping and a pair of functions to enable this behavior imperatively.Android Device | Android Emulator | iOS Device | iOS Simulator | Web |
---|---|---|---|---|
Pending |
expo install expo-keep-awake
If you're installing this in a bare React Native app, you should also follow these additional installation instructions.
import { useKeepAwake } from 'expo-keep-awake'; import React from 'react'; import { Text, View } from 'react-native'; export default function KeepAwakeExample { useKeepAwake(); return ( <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> <Text>This screen will never sleep!</Text> </View> ); }
import { activateKeepAwake, deactivateKeepAwake } from 'expo-keep-awake'; import React from 'react'; import { Button, View } from 'react-native'; export default class KeepAwakeExample extends React.Component { render() { return ( <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> <Button onPress={this._activate}>Activate</Button> <Button onPress={this._deactivate}>Deactivate</Button> </View> ); } _activate = () => { activateKeepAwake(); }; _deactivate = () => { deactivateKeepAwake(); }; }
import KeepAwake from 'expo-keep-awake';
tag
argument is used when activating and deactivating the keep-awake feature. If unspecified, the default tag is used. See the documentation for activateKeepAwake
below to learn more about the tag
argument.deactivateKeepAwake
is called with the same tag
value.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.tag
value. If tag
is unspecified, it defaults to the same default tag that activateKeepAwake
uses.