react / react/react-native

[Android] - Can't access ShadowNode in FlatList with horizontal prop

未关闭
#51,601 5 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Component: FlatList Issue: Author Provided Repro Platform: Android Type: New Architecture
主要语言
C++
星标
127k
派生
25.3k
平均合并
1 天 23 小时
30 天内合并 PR
4

描述

Description

I've found a discrepancy between Android and iOS platforms.
When the horizontal prop is set, the ref returned during unmount has a nullable NativeState property which breaks ShadowNode cleanup required by Unistyles.

How I access the NativeState for FlatList components:

ref?.getScrollResponder?.()?.getNativeScrollRef?.()?.__internalInstanceHandle?.stateNode?.node

Link

and then in C++:

ShadowNode::Shared shadowNode = shadowNodeFromValue(rt, args[0]); // args[0] is jsi::Value with NativeState

Desired behaviour:
I should be able to access ShadowNode during cleanup to perform own cleanups as in any other component or without horizontal prop.

Steps to reproduce
  1. Install the provided repro
  2. Run the app on Android and open the debugger to view console.log output
  3. You should see two logs:
    Mount
    NativeState: ✅
    
  4. Tap the Reload button
  5. Notice that NativeState is no longer present:
    Unmount
    NativeState: ❌
    
  6. Run the app on iOS and open the debugger to view console.log output
  7. Verify that NativeState is present in both the mount and unmount phases
  8. Comment out the horizontal prop
  9. Verify that NativeState is present in both the mount and unmount phases on both iOS and Android
React Native Version

0.79.2

Affected Platforms

Runtime - Android

Areas

Fabric - The New Renderer

Output of npx @react-native-community/cli info
System:
  OS: macOS 15.3.2
  CPU: (12) arm64 Apple M3 Pro
  Memory: 2.15 GB / 36.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 23.5.0
    path: /opt/homebrew/bin/node
  Yarn:
    version: 1.22.22
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.9.2
    path: /opt/homebrew/bin/npm
  Watchman:
    version: 2024.12.02.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:
    API Levels:
      - "23"
      - "28"
      - "29"
      - "30"
      - "33"
      - "34"
      - "35"
    Build Tools:
      - 30.0.3
      - 34.0.0
      - 35.0.0
    System Images:
      - android-23 | ARM 64 v8a
      - android-24 | Google APIs ARM 64 v8a
      - android-26 | Google APIs ARM 64 v8a
      - android-28 | ARM 64 v8a
      - android-29 | ARM 64 v8a
      - android-30 | ARM 64 v8a
      - android-30 | Google APIs ARM 64 v8a
      - android-34 | Android TV ARM 64 v8a
      - android-34 | ARM 64 v8a
      - android-34 | Google APIs ARM 64 v8a
      - android-35 | Google APIs ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.3 AI-243.25659.59.2432.13404313
  Xcode:
    version: 16.3/16E140
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.11
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 18.0.0
    wanted: 18.0.0
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.79.2
    wanted: 0.79.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
Stacktrace or Logs
No crash
MANDATORY Reproducer

https://github.com/jpudysz/react-native-horizontal-flatlist-repro

Screenshots and Videos

Android + horizontal prop

Image

Android + no horizontal prop

Image

iOS + horizontal prop

Image

iOS + no horizontal prop

Image

贡献指南

打开贡献指南

从这里开始

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

调研方向

先从必需的 reproducer 开始,比较 FlatList 在有和没有 horizontal prop 时的 Android 和 iOS 日志。使用报告中的 React Native 0.79.2 设置,跟踪围绕 NativeState 的 Fabric ShadowNode 清理路径以及 Android 实现。完成标准是:对于 horizontal FlatList,NativeState 在 Android 卸载清理期间仍然可用,与其他情况一致。

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

评估

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

把新 issue 发到你的邮箱

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