react / react/react-native

【Android】:Animated.event does not update latest contentOffset.y on onScroll Event When useNativeDriver is set to true

未关闭
#52,657 8 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

API: Animated Needs: Triage :mag: Platform: Android
主要语言
C++
星标
127k
派生
25.3k
平均合并
1 天 23 小时
30 天内合并 PR
4

描述

Description

I want to implement a stickyHeader component that relies on the scroll event of the scrollView to get the latest contentOffset.y. Then, by listening to the changes in y, I can set the translateY property of the stickyHeader.

However, when the content height of the scrollView changes dynamically, especially when it decreases, using addListener to track the animation value changes, we find that when useNativeDriver is set to true, Animated.event sometimes fails to update the latest contentOffset.y value. The listener callback of Animated.event prints e.nativeEvent.contentOffset.y as the latest value, but printing animatedValue.__getValue still shows the previous value.

Unfortunately, we cannot trigger the animation value change in the listener callback of Animated.event, as that would cause the sticky animation to flicker.

Image

Steps to reproduce
  1. Install the app.
  2. Click on tab1 and scroll the scroll-view content to the bottom.
  3. Click on tab2.
  4. Repeat steps 2 and 3 to reproduce the issue.

I cannot reproduce the issue in the emulator; it only occurs sporadically on a real device.

React Native Version

0.80.1

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info
ystem:
  OS: macOS 14.2.1
  CPU: (8) arm64 Apple M3
  Memory: 137.05 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 23.10.0
    path: ~/.nvm/versions/node/v23.10.0/bin/node
  Yarn:
    version: 1.22.22
    path: /usr/local/bin/yarn
  npm:
    version: 10.9.2
    path: ~/.nvm/versions/node/v23.10.0/bin/npm
  Watchman:
    version: 2024.10.21.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.4
      - iOS 17.4
      - macOS 14.4
      - tvOS 17.4
      - visionOS 1.1
      - watchOS 10.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2023.3 AI-233.14808.21.2331.11709847
  Xcode:
    version: 15.3/15E204a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.11
    path: /usr/bin/javac
  Ruby:
    version: 3.1.0
    path: /Users/didi/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 19.0.0
    wanted: 19.0.0
  react:
    installed: 19.1.0
    wanted: 19.1.0
  react-native:
    installed: 0.80.1
    wanted: 0.80.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false
Stacktrace or Logs
no logs
MANDATORY Reproducer

https://github.com/yandadaFreedom/reproducer-react-native-0.80.1/tree/bug-animated-event

Screenshots and Videos

The issue is reproduced at the 35-second mark in the video.

https://github.com/user-attachments/assets/f6da6f71-d5a0-410a-b207-2eb9d174d7e5

贡献指南

打开贡献指南

从这里开始

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

调研方向

从必需的复现步骤开始,检查使用原生驱动时 Android 的 Animated.event 路径,重点关注步骤中描述的 ScrollView 内容高度动态变化。在真实设备上复现,并将 listener 的 contentOffset.y 与 animated value 进行比较;当最新值能够可靠地更新且不会导致 sticky-header 闪烁时,即表示完成。

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

评估

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

把新 issue 发到你的邮箱

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