Skip to content

Latest commit

 

History

History
56 lines (44 loc) · 1.29 KB

File metadata and controls

56 lines (44 loc) · 1.29 KB

react-native-use-keyboard-height

a simple hook to get keyboard height while it's shown in react-native

Demo

Installation

npm install react-native-use-keyboard-height

Usage

import React from 'react';
import { StyleSheet, View, Text, TextInput } from 'react-native';
import useKeyboardHeight from 'react-native-use-keyboard-height';

export default function App() {
  const keyboardHeight = useKeyboardHeight(); // both ios and android
  // const keyboardHeight = useKeyboardHeight(['ios', 'android']); // both ios and android
  // const keyboardHeight = useKeyboardHeight(['ios']); // only ios
  // const keyboardHeight = useKeyboardHeight(['android']); // only android
  return (
    <View style={styles.container}>
      <Text>Current Keyboard Height: {keyboardHeight}</Text>
      <TextInput style={styles.input}></TextInput>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  input: {
    width: 300,
    height: 50,
    borderWidth: 1,
    borderColor: 'grey',
    textAlign: 'center',
    marginTop: 10,
  },
});

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT