react / react/react-native

`KeyboardAvoidingView` infinitely updates on Android

未关闭
#45,192 11 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

API: Keyboard Component: KeyboardAvoidingView Issue: Author Provided Repro Platform: Android Resolution: PR Submitted
主要语言
C++
星标
127k
派生
25.3k
平均合并
1 天 23 小时
30 天内合并 PR
4

描述

Description

The bottom state of the KeyboardAvoidingView component infinitely updates on Android. This is visible when inspecting KeyboardAvoidingView's state in React Native DevTools, it continuously changes value. Or when a component is rendered just above the keyboard, it flickers and/or bounces up and down.

Steps to reproduce
Prerequisites
  1. App from reproducer repo is built and open. Reproduction 1 is on branch example-1. Reproduction 2 is on branch example-2. For each branch, checkout, yarn install then yarn android.
  2. React Native DevTools is running.
Reproduction 1

Reproduction 1 is a text input and footer fixed to the bottom wrapped in a KeyboardAvoidingView. While the bottom state changes, the change is so small (<1 px) that it is not noticeable in the UI.

Steps
  1. Inspect KeyboardAvoidingView in the React Native DevTools.
  2. Focus on text input in app.
  3. Check bottom state in DevTools.
  4. Unfocus text input in app.
  5. Check bottom state in DevTools.
Expected behaviour

The bottom state should not continuously change.

Actual behaviour

The bottom state continuously changes.

Reproduction 2

Reproduction 2 is the same as reproduction 1 but with two screens to show the effect on the UI as the bottom state change is much larger.

Steps
  1. Focus on text input in the app.
  2. Tap "Go to screen 2".
  3. Inspect Screen2's KeyboardAvoidingView in the React Native DevTools.
Expected behaviour

The bottom state should not continuously change. The footer should not be flickering.

Actual behaviour

The bottom state continuously changes. The footer is flickering.

React Native Version

0.74.2

Affected Platforms

Runtime - Android

Output of npx react-native info
System:
  OS: macOS 14.5
  CPU: (8) arm64 Apple M1
  Memory: 100.70 MB / 16.00 GB
  Shell:
    version: 3.7.0
    path: /opt/homebrew/bin/fish
Binaries:
  Node:
    version: 20.11.1
    path: ~/.local/share/mise/installs/node/20/bin/node
  Yarn:
    version: 3.6.4
    path: ~/.local/share/mise/installs/node/20/bin/yarn
  npm:
    version: 10.2.4
    path: ~/.local/share/mise/installs/node/20/bin/npm
  Watchman:
    version: 2024.01.22.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK:
    API Levels:
      - "33"
      - "34"
    Build Tools:
      - 29.0.2
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 33.0.1
      - 34.0.0
    System Images:
      - android-33 | Google APIs ARM 64 v8a
      - android-34 | ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2023.2 AI-232.10227.8.2321.11479570
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    path: /opt/homebrew/opt/openjdk@17/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.2
    wanted: 0.74.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: false
Stacktrace or Logs
N/A
Reproducer

https://github.com/winghouchan/react-native-keyboardavoidingview-infinite-update-mcve

Screenshots and Videos
Reproduction 1

https://github.com/facebook/react-native/assets/6061021/4c89d653-2030-4a65-bf47-8a2ec895fd39

Reproduction 2

https://github.com/facebook/react-native/assets/6061021/43f2a203-232a-425d-a537-91f4f96ea8b5

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先检出链接的 reproducer 中的 example-1 和 example-2 分支,运行 yarn install 和 yarn android,然后在 React Native DevTools 中检查 KeyboardAvoidingView。比较在聚焦和取消聚焦 input 以及导航到 Screen2 时的 Android 行为;完成的标准是底部状态保持稳定,footer 不再闪烁或跳动。

由索引模型根据 Issue 内容生成。

评估

技术栈
android, react-native
领域
mobile
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。