Coder Social home page Coder Social logo

lucasfeijo / react-native-keyboard-accessory-view Goto Github PK

View Code? Open in Web Editor NEW

This project forked from flyerhq/react-native-keyboard-accessory-view

0.0 0.0 0.0 748 KB

Keyboard accessory (sticky) view for your React Native app. Supports interactive dismiss on iOS.

License: MIT License

JavaScript 5.15% Java 21.58% Starlark 1.86% Ruby 16.01% Swift 5.60% Objective-C 0.62% TypeScript 49.17%

react-native-keyboard-accessory-view's Introduction

React Native Keyboard Accessory View

npm build Maintainability Test Coverage type-coverage

Keyboard accessory (sticky) view for your React Native app. Supports interactive dismiss on iOS, respects safe area and works in both portrait and landscape, on both iOS and Android.

keyboard-accessory-view

Getting Started

This library depends on react-native-safe-area-context. If you use React Navigation you probably already have it in your dependencies, so you're good to go. If not, please follow the instructions here to install it. Then run:

yarn add @flyerhq/react-native-keyboard-accessory-view

Usage

import {
  KeyboardAccessoryView,
  usePanResponder,
} from '@flyerhq/react-native-keyboard-accessory-view'
// ...
const { panHandlers, positionY } = usePanResponder()
const [contentBottomInset, setContentBottomInset] = useState(0)
// ...
return (
  <>
    // Can be anything scrollable
    <ScrollView
      contentContainerStyle={{
        paddingBottom: contentBottomInset,
      }}
      keyboardDismissMode='interactive'
      scrollIndicatorInsets={{ bottom: contentBottomInset }}
      {...panHandlers}
    />
    <KeyboardAccessoryView
      onContentBottomInsetUpdate={setContentBottomInset}
      panResponderPositionY={positionY}
    >
      // Your accessory view
    </KeyboardAccessoryView>
  </>
)

Let's break it down.

usePanResponder is used to track a finger position on a screen and to adjust KeyboardAccessoryView bottom position to go with a keyboard interactive dismiss. Under the hood, it creates PanResponder which tracks the Y position. It returns this position and panHandlers which should be spread under anything scrollable (e.g. ScrollView, FlatList). On Android, an empty object is returned in panHandlers since we don't have interactive dismiss and don't want to add unnecessary responders.

KeyboardAccessoryView optionally accepts panResponderPositionY returned from the usePanResponder hook. If you don't provide this value, the accessory view will not stick to the keyboard during interactive dismiss, but it will still work correctly on keyboard show/hide events. If you don't need interactive dismiss support you don't need to provide panResponderPositionY and use usePanResponder hook.

Additionally, KeyboardAccessoryView provides a onContentBottomInsetUpdate callback which can be used to position scrollable content above the keyboard.

Props

KeyboardAccessoryView

  • style (optional) - accepts View Style Props. Used to style the view which includes both content container and safe area insets. A common use case will be setting backgroundColor so the content container and safe area insets are of the matching color.

  • contentContainerStyle (optional) - accepts View Style Props. Used to style the content container, but not the safe area insets.

  • onContentBottomInsetUpdate (optional) - accepts a function with a number parameter. See the description above.

  • panResponderPositionY (optional) - accepts a number. See the description above.

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.