react-native-keyboard-avoid
Component that handles keyboard appearance and automatically make any component node to keep out keyboard.
Work with TextInput
,View
and so on.
Supported versions
v1.0.0
requiresRN>=0.20
Installation
Installation can be done through npm
or yarn
:
npm i react-native-keyboard-avoid --save
yarn add react-native-keyboard-avoid
Usage
You just need use this KeyboardAvoid
on whatever you want to keep out from native keyboard view.
It accept ScrollView
, ListView
, FlatList
and any other View
component. There will show you 3 example.
ScrollView
or ListView
, FlatList
1.With something in
; { KeyboardAvoid;}
<ScrollView = = = => <View => <TextInput = = = =/> <Button =>Search</Button> </View></ScrollView> or <FlatList = =/>
2.With component which use position: 'absolute'
; { thisaTextInput; KeyboardAvoid;}
<View = => <TouchableOpacity => <Text =>浮低</Text> </TouchableOpacity></View>
3.With two components one use position and one use scroll
; { KeyboardAvoid; KeyboardAvoid;}
Methods
Method | Parameter | Description |
---|---|---|
checkNeedScroll |
(params, type='scroll', offset=0) |
Get ScrollResponder |
unMount |
none | unMount this handler while app view unMount |
API
KeyboardAvoid.checkNeedScroll(params, type='scroll', offset=0)
Prame
params {object}
Prop | Type | Description |
---|---|---|
nodeRef |
Node Ref | ref of the component which need to avoid from keyboard |
scrollNodeRef |
Node Ref | ref of scroll component |
contentOffset |
Node Ref | scrolloffset.y of scroll component |
type {string}
value | Description |
---|---|
scroll |
Such as example 1. keyboard avoid in ScrollView or ListView , FlatList |
position |
Such as example 2. keyboard avoid with position |
offset {number}
target offset from the top of keyboard
onScroll={(event) => {this.contentOffset = event.nativeEvent.contentOffset.y}}