Skip to content

Commit 59e7b01

Browse files
committed
Merge branch 'master' of https://github.com/Naturalclar/react-native-hooks into chore/addEslint
2 parents cafaaa6 + a30f739 commit 59e7b01

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
![React Native Hooks](reactnativehooks.jpg)
22

33
## React Native Hooks
4+
5+
[![Version][version-badge]][package]
6+
47
React Native APIs turned into React Hooks allowing you to access asynchronous APIs directly in your functional components.
58

69
> Note: You must use React Native >= 0.59.0
@@ -144,3 +147,6 @@ console.log('layout: ', layout)
144147

145148
<View onLayout={onLayout} style={{width: 200, height: 200, marginTop: 30}} />
146149
```
150+
151+
[version-badge]: https://img.shields.io/npm/v/react-native-hooks.svg?style=flat-square
152+
[package]: https://www.npmjs.com/package/react-native-hooks

src/useKeyboard.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@ export default function useKeyboard() {
1010
start: {screenX: 0, screenY: 0, width: 0, height: 0},
1111
end: {screenX: 0, screenY: 0, width: 0, height: 0},
1212
})
13+
const [keyboardHeight, setKeyboardHeight] = useState<number>(0)
1314

1415
const handleKeyboardWillShow: KeyboardEventListener = e => {
1516
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
1617
}
1718
const handleKeyboardDidShow: KeyboardEventListener = e => {
1819
setShown(true)
1920
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
21+
setKeyboardHeight(e.endCoordinates.height)
2022
}
2123
const handleKeyboardWillHide: KeyboardEventListener = e => {
2224
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
2325
}
2426
const handleKeyboardDidHide: KeyboardEventListener = e => {
2527
setShown(false)
2628
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
29+
setKeyboardHeight(0)
2730
}
2831

2932
useEffect(() => {
@@ -55,5 +58,6 @@ export default function useKeyboard() {
5558
return {
5659
keyboardShown: shown,
5760
coordinates,
61+
keyboardHeight,
5862
}
5963
}

0 commit comments

Comments
 (0)