# react-native-use-keyboard

> A versatile and lightweight React Native hook for responsive keyboard handling. This hook provides real-time keyboard visibility and height information, supports customizable events, debounce handling for performance optimization, and is adaptable to orie

Latest version **1.1.0** (published 2025-01-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-use-keyboard
pnpm add react-native-use-keyboard
yarn add react-native-use-keyboard
bun add react-native-use-keyboard
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2025-01-19 |
| First published | 2023-12-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | softwarewizard.dev |
| Maintainers | kurucaner |
| Keywords | react-native, react, react-hook, keyboard, keyboard-height, keyboard-visibility |

## Links

- npm: https://www.npmjs.com/package/react-native-use-keyboard
- Repository: https://github.com/kurucaner/react-native-use-keyboard
- Homepage: https://github.com/kurucaner/react-native-use-keyboard#readme
- Issues: https://github.com/kurucaner/react-native-use-keyboard/issues
- npm.io page: https://npm.io/package/react-native-use-keyboard

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2025-01-19
- 1.0.0 — 2023-12-09

## README

# `useKeyboard` Hook

## Overview

The **`useKeyboard`** hook is designed for React Native applications to easily manage and respond to keyboard events. It provides information about the keyboard's visibility and height, which can be used to adjust the layout or behavior of your application when the keyboard is shown or hidden.

## Features

- 🎯 Real-time keyboard visibility tracking
- 📏 Accurate keyboard height measurements
- 🔄 Platform-specific event handling (iOS & Android)
- ⚙️ Customizable keyboard events
- 🪶 Lightweight with zero dependencies
- 💪 Written in TypeScript with full type support

## Installation

```bash
npm install react-native-use-keyboard
# or
yarn add react-native-use-keyboard
# or
pnpm install react-native-use-keyboard
# or
bun install react-native-use-keyboard
```

## Usage

```tsx
import { useKeyboard } from "react-native-use-keyboard";

const MyComponent = () => {
  const { isVisible, height } = useKeyboard();

  return (
    <View style={{ flex: 1 }}>
      <View style={{ flex: 1 }}>
        <Text>My Component</Text>
      </View>
      {isVisible && (
        <View style={{ height }}>
          <Text>Keyboard is visible</Text>
        </View>
      )}
    </View>
  );
};
```

### With Custom Events

```tsx
const MyComponent = () => {
  const { isVisible, height } = useKeyboard({
    show: "keyboardDidShow", // custom show event
    hide: "keyboardDidHide", // custom hide event
  });
  // ... rest of your component
};
```

## API

### `useKeyboard(customEvents?: CustomEvents): KeyboardInfo`

#### Parameters

- `customEvents` (optional): An object to customize the keyboard event names.
  - `show`: A `KeyboardEventName` to specify a custom event name for keyboard show events
  - `hide`: A `KeyboardEventName` to specify a custom event name for keyboard hide events

#### Return Value

Returns an object with:

- `isVisible`: `boolean` - Indicates if the keyboard is currently visible
- `height`: `number` - Current height of the keyboard in pixels (0 when hidden)

## Platform Specific Behavior

By default, the hook uses different events for iOS and Android:

- **iOS**: Uses 'keyboardWillShow' and 'keyboardWillHide'
- **Android**: Uses 'keyboardDidShow' and 'keyboardDidHide'

## Common Use Cases

### Adjusting Screen Content

```tsx
const MyScreen = () => {
  const { isVisible, height } = useKeyboard();

  return (
    <View style={{ flex: 1 }}>
      <ScrollView
        contentContainerStyle={{
          paddingBottom: isVisible ? height : 0,
        }}
      >
        {/* Your content */}
      </ScrollView>
    </View>
  );
};
```

### Animating Views with Keyboard

```tsx
const MyAnimatedComponent = () => {
  const { isVisible, height } = useKeyboard();
  const translateY = useRef(new Animated.Value(0)).current;

  useEffect(() => {
    Animated.timing(translateY, {
      toValue: isVisible ? -height : 0,
      duration: 250,
      useNativeDriver: true,
    }).start();
  }, [isVisible, height]);

  return (
    <Animated.View style={{ transform: [{ translateY }] }}>
      {/* Your content */}
    </Animated.View>
  );
};
```

## Requirements

- React Native >= 0.60.0
- React >= 16.8.0 (Hooks support)

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

MIT

---
_Source: https://npm.io/package/react-native-use-keyboard · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
