一个处理键盘出现并自动滚动到获得焦点的 TextInput 的 ScrollView 组件。
一个处理键盘出现并自动滚动到获得焦点的 TextInput 的 ScrollView 组件。
一个 ScrollView 组件,可处理键盘出现事件并自动滚动到获得焦点的 TextInput。
v0.4.0 需要 RN>=0.48v0.2.0 需要 RN>=0.32.0。v0.1.2 需要 RN>=0.27.2,但你应该使用 0.2.0,以便在多个滚动视图中正常工作。v0.0.7 需要 React-native>=0.25.0。v0.0.6。可以通过 npm 或 yarn 进行安装:
npm i react-native-keyboard-aware-scroll-view --saveyarn add react-native-keyboard-aware-scroll-view你可以使用 KeyboardAwareScrollView、KeyboardAwareSectionList 或 KeyboardAwareFlatList
组件。它们分别接受 ScrollView、SectionList 和 FlatList 的默认属性,并
实现了一个名为 KeyboardAwareHOC 的自定义高阶组件来处理键盘的出现。
如果你想在其他任何组件中使用,这个高阶组件也可以单独使用。
导入 React-native-keyboard-aware-scroll-view 并将你的内容包裹在
其中:
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'<KeyboardAwareScrollView>
<View>
<TextInput />
</View>
</KeyboardAwareScrollView>TextInput 字段中自动滚动从 v0.1.0 开始,该组件会自动滚动到获得焦点的 TextInput。对于 v0.0.7 及更早的版本,你可以按照以下方法操作。
TextInput为了滚动到任意 TextInput 字段,你可以使用内置方法 scrollToFocusedInput。示例:
_scrollToInput (reactNode: any) {
// Add a 'scroll' ref to your ScrollView
this.scroll.props.scrollToFocusedInput(reactNode)
}<KeyboardAwareScrollView
innerRef={ref => {
this.scroll = ref
}}>
<View>
<TextInput
onFocus={(event: Event) => {
// `bind` the function if you're using ES6 classes
this._scrollToInput(ReactNative.findNodeHandle(event.target))
}}
/>
</View>
</KeyboardAwareScrollView>还有另一种 b
暂无开放 Issues,或尚未同步最近议题。