KeyboardAvoidingView not Working Properly

前端 未结 14 2418
悲&欢浪女
悲&欢浪女 2020-12-02 08:51

KeyboardAvoidingView not Working Properly

I am trying to use the KeyboardAvoidingView with behavior="padding".

For some reason, when I

14条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 09:41

    This is a known issue with KeyboardAvoidingView and Android. There are multiple ways to address this issue.

    React Native documentation says:

    Android may behave better when given no behavior prop at all, whereas iOS is the opposite.

    So, if you are working only with Android you may remove behavior prop and it should work straight away. For best results add android:windowSoftInputMode="adjustResize" to your Manifest.

    Alternatively you can give an offset value that works for you something like this: KeyboardAvoidingView keyboardVerticalOffset={-500} behavior="padding"

    For ios do the same thing conditionally:

    behavior= {(Platform.OS === 'ios')? "padding" : null}

    keyboardVerticalOffset={Platform.select({ios: 0, android: 500})}

提交回复
热议问题