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

Abierto Apto para principiantes
#60,167 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
android, java, kotlin, react-native
Área
frontend, mobile

Línea de trabajo

Lee BaseViewManager.prepareToRecycleView en ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java y compara sus restablecimientos de propiedades de foco con ReactViewManager.kt, donde se establece nextFocusLeftId. El reproductor en rn-recycled-view-next-focus-left demuestra que la vista reciclada conserva el valor anterior. Verifica que el reciclaje lo borre y que una vista con su propio nextFocusLeft siga usando ese destino.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
C++
Estrellas
127k
Forks
25.5k
Merge medio
3 d 19 h
PR fusionados (30 d)
291

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de react/react-native

Todos los issues de react/react-native

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.