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

中文文档
2.4.0发布于 2022/01/28MITTypeScriptCommonJS零依赖近 30 天下载 6825

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

此软件包已被标记为弃用

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

原始使用文档
文档目录6 节
  1. Getting Started
  2. Usage
  3. Handling wrong offsets
  4. Props
  5. KeyboardAccessoryView
  6. License

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 } from '@flyerhq/react-native-keyboard-accessory-view'
import { GestureResponderHandlers } from 'react-native'
// ...
const renderScrollable = (panHandlers: GestureResponderHandlers) => (
  // Can be anything scrollable
  <ScrollView keyboardDismissMode='interactive' {...panHandlers} />
)
// ...
return (
  <KeyboardAccessoryView renderScrollable={renderScrollable}>
    // Your accessory view
  </KeyboardAccessoryView>
)

Handling wrong offsets

Sometimes when you use a tab bar or similar component, the accessory view does not work correctly. In order to fix this, you need to use a combination of next props: contentContainerStyle, contentOffsetKeyboardClosed, contentOffsetKeyboardOpened and spaceBetweenKeyboardAndAccessoryView.

First of all, you need to decide if you need this extra safe area margin at the bottom (as you can see the size of the accessory view is different when the keyboard is open and closed, that's because when it's closed, safe area bottom margin is added). If you have, for example, a tab bar, most likely you don't need this margin, because safe is area already occupied by the tab bar. To remove it pass this style: contentContainerStyle={{ marginBottom: 0 }}.

When the first step is done, you need to check if you have a space between the accessory view and the keyboard, when the latter is opened. If you do, pass the offset to the spaceBetweenKeyboardAndAccessoryView prop. Usually, it can be calculated based on a bottom safe area inset from react-native-safe-area-context and/or the height of the tab bar, for example.

Lastly, validate if the content above the accessory view has correct offsets, if no, you can adjust it using contentOffsetKeyboardClosed and contentOffsetKeyboardOpened props. Sometimes offsets are correct for the one keyboard state, use one of these props if this is the case. As with the spaceBetweenKeyboardAndAccessoryView prop, offsets are calculated based on the bottom safe area inset and/or the height of the tab bar, for example.

Props

KeyboardAccessoryView

  • renderScrollable (required) - accepts a ReactNode. Your scrollable component.

  • style (optional) - accepts View Style Props. Use 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. Use to style the content container, but not the safe area insets.

  • contentOffsetKeyboardClosed (optional) - accepts a number. Use to adjust content offset when the keyboard is open. Read more here.

  • contentOffsetKeyboardOpened (optional) - accepts a number. Use to adjust content offset when the keyboard is closed. Read more here.

  • renderBackground (optional) - accepts a function returning React node. This is useful when you want to have a custom node as a background (e.g. <ImageBackground style={StyleSheet.absoluteFill} /> ). Remember about absolute positioning.

  • scrollableContainerStyle (optional) - accepts View Style Props. Use to style the container wrapping a scrollable component passed in renderScrollable. In case you want scrollable to fill the entire container try passing flex: 1 here.

  • spaceBetweenKeyboardAndAccessoryView (optional) - accepts a number. Use to adjust space between the accessory view and the keyboard, when the latter is open. Read more here.

  • useListenersOnAndroid (optional) - accepts a boolean. By default, Android OS will resize the window when the keyboard is open and accessory view will automatically be positioned above the keyboard. This behavior can be amended, so if for some reason accessory view doesn't appear on top of the keyboard, try setting this prop, it will calculate the content height based on a keyboard listener. Has no impact on iOS.

License

MIT

版本与发布记录

@flyerhq/react-native-keyboard-accessory-view 共发布 30 个版本,首次发布于 2020/06/02;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.4.0latest2022/01/284 年前
2.3.32021/10/245 年前
2.3.22021/09/065 年前
2.3.12021/08/225 年前
2.3.02021/08/195 年前
2.2.22021/08/175 年前

关于 @flyerhq/react-native-keyboard-accessory-view 的常见问题

@flyerhq/react-native-keyboard-accessory-view 是什么?

Keyboard accessory (sticky) view for your React Native app. Supports interactive dismiss on iOS.注意:该包已被作者标记为弃用——Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

如何安装 @flyerhq/react-native-keyboard-accessory-view?

在项目目录运行 npm install @flyerhq/react-native-keyboard-accessory-view,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(*)、react-native(*)、react-native-safe-area-context(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@flyerhq/react-native-keyboard-accessory-view 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@flyerhq/react-native-keyboard-accessory-view 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@flyerhq/react-native-keyboard-accessory-view 可以商用吗?

@flyerhq/react-native-keyboard-accessory-view 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@flyerhq/react-native-keyboard-accessory-view 的下载量有多少?

根据 npm 官方下载统计,@flyerhq/react-native-keyboard-accessory-view 在 2026/10/15 – 2026/11/13 这 30 天内被下载 6,825 次,日均约 228 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flyerhq/react-native-keyboard-accessory-view 还在维护吗?

最新版本 2.4.0 发布于 2022/01/28(4 年前);至今共发布 30 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/06/02。作者已将其标记为弃用,新项目建议寻找替代方案。