Prevent the phone screen from going to sleep.
npm install @thehale/react-native-keep-awakePrevent the phone screen from going to sleep.




``sh`
npm install @thehale/react-native-keep-awake
React Native 0.78.0+ (New Architecture only)
There are three different ways you can use this library to keep a screen from going to sleep.
Any screen that includes the KeepAwake component in its tree will not go to sleep.
`tsx
import { KeepAwake } from '@thehale/react-native-keep-awake';
function MyScreen() {
return (
)
}
`
Invoking the useKeepAwake hook will prevent that screen from going to sleep.
`tsx
import { useKeepAwake } from '@thehale/react-native-keep-awake';
function MyScreen() {
useKeepAwake()
return (
)
}
`
`tsx
import { activate, deactivate } from '@thehale/react-native-keep-awake';
function MyScreen() {
return (
)
}
`
See the contributing guide to learn how to contribute to the repository and the development workflow.
Provided under the terms of the Mozilla Public License, version 2.0
> [!NOTE]
> This package is a rewrite of react-native-keep-awake and @sayem314/react-native-keep-awake which are licensed under the MIT license.
You can use files from this project in both open source and proprietary
applications, provided you include the above attribution. However, if
you modify any code in this project, or copy blocks of it into your own
code, you must publicly share the resulting files (note, not your whole
program) under the MPL-2.0. The best way to do this is via a Pull
Request back into this project.
If you have any other questions, you may also find Mozilla's official
FAQ for the MPL-2.0 license
insightful.
If you dislike this license, you can contact me about negotiating a paid
contract with different terms.
Disclaimer: This TL;DR is just a summary. All legal questions
regarding usage of this project must be handled according to the
official terms specified in the LICENSE` file.
I believe that an open-source software license should ensure that code
can be used everywhere.
Strict copyleft licenses, like the GPL family of licenses, fail to
fulfill that vision because they only permit code to be used in other
GPL-licensed projects. Permissive licenses, like the MIT and Apache
licenses, allow code to be used everywhere but fail to prevent
proprietary or GPL-licensed projects from limiting access to any
improvements they make.
In contrast, the MPL-2.0 license allows code to be used in any software
project, while ensuring that any improvements remain available for
everyone.
---
Made with create-react-native-library