How To Use both 'adjustPan' and 'adjustResize' for 'windowSoftInputMode' in React Native Android app

前端 未结 1 1896
自闭症患者
自闭症患者 2021-02-18 18:21

How can I use both \'adjustPan\' and \'adjustResize\' in AndroidManifest.xml react native app.

Use Case

My navigation is made upon ReactNavigation with StackNa

相关标签:
1条回答
  • 2021-02-18 19:04

    I found an npm package called react-native-android-keyboard-adjust, which allows us to switch the windowSoftInputMode on demand, this should be able to cater for your use case. However, the library seems to be not actively maintained and the installation documentation is a little bit out of date but for the most part, you can follow the instructions given by the README.md.

    For the Update MainActivity.java in your project part, the recent versions of React Native should be able to auto-link the dependencies and there is no need to do this modification manually.

    After the above steps, you can try to start your app. If you encountered an error related to something like The number of method references in a .dex file cannot exceed 64k, you can add the followings to your android/app/build.gradle file

    android {
        ...
    
        defaultConfig {
            ...
            multiDexEnabled true
        }
    
        ...
    }
    

    After installing the package, you can call the methods provided by the library to change the windowSoftInputMode as you need.

    For example, assuming you have a default windowSoftInputMode of adjustResize, and you want to use adjustPan within ScreenA, you can call AndroidKeyboardAdjust.setAdjustPan() when ScreenA mount, and reset the windowSoftInputMode to adjustResize on unmount by calling AndroidKeyboardAdjust.setAdjustResize()

    0 讨论(0)
提交回复
热议问题