Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…hooks into chore/addEslint
  • Loading branch information
Naturalclar committed Feb 3, 2020
2 parents cafaaa6 + a30f739 commit 59e7b01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
![React Native Hooks](reactnativehooks.jpg)

## React Native Hooks

[![Version][version-badge]][package]

React Native APIs turned into React Hooks allowing you to access asynchronous APIs directly in your functional components.

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

<View onLayout={onLayout} style={{width: 200, height: 200, marginTop: 30}} />
```

[version-badge]: https://img.shields.io/npm/v/react-native-hooks.svg?style=flat-square
[package]: https://www.npmjs.com/package/react-native-hooks
4 changes: 4 additions & 0 deletions src/useKeyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ export default function useKeyboard() {
start: {screenX: 0, screenY: 0, width: 0, height: 0},
end: {screenX: 0, screenY: 0, width: 0, height: 0},
})
const [keyboardHeight, setKeyboardHeight] = useState<number>(0)

const handleKeyboardWillShow: KeyboardEventListener = e => {
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
}
const handleKeyboardDidShow: KeyboardEventListener = e => {
setShown(true)
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
setKeyboardHeight(e.endCoordinates.height)
}
const handleKeyboardWillHide: KeyboardEventListener = e => {
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
}
const handleKeyboardDidHide: KeyboardEventListener = e => {
setShown(false)
setCoordinates({start: e.startCoordinates, end: e.endCoordinates})
setKeyboardHeight(0)
}

useEffect(() => {
Expand Down Expand Up @@ -55,5 +58,6 @@ export default function useKeyboard() {
return {
keyboardShown: shown,
coordinates,
keyboardHeight,
}
}

0 comments on commit 59e7b01

Please sign in to comment.