react-native: `KeyboardAvoidingView` do not keep input in view under Android 15 (target SDK 35)

Description

Under RN 0.77.1 and Android 15 with targetSdkVersion = 35, the KeyboardAvoidingView stopped working as expected. In the video below, we can see that clicking on the input brings the keyboard and makes the input disappear under the keyboard. However, just using targetSdkVersion = 34 fixed the issue.

Something is problematic under Android 15 SDK 35 and the KeyboardAvoidingView component.

Steps to reproduce

  1. Create an RN 77 project npx @react-native-community/cli init Rn77App --version 0.77.1
  2. Use an input wrapped in a KeyboardAvoidingView under the scroll view of the example app
  3. Make sure to use targetSdkVersion = 35
  4. Click on the input
  5. The input disappears under the keyboard
  6. Expected: The input moves up and stays in view, like when using targetSdkVersion = 34 or under RN 76

React Native Version

0.77.1

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info

System:
  OS: macOS 15.3
  CPU: (12) arm64 Apple M2 Pro
  Memory: 1.65 GB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.20.4
    path: ~/.nvm/versions/node/v18.20.4/bin/node
  Yarn:
    version: 1.22.22
    path: ~/.nvm/versions/node/v18.20.4/bin/yarn
  npm:
    version: 10.7.0
    path: ~/.nvm/versions/node/v18.20.4/bin/npm
  Watchman:
    version: 2024.11.04.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /Users/dprevost/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.2
      - iOS 18.2
      - macOS 15.2
      - tvOS 18.2
      - visionOS 2.2
      - watchOS 11.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.2 AI-242.23726.103.2422.13016713
  Xcode:
    version: 16.2/16C5032a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.13
    path: /usr/bin/javac
  Ruby:
    version: 3.3.3
    path: /Users/dprevost/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.77.1
    wanted: 0.77.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

None

Reproducer

https://github.com/dprevost-LMI/Rn77App

Screenshots and Videos

The below are from a physical Pixel 9

Working case under RN 76 Non-working case under RN 77 and SDK 35

https://github.com/user-attachments/assets/1463d622-c878-4291-8511-454abcc8b312

https://github.com/user-attachments/assets/1bc84f01-ecea-4ed4-b897-6a1bf378668f

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 18
  • Comments: 24 (5 by maintainers)

Most upvoted comments

The above suggested change works for me too. I had to make that change in MainActivity.kt

import android.os.Build
import android.view.View
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

override fun onCreate(savedInstanceState: Bundle?) {
    RNBootSplash.init(this, R.style.BootTheme)
    super.onCreate(null)
    
    if (Build.VERSION.SDK_INT >= 35) {
        val rootView = findViewById<View>(android.R.id.content)
        ViewCompat.setOnApplyWindowInsetsListener(rootView) { _, insets ->
          val innerPadding = insets.getInsets(WindowInsetsCompat.Type.ime())
          rootView.setPadding(
            innerPadding.left,
            innerPadding.top,
            innerPadding.right,
            innerPadding.bottom
          )
          insets
      }
    }
  }

Since Android API 35, I’ve noticed that adjustResize is no longer sufficient on its own, as described in this article. As an alternative, I set the IME padding manually in Kotlin, like

ViewCompat.setOnApplyWindowInsetsListener(rootView) { _, insets ->
   val innerPadding = insets.getInsets(
     WindowInsetsCompat.Type.ime()
 )
   rootView.setPadding(
     innerPadding.left,
     innerPadding.top,
     innerPadding.right,
     innerPadding.bottom)
   insets
}

Which worked fine. However, I think RN could perhaps handle this IME padding by default in KeyboardAvoidingView? I can make a PR if it’s fine

Sorry for the delayed update. I was able to repro the issue but didn’t have much chance to look into it yet.

If you’re using Expo Managed Workflow and facing this issue on Android 15 (SDK 35), I’ve created an Expo Config Plugin to easily fix this without ejecting or manually editing native code.

You can install and use it directly from npm:

📦 expo-android-keyboard-fix

Installation:

npm install expo-android-keyboard-fix
# or
yarn add expo-android-keyboard-fix

Then add it to your app.json or app.config.js:

{
  "expo": {
    "plugins": ["expo-android-keyboard-fix"]
  }
}

After applying this plugin, your inputs will correctly stay visible when the keyboard opens on Android 15+.

Hope this helps! Let me know if you have any questions. 🚀

@cortinico @alanleedev Hi, any update on this? There’s a fix suggested in the comments that seems to work well. Would it be possible to get this implemented? Thanks!

I’m happy to look for a possible fix and contribute one, if someone can provide a reproducer for the latest main or v0.81.0-rc.1

If you are still facing this issue, check whether the screen is from a stack navigator. Make sure you have wrapped your stack navigator inside a KeyboardAvoidingView, like this:

<KeyboardAvoidingView>
  <Stack.Navigator>...</Stack.Navigator>
</KeyboardAvoidingView>

For those using React Navigation (which I assume includes most of us), this approach might help resolve your KeyboardAvoidingView issues — especially on Android 15.

Do not wrap your individual components with <KeyboardAvoidingView>. Instead, wrap the entire <Tab.Navigator> with it.

Here’s what worked for me:


import { KeyboardAvoidingView, Platform } from 'react-native';

function TabNavigator() {
  return (
    <KeyboardAvoidingView
      behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
      style={{ flex: 1 }}>
      <Tab.Navigator
        screenOptions={{
          headerShown: false,
        }}>
        <Tab.Screen name="Tab" component={StackContainer} />
      </Tab.Navigator>
    </KeyboardAvoidingView>
  );
}
"dependencies": {
    "@react-navigation/elements": "2.4.2",
    "@react-navigation/native": "^7.1.9",
    "@react-navigation/native-stack": "^7.3.13",
}

@dprevost-LMI, yes, sure! But this kind of bugs are hard to debug, so I guess people are coming firstly to ReactNative (myself included). But indeed I think the issue is not directly related to RN repo.

cc @alanleedev Could you briefly look into this one?