Keep the screen from going to sleep. iOS, Android and Web.
npm install @sayem314/react-native-keep-awakeThis React Native package allows you to prevent the screen from going to sleep while your app is active. It's useful for things like navigation or video playback, where the user expects the app to remain visible over long periods without touch interaction.
As the first step, install this module:
#### React Native 0.60+
yarn add @sayem314/react-native-keep-awake
#### React Native new architecture
You must use react-native-keep-awake@1.2.0 or newer if you want to use the RN new architecture.
#### example: hooks
``js
import { useKeepAwake } from '@sayem314/react-native-keep-awake';
import React from 'react';
import { Text, View } from 'react-native';
export default function KeepAwakeExample {
useKeepAwake();
return (
);
}
`
#### example: components
`js
import KeepAwake from '@sayem314/react-native-keep-awake';
import React from 'react';
import { Text, View } from 'react-native';
export default function KeepAwakeExample {
return (
);
}
`
#### example: functions
`js
import { activateKeepAwake, deactivateKeepAwake} from "@sayem314/react-native-keep-awake";
import React from "react";
import { Button, View } from "react-native";
export default class KeepAwakeExample extends React.Component {
render() {
return (
);
}
_activate = () => {
activateKeepAwake();
};
_deactivate = () => {
deactivateKeepAwake();
};
}
``