Prevent the phone screen from going to sleep.
0

Configure Feed

Select the types of activity you want to include in your feed.

docs: add usage instructions to README

Joseph Hale (Jul 25, 2025, 4:14 PM -0700) 666b2a0c 94946f46

+48 -4
+48 -4
README.md
··· 21 21 22 22 ## Usage 23 23 24 + There are three different ways you can use this library to keep a screen from going to sleep 24 25 25 - ```js 26 - import { multiply } from 'react-native-keep-awake'; 26 + ### Add a Component 27 + 28 + Any screen that includes the `KeepAwake` component in its tree will not go to sleep. 27 29 28 - // ... 30 + ```tsx 31 + import { KeepAwake } from 'react-native-keep-awake'; 29 32 30 - const result = multiply(3, 7); 33 + function MyScreen() { 34 + return ( 35 + <View> 36 + <KeepAwake /> 37 + <Text>This screen won't go to sleep!</Text> 38 + </View> 39 + ) 40 + } 31 41 ``` 32 42 43 + ### Use a Hook 44 + 45 + Invoking the `useKeepAwake` hook will prevent that screen from going to sleep. 46 + 47 + ```tsx 48 + import { useKeepAwake } from 'react-native-keep-awake'; 49 + 50 + function MyScreen() { 51 + useKeepAwake() 52 + return ( 53 + <View> 54 + <Text>This screen won't go to sleep!</Text> 55 + </View> 56 + ) 57 + } 58 + ``` 59 + 60 + ### Manual Control 61 + 62 + ```tsx 63 + import { activate, deactivate } from 'react-native-keep-awake'; 64 + 65 + function MyScreen() { 66 + return ( 67 + <View> 68 + <Text>Press this button to block the screen from going to sleep</Text> 69 + <Button title="Activate" onPress={activate} /> 70 + 71 + <Text>Press this button to allow the screen to sleep/lock</Text> 72 + <Button title="Deactivate" onPress={deactivate} /> 73 + </View> 74 + ) 75 + } 76 + ``` 33 77 34 78 ## Contributing 35 79