File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ yarn add react-native-hooks
21
21
## API
22
22
- [ useAccessibilityInfo] ( https://github.com/react-native-community/react-native-hooks#useaccessibilityinfo )
23
23
- [ useAppState] ( https://github.com/react-native-community/react-native-hooks#useappstate )
24
+ - [ useBackHandler] ( https://github.com/react-native-community/react-native-hooks#usebackhandler )
24
25
- [ useCameraRoll] ( https://github.com/react-native-community/react-native-hooks#usecameraroll )
25
26
- [ useClipboard] ( https://github.com/react-native-community/react-native-hooks#useclipboard )
26
27
- [ useDimensions] ( https://github.com/react-native-community/react-native-hooks#usedimensions )
@@ -47,6 +48,21 @@ import { useAppState } from 'react-native-hooks'
47
48
const currentAppState = useAppState ()
48
49
```
49
50
51
+ ### ` useBackHandler `
52
+
53
+ ``` js
54
+ import { useBackHandler } from ' react-native-hooks'
55
+
56
+ useBackHandler (() => {
57
+ if (shouldBeHandledHere) {
58
+ // handle it
59
+ return true
60
+ }
61
+ // let the default thing happen
62
+ return false
63
+ })
64
+ ```
65
+
50
66
### ` useCameraRoll `
51
67
52
68
``` js
Original file line number Diff line number Diff line change 1
1
import useDimensions from './lib/useDimensions'
2
2
import useAppState from './lib/useAppState'
3
+ import useBackHandler from './lib/useBackHandler'
3
4
import useCameraRoll from './lib/useCameraRoll'
4
5
import useClipboard from './lib/useClipboard'
5
6
import useAccessibilityInfo from './lib/useAccessibilityInfo'
@@ -12,6 +13,7 @@ import useDeviceOrientation from './lib/useDeviceOrientation'
12
13
export {
13
14
useDimensions ,
14
15
useAppState ,
16
+ useBackHandler ,
15
17
useCameraRoll ,
16
18
useClipboard ,
17
19
useAccessibilityInfo ,
Original file line number Diff line number Diff line change
1
+ import React , { useEffect , useState } from 'react'
2
+ import { BackHandler } from 'react-native'
3
+
4
+
5
+ export default ( handler ) => {
6
+ useEffect ( ( ) => {
7
+ BackHandler . addEventListener ( 'hardwareBackPress' , handler )
8
+
9
+ return ( ) => {
10
+ BackHandler . removeEventListener ( 'hardwareBackPress' , handler )
11
+ }
12
+ } )
13
+ }
You can’t perform that action at this time.
0 commit comments