react / react/react-native

Android: Keyboard.addListener returns incorrect height when switching between different keyboard types

オープン
#52,600 コメント 8 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

API: Keyboard Component: Switch Needs: Attention Needs: Repro Needs: Version Info Platform: Android
主要言語
C++
スター
127k
フォーク
25.3k
平均マージ
1日 23時間
マージ済み PR(30日)
4

説明

Description

When switching between different keyboard types on Android, Keyboard.addListener events and Keyboard.metrics()?.height return the height of the previous keyboard instead of the current one. This issue occurs consistently when the previous and current keyboards have different heights (e.g., switching from numeric keyboard to password keyboard, or from system security keyboard to regular keyboard). The problem affects both event callback heights and the static Keyboard.metrics()?.height value. The issue resolves itself on the next keyboard opening, but can be stably reproduced by switching between different keyboard types.

Steps to reproduce

Steps to reproduce the behavior:

  1. Open an app with text inputs on Android device
  2. Focus on a text input with keyboardType: 'numeric'
  3. Note the keyboard height (e.g., 300px)
  4. Switch to another text input with keyboardType: 'visible-password'
  5. Observe that both Keyboard.addListener events and Keyboard.metrics()?.height return the previous keyboard's height (300px) instead of the current keyboard's height
  6. Close and reopen the keyboard - the issue resolves and correct height is returned
React Native Version

0.78

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info
System:
  OS: macOS 15.3.1
  CPU: (10) arm64 Apple M4
  Memory: 153.83 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 23.11.0
    path: /opt/homebrew/bin/node
  Yarn:
    version: 1.22.22
    path: ~/app/Systech_HX_App/node_modules/.bin/yarn
  npm:
    version: 10.9.2
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2025.04.28.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.4
      - iOS 18.4
      - macOS 15.4
      - tvOS 18.4
      - visionOS 2.4
      - watchOS 11.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.3 AI-243.25659.59.2432.13423653
  Xcode:
    version: 16.3/16E140
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.15
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/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
Stacktrace or Logs
..
MANDATORY Reproducer

https://github.com/facebook/react-native/

Screenshots and Videos

No response

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、キーボードタイプが numeric と visible-password の入力を使って Android で問題を再現し、その後 Keyboard.addListener と Keyboard.metrics() の背後にある実装を調べます。キーボードを切り替えたときとキーボードを再度開いたときに報告される高さを確認します。イベントコールバックとメトリクスの両方が現在のキーボードの高さを報告すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
android
領域
mobile
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。