Android: with view recycling on, a recycled View keeps its nextFocusLeft

Đang mở Phù hợp với người mới
#60,167 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
android, java, kotlin, react-native
Lĩnh vực
frontend, mobile

Hướng nghiên cứu

Đọc BaseViewManager.prepareToRecycleView trong ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java và so sánh việc đặt lại các thuộc tính tiêu điểm với ReactViewManager.kt, nơi nextFocusLeftId được đặt. Trường hợp tái hiện tại rn-recycled-view-next-focus-left cho thấy view được tái chế vẫn giữ giá trị cũ. Hãy xác minh rằng việc tái chế xóa giá trị đó, trong khi một view có nextFocusLeft riêng vẫn sử dụng đích đó.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Needs: Triage :mag: Platform: Android
Description

With view recycling on (enableViewRecycling), a View that mounts on a recycled ReactViewGroup keeps the nextFocusLeft of the view that used it before, so Arrow Left (D-pad Left) from it moves focus to that old target.

BaseViewManager.prepareToRecycleView resets nextFocusDown, nextFocusForward, nextFocusRight and nextFocusUp to View.NO_ID (L155-L161), but not nextFocusLeft, which ReactViewManager sets as nextFocusLeftId (L260-L263). A new View without the prop never sets it back.

Steps to reproduce

The reproducer turns enableViewRecycling on in MainApplication and renders a row of three focusable Pressables: "Target", "Neighbour" and "Old subject", whose nextFocusLeft is "Target". Once Arrow Left from "Old subject" has focused "Target", "Old subject" unmounts, and a second later "New subject", without nextFocusLeft, mounts in its place. MainActivity logs which Android view instance each subject is drawn by and its nextFocusLeftId.

  1. Clone the reproducer and, with one Android device attached, run ./reproduce.sh. It builds and installs the release APK, presses the arrow keys with adb shell input keyevent and reads which view holds focus from uiautomator dump.
  2. Or by hand: cd ReproducerApp/android && ./gradlew assembleRelease && adb install -r app/build/outputs/apk/release/app-release.apk, open the app, and with a keyboard or D-pad:
    1. Press Right until "Old subject" holds focus, then Left: focus goes to "Target".
    2. A second later "New subject" replaces "Old subject". Press Right until "New subject" holds focus, then Left.

Expected: Arrow Left from "New subject" focuses "Neighbour", the view on its left; a nextFocusLeft that a view sets itself still decides where Left goes, as it does for "Old subject".
Seen: it focuses "Target", "Old subject"'s nextFocusLeft.

React Native Version

0.90.0-nightly-20261119-f4f8b6a1f

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info
System:
  OS: Windows 11 10.0.26300
  CPU: "(32) x64 AMD Ryzen 9 9950X3D 16-Core Processor          "
  Memory: 170.02 GB / 255.67 GB
Binaries:
  Node:
    version: 26.12.1
    path: C:\Program Files\nodejs\node.EXE
  Yarn:
    version: 1.22.22
    path: C:\Users\<user>\AppData\Roaming\npm\yarn.CMD
  npm:
    version: 12.2.1
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK:
    AllowDevelopmentWithoutDevLicense: Enabled
    Versions:
      - 10.0.19041.0
      - 10.0.26100.0
IDEs:
  Android Studio: AI-262.9437.185.2621.16467767
  Visual Studio: Not Found
Languages:
  Java:
    version: 17.0.20.1
    path: C:\Program Files\Microsoft\jdk-17.0.20.101-hotspot\bin\javac.EXE
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli":
    installed: 21.0.0
    wanted: 21.0.0
  react:
    installed: 19.3.0
    wanted: 19.3.0
  react-native:
    installed: 0.90.0-nightly-20261119-f4f8b6a1f
    wanted: 0.90.0-nightly-20261119-f4f8b6a1f
  react-native-windows: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found
Stacktrace or Logs

No error is logged. ./reproduce.sh at the reproducer's fb8a697, on a Galaxy S23:

device: SM-S911B, Android 14 (API 34), arm64-v8a
react-native 0.90.0-nightly-20261119-f4f8b6a1f
== ./gradlew :app:assembleRelease -PreactNativeArchitectures=arm64-v8a
enableViewRecycling true
== 1. Arrow Right to the old subject (nextFocusLeft = Target), then Arrow Left
focused: Old subject
Arrow Left from the old subject focused: Target
== 2. The old subject unmounts; a new subject without nextFocusLeft mounts
subject-old: view instance 226627177, id 30, nextFocusLeftId 10
subject-new: view instance 226627177, id 48, nextFocusLeftId 10
the new subject reuses the old subject's Android view: yes
== 3. Arrow Right to the new subject, then Arrow Left
focused: New subject
Arrow Left from the new subject focused: Target
SUMMARY: Arrow Left from the new subject, which has no nextFocusLeft, went to "Target", the old subject's nextFocusLeft; expected "Neighbour"
MANDATORY Reproducer

https://github.com/YevheniiKotyrlo/rn-recycled-view-next-focus-left

Screenshots and Videos

No response

Ngôn ngữ chính
C++
Star
127k
Fork
25.5k
Merge trung bình
3 ngày 19 giờ
Pull request đã merge (30 ngày)
291

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của react/react-native

Tất cả issue của react/react-native

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.