Skip to main content
Glama
keep-awake.md1.38 kB
--- title: KeepAwake description: A React component that prevents the screen from sleeping when rendered. sourceCodeUrl: https://github.com/expo/expo/tree/sdk-52/packages/expo-keep-awake packageName: expo-keep-awake iconUrl: /static/images/packages/expo-keep-awake.png platforms: ["android", "ios", "tvos", "web"] --- `expo-keep-awake` provides a React hook that prevents the screen from sleeping and a pair of functions to enable this behavior imperatively. ## Installation ## Usage ### Example: hook ```jsx /* @info As long as this component is mounted, the screen will not turn off from being idle. */ useKeepAwake(); /* @end */ return ( <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> <Text>This screen will never sleep!</Text> </View> ); } ``` ### Example: functions ```jsx render() { return ( <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> </View> ); } _activate = () => { /* @info Screen will remain on after called until <strong>deactivateKeepAwake()</strong> is called. */ activateKeepAwake(); /* @end */ alert('Activated!'); }; _deactivate = () => { /* @info Deactivates KeepAwake, or does nothing if it was never activated. */ deactivateKeepAwake(); /* @end */ alert('Deactivated!'); }; } ``` ## API ```js ```

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/jaksm/expo-docs-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server