文档模板:v0.4.2
react-native-input-scroll-view
English | 简体中文
本项目基于 react-native-input-scroll-view 开发。
该第三方库的仓库已迁移至 GitCode,且支持直接从 npm 下载,新的包名为:@react-native-ohos/react-native-input-scroll-view,版本所属关系如下:
| 三方库名称 | 三方库版本(npm地址) | 发布信息 | 支持RN版本 | Autolink | 编译API版本 | 社区基线版本 | 源码地址 |
|---|---|---|---|---|---|---|---|
| @react-native-ohos/react-native-input-scroll-view | ~1.12.0 | GitCode Releases | 0.77.* | 否 | API12+ | 1.11.0 | br_rnoh0.77 |
| @react-native-ohos/react-native-input-scroll-view | ~1.11.1 | GitCode Releases | 0.72.* | 否 | API12+ | 1.11.0 | br_rnoh0.72 |
| @react-native-oh-tpl/react-native-input-scroll-view | <= 1.11.0-0.0.1@deprecated | GitHub Releases(deprecated) | 0.72.* | 否 | API12+ | 1.11.0 | sig |
简介
react-native-input-scroll-view 是一个 React Native 组件,主要用于解决键盘弹出时遮挡输入框的常见问题。
下载安装
进入到工程目录并输入以下命令:
npm
npm install @react-native-ohos/react-native-input-scroll-view
yarn
yarn add @react-native-ohos/react-native-input-scroll-view
约束与限制
兼容性
本文档内容基于以下版本验证通过:
- RNOH: 0.77.18; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.868; ROM: 6.0.0.112;
权限要求
无特殊权限要求。
使用示例
下面的代码展示了这个库的基本使用场景:
使用时 import 的库名不变。
import React, { useState } from 'react';
import { StyleSheet, TextInput, View } from 'react-native';
import InputScrollView from 'react-native-input-scroll-view';
const keyboardOffsetInput = () => {
const [text, setText] = useState('');
return (
<View style={styles.container}>
<InputScrollView keyboardOffset={100}>
<View style={styles.placeholder} />
<TextInput style={styles.input}
value={text}
multiline
onChangeText={setText}
/>
</InputScrollView>
</View>
);
}
const styles = StyleSheet.create({
container: {
backgroundColor: '#EEE',
},
placeholder: {
height: 400,
justifyContent: 'center',
alignItems: 'center',
},
input: {
margin: 20,
paddingVertical: 10,
paddingHorizontal: 20,
borderColor: 'gray',
borderWidth: 1,
backgroundColor: '#FFF',
},
});
export default keyboardOffsetInput;
接口说明
"Platform"列表示该属性在原三方库上支持的平台。
"OpenHarmony Support"列为 yes 表示 OpenHarmony平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
组件
| 名称 | 参数类型 | 必填 | 平台 | OpenHarmony平台支持 | 描述 |
|---|---|---|---|---|---|
| InputScrollView | InputScrollViewProps | no | All | Yes | 键盘自适应滚动容器组件,基于 ScrollView 封装,自动将输入框滚动到键盘上方 |
属性
| 名称 | 参数类型 | 默认值 | 必填 | 平台 | OpenHarmony平台支持 | 描述 |
|---|---|---|---|---|---|---|
| topOffset | Number | — | no | All | Yes | InputScrollView 相对于窗口顶部的偏移量。当屏幕包含 TopBar 时,通常设置为 TopBar 的高度。如果未明确设置,程序会自动判断,但可能会引起问题 issues#43 |
| keyboardOffset | Number | 40 | no | All | Yes | 当自动调整时,光标相对于键盘顶部的偏移量 |
| multilineInputStyle | Style | — | no | All | Yes | 如果多行输入框有特定样式,为了光标能够精准调整到键盘上方,应将多行文本的样式也设置在这里,主要包含 fontSize、fontFamily、lineHeight 等会影响到光标位置的样式属性。注意,不要包含 width 和 height |
| useAnimatedScrollView | Boolean | false | no | All | Yes | 用 Animated.ScrollView 组件替换 ScrollView 组件 |
| supportHardwareKeyboard | Boolean | false | no | All | Yes | (beta)如果设备不使用软键盘,可以尝试使用此参数解决问题 issues#69 |
| keyboardAvoidingViewProps | Props | — | no | All | Yes | KeyboardAvoidingView 组件的 Props,详细请查阅 RN 官方文档 KeyboardAvoidingView 章节 |
| ...ScrollView.props | Props | — | no | All | Yes | 继承 ScrollView 组件的所有属性,详细请查阅 RN 官方文档 ScrollView 章节 |
遗留问题
无
其他
无
目录结构
/react-native-input-scroll-view # 项目根目录
├── index.js # 组件入口,InputScrollView 实现
├── index.d.ts # TypeScript 类型声明
├── __test__ # 原库 Android/iOS 测试工程(用于对照基线行为)
├── images # 示例图与动图
├── LICENSE # 开源协议文件
├── README.md # 中文安装使用方法
├── README_en.md # 英文安装使用方法
└── package.json # 包配置
贡献代码
使用过程中发现任何问题都可以提交 Issue,当然,也非常欢迎提交 PR 。
开源协议
本项目基于 The MIT License (MIT) ,请自由地享受和参与开源。