@rnhooks/keyboard
Version:
React Native Hook for Keyboard
58 lines (42 loc) • 1.96 kB
Markdown
# /keyboard [](https://travis-ci.com/react-native-hooks/keyboard) [](https://codeclimate.com/github/react-native-hooks/keyboard/maintainability)
> React Native hook for [keyboard](https://facebook.github.io/react-native/docs/keyboard#docsNav)
### Installation
```bash
yarn add /keyboard
```
> **Note**
>
> `v1.0.0` and above is only supported on `react-native >= 0.65`, for older `react-native` use the older release.
### Usage
```js
import useKeyboard from '/keyboard';
function App() {
const [visible, dismiss] = useKeyboard();
return (
<View style={styles.container}>
<Text style={styles.welcome}>/keyboard</Text>
<Text style={styles.instructions}>{visible ? 'Keyboard Visible' : 'Keyboard Not Visible'}</Text>
<Button title="Dismiss Keyboard" onPress={dismiss} />
</View>
);
}
```
### Configuration
If you like, you can configure the hook to use the `will` events instead of the
`did` events (by default, it uses the `did` events). This is useful in cases
where you want to trigger an animation before the keyboard begins dismissing:
```js
useKeyboard({
useWillShow: true,
useWillHide: true,
})
```
| Name | Default | Type | Description |
| ----------- | ------- | -------:| ----------------------------------------- |
| useWillShow | `false` | boolean | Use the `keyboardWillShow` event instead. |
| useWillHide | `false` | boolean | Use the `keyboardWillHide` event instead. |
### Output
| Name | Default | Type | Description |
| ------- | ------------------- | --------:| ------------------- |
| visible | `false` | boolean | Keyboard Visibility |
| dismiss | `Keyboard.dismiss` | function | Dismiss Keyboard |