react原生输入滚动视图
Access rate limit exceeded. Please log in to continue.
Doc template: v0.4.2
react-native-input-scroll-view
English | 简体中文
This project is developed based on react-native-input-scroll-view.
The repository of this third-party library has been migrated to GitCode and can be downloaded directly from npm. The new package name is: @react-native-ohos/react-native-input-scroll-view. The version mapping is as follows:
| Third-party library name | Third-party library version (npm address) | Release information | Supported RN version | Autolink | Compilation API version | Community baseline version | Source code address |
|---|---|---|---|---|---|---|---|
| @react-native-ohos/react-native-input-scroll-view | ~1.12.0 | GitCode Releases | 0.77.* | No | API12+ | 1.11.0 | br_rnoh0.77 |
| @react-native-ohos/react-native-input-scroll-view | ~1.11.1 | GitCode Releases | 0.72.* | No | 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.* | No | API12+ | 1.11.0 | sig |
Introduction
react-native-input-scroll-view is a React Native component mainly used to solve the common problem of input fields being obscured by the keyboard when it pops up.
Download and Installation
Enter the project directory and run the following command:
npm
npm install @react-native-ohos/react-native-input-scroll-view
yarn
yarn add @react-native-ohos/react-native-input-scroll-view
Constraints and Limitations
Compatibility
The content of this document has been verified based on the following versions:
- RNOH: 0.77.18; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.868; ROM: 6.0.0.112;
Permission Requirements
No special permission is required.
Usage Example
The following code demonstrates the basic usage scenarios of this library:
The library name in the import statement remains unchanged.
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;
API Description
The "Platform" column indicates the platforms supported by the original third-party library.
The "OpenHarmony Support" column: yes means the OpenHarmony platform supports this property; no means it is not supported; partially means it is partially supported. The usage is consistent across platforms, and the effect is aligned with iOS or Android.
Component
| Name | Parameter type | Required | Platform | OpenHarmony Support | Description |
|---|---|---|---|---|---|
| InputScrollView | InputScrollViewProps | no | All | Yes | Keyboard-adaptive scroll container component based on ScrollView that automatically scrolls the input field above the keyboard |
Properties
| Name | Parameter type | Default value | Required | Platform | OpenHarmony Support | Description |
|---|---|---|---|---|---|---|
| topOffset | Number | — | no | All | Yes | Offset of the InputScrollView relative to the top of the window. When the screen contains a TopBar, it is usually set to the height of the TopBar. If not set explicitly, the program will determine it automatically, but problems may occur issues#43 |
| keyboardOffset | Number | 40 | no | All | Yes | Offset of the cursor relative to the top of the keyboard during automatic adjustment |
| multilineInputStyle | Style | — | no | All | Yes | If your multiline input has specific styles, set the multiline text styles here so that the cursor can be precisely adjusted above the keyboard, mainly including style properties that affect the cursor position such as fontSize, fontFamily and lineHeight. Note: do not include width and height |
| useAnimatedScrollView | Boolean | false | no | All | Yes | Replaces the ScrollView component with the Animated.ScrollView component |
| supportHardwareKeyboard | Boolean | false | no | All | Yes | (beta) If your device does not use a soft keyboard, try this property to solve the problem issues#69 |
| keyboardAvoidingViewProps | Props | — | no | All | Yes | Props of the KeyboardAvoidingView component; see the KeyboardAvoidingView section of the official RN docs for details |
| ...ScrollView.props | Props | — | no | All | Yes | Inherits all props of the ScrollView component; see the ScrollView section of the official RN docs for details |
Known Issues
None
Others
None
Directory Structure
/react-native-input-scroll-view # Project root directory
├── index.js # Component entry, InputScrollView implementation
├── index.d.ts # TypeScript type declarations
├── __test__ # Original Android/iOS test projects of the upstream library (for baseline comparison)
├── images # Sample images and GIFs
├── LICENSE # Open source license file
├── README.md # Chinese installation and usage instructions
├── README_en.md # English installation and usage instructions
└── package.json # Package configuration
Contributing
If you encounter any problems during usage, you are welcome to submit an Issue. Of course, PRs are also highly welcomed.
Open Source License
This project is based on The MIT License (MIT). Please feel free to enjoy and participate in open source.