react-native-wakelock-keepawake
v0.2.3
Published
A React Native package that prevents the screen from going to sleep while your app is active. Works for both iOS and Android.
Readme
react-native-wakelock-keepawake
A React Native package that prevents the screen from going to sleep while your app is active. Works for both iOS and Android.
Installation
yarn add react-native-wakelock-keepawakeOR
npm install react-native-wakelock-keepawakeUsage
Android Setup
Add the following permission to your AndroidManifest.xml:
<uses-permission android:name="android.permission.WAKE_LOCK" />Usage
import {
activateWakelock,
deactivateWakelock,
} from 'react-native-wakelock-keepawake';
// Keep the screen awake
activateWakelock();
// Allow the screen to sleep
deactivateWakelock();Example
import React, { useEffect } from 'react';
import { View, Button } from 'react-native';
import {
activateWakelock,
deactivateWakelock,
} from 'react-native-wakelock-keepawake';
function VideoPlayer() {
useEffect(() => {
// Activate keep awake when component mounts
activateWakelock();
// Deactivate when component unmounts
return () => {
deactivateWakelock();
};
}, []);
return <View>{/* Your video player component */}</View>;
}API Reference
activateWakelock()
Prevents the screen from going to sleep. The screen will remain on until deactivateWakelock() is called.
deactivateWakelock()
Allows the screen to go to sleep following the device's normal behavior.
Common Use Cases
- Video players
- Navigation apps
- Reading apps
- Games
- Presentation apps
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT
Made with create-react-native-library
