react / react/react-native

KeyboardAvoidingView Leaves Extra Bottom Padding After Keyboard Closes

Offen
#52,596 30 Kommentare 60 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

API: Keyboard Component: KeyboardAvoidingView Issue: Author Provided Repro
Vorherrschende Sprache
C++
Sterne
127k
Forks
25.3k
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
4

Beschreibung

Description
Description

When using KeyboardAvoidingView with behavior="height" on Android in combination with SafeAreaView and useSafeAreaInsets(), remains even after the keyboard closes, leaving an unexpected gap at the bottom of the screen. This issue is more visible on Android devices without soft navigation buttons.

This behavior is inconsistent with iOS, where the padding collapses as expected.

Expected Behavior
When the keyboard closes, the layout should return to its original state, removing any bottom padding unless explicitly added by the developer.

Actual Behavior
After the keyboard closes on Android, an extra bottom padding remains on the screen, pushing up content unnecessarily.
Removing paddingBottom: insets.bottom fixes it, but this breaks devices with safe area (iOS or gesture nav Android) where insets are needed.

Steps to reproduce
Steps To Reproduce
  1. Create a SafeAreaView wrapping a KeyboardAvoidingView (behavior="height").
  2. Inside, render a FlatList and an input box pinned to the bottom.
  3. Open keyboard → input shifts correctly.
  4. Close keyboard → padding remains, leaving gap at bottom.

<SafeAreaView style={{flex: 1}}> <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : 'height'} style={{ flex: 1, paddingTop: insets.top, }}> <View style={[ {flex: 1}, theme == 'dark' ? {backgroundColor: AppTheme.dark.screenBackground} : {backgroundColor: AppTheme.light.screenBackground}, ]}> </View> </KeyboardAvoidingView> </SafeAreaView>

React Native Version

0.78.0

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info
info Fetching system and libraries information...
System:
  OS: macOS 15.5
  CPU: (8) arm64 Apple M2
  Memory: 151.19 MB / 8.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.14.0
    path: ~/.nvm/versions/node/v20.14.0/bin/node
  Yarn:
    version: 4.8.1
    path: ~/.nvm/versions/node/v20.14.0/bin/yarn
  npm:
    version: 10.7.0
    path: ~/.nvm/versions/node/v20.14.0/bin/npm
  Watchman:
    version: 2025.04.28.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /Users/socon/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.5
      - iOS 18.5
      - macOS 15.5
      - tvOS 18.5
      - visionOS 2.5
      - watchOS 11.5
  Android SDK:
    API Levels:
      - "33"
      - "34"
      - "35"
    Build Tools:
      - 30.0.3
      - 34.0.0
      - 35.0.0
      - 35.0.1
      - 36.0.0
    System Images:
      - android-28 | Google ARM64-V8a Play ARM 64 v8a
      - android-29 | Google Play ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
      - android-36 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.3 AI-243.26053.27.2432.13536105
  Xcode:
    version: 16.4/16F6
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.11
    path: /usr/bin/javac
  Ruby:
    version: 3.2.2
    path: /Users/socon/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.78.0
    wanted: 0.78.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

info React Native v0.80.1 is now available (your project is running on v0.78.0).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.80.1
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.78.0&to=0.80.1
info For more info, check out "https://reactnative.dev/docs/upgrading?os=macos".
Stacktrace or Logs
No Crash Happened
MANDATORY Reproducer

NONE

Screenshots and Videos

When Keyboard is Opened it is ok
but when it is closed getting a extra padding below

Image Image Image

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der in der Issue beschriebenen Reproduktion von KeyboardAvoidingView und SafeAreaView unter Android mit behavior="height" und useSafeAreaInsets(). Verfolge die Änderungen des Android-Layouts, wenn die Tastatur geöffnet und geschlossen wird. Als erledigt gilt die Aufgabe, wenn das untere Padding nach dem Schließen wieder in seinen ursprünglichen Zustand zurückkehrt, ohne die Safe-Area-Behandlung auf Geräten mit Gesten-Navigation oder unter iOS zu beeinträchtigen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
android, javascript, react-native
Bereich
frontend, mobile
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.