What is expo-keep-awake?
The expo-keep-awake package is used to prevent the screen from sleeping or dimming while your app is in use. This is particularly useful for applications that require constant user interaction or display information that the user needs to see without interruption.
What are expo-keep-awake's main functionalities?
Activate Keep Awake
This feature allows you to activate the keep-awake functionality, preventing the screen from sleeping or dimming.
import { activateKeepAwake } from 'expo-keep-awake';
activateKeepAwake();
Deactivate Keep Awake
This feature allows you to deactivate the keep-awake functionality, allowing the screen to sleep or dim as usual.
import { deactivateKeepAwake } from 'expo-keep-awake';
deactivateKeepAwake();
Use Keep Awake Hook
This feature provides a React hook that you can use within a functional component to keep the screen awake while the component is mounted.
import { useKeepAwake } from 'expo-keep-awake';
function MyComponent() {
useKeepAwake();
return <View>{/* Your component code */}</View>;
}
Other packages similar to expo-keep-awake
react-native-keep-awake
The react-native-keep-awake package provides similar functionality to expo-keep-awake, allowing you to prevent the screen from sleeping. It is a good alternative for non-Expo managed workflows.
react-native-idle-timer
The react-native-idle-timer package allows you to enable or disable the idle timer, which controls whether the screen should sleep. It offers more granular control over the idle state compared to expo-keep-awake.
Provides a React component that prevents the screen sleeping when rendered. It also exposes static methods to control the behavior imperatively.
API documentation
Installation in managed Expo projects
For managed Expo projects, please follow the installation instructions in the API documentation for the latest stable release.
Installation in bare React Native projects
For bare React Native projects, you must ensure that you have installed and configured the expo
package before continuing.
Add the package to your npm dependencies
npx expo install expo-keep-awake
Configure for Android
No additional set up necessary.
Configure for iOS
Run npx pod-install
after installing the npm package.
Contributing
Contributions are very welcome! Please refer to guidelines described in the contributing guide.