react-native 在Android中,当滚动事件结束时,滚动速度会被`scrollEventThrottle`限制,

iqxoj9l9  于 24天前  发布在  React
关注(0)|答案(4)|浏览(22)

描述

在安卓设备上,通过设置非零的scrollEventThrottle值,可以阻止onScrollEndDrag事件的发生。

重现步骤

  • 使用以下代码,以任何速度滚动/拖动,注意onScrollEndDrag消息没有被记录。
  • 在不进行拖动/无速度的情况下重复(在释放之前保持相同的滚动位置超过250ms),注意onScrollEndDrag消息被记录。
<FlatList
  data={[1,2,3,4]}
  onScrollEndDrag={() => console.log('onScrollEndDrag')}
  renderItem={() => <View style={{height: 400}} />}
  scrollEventThrottle={250}
/>

React Native版本

0.73.6

受影响的平台

运行时 - Android

npx react-native info的输出

info Fetching system and libraries information...
System:
  OS: macOS 14.4.1
  CPU: (10) arm64 Apple M1 Pro
  Memory: 264.94 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.20.1
    path: ~/.nvm/versions/node/v18.20.1/bin/node
  Yarn:
    version: 1.22.19
    path: ~/.yarn/bin/yarn
  npm:
    version: 7.24.2
    path: ~/code/react-native-sydney-components/node_modules/.bin/npm
  Watchman:
    version: 2024.04.15.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/AG63864/.rbenv/shims/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:
    API Levels:
      - "33"
      - "34"
    Build Tools:
      - 33.0.1
      - 34.0.0
    System Images:
      - android-34 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2023.2 AI-232.10300.40.2321.11567975
  Xcode:
    version: 15.3/15E204a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.11
    path: /Users/AG63864/.jenv/shims/javac
  Ruby:
    version: 3.1.1
    path: /Users/AG63864/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.6
    wanted: 0.73.6
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: false
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

info React Native v0.74.0 is now available (your project is running on v0.73.6).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.74.0
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.74.0
info For more info, check out "https://reactnative.dev/docs/upgrading?os=macos".

堆栈跟踪或日志

n/a

重现器

https://github.com/scrungrth/android-scroll-throttle-reproducer

截图和视频

  • 无响应*
svmlkihl

svmlkihl1#

⚠️React Native的新版本可用!
i️您正在使用受支持的次要版本,但似乎有一个更新的补丁可用 - 0.73.7。请升级到您次要版本的最高补丁或最新版本,并验证问题是否仍然存在(或者,创建一个新项目并在其中重现问题)。如果无法重现,请告知我们,以便我们关闭此问题。这有助于确保我们关注仍在最近版本中存在的问题。
ctehm74n

ctehm74n2#

我已经调试过这个问题,以下是我的观察结果:

  • scrollEventThrottle 控制所有滚动事件,包括 onScrollonScrollEndDragonScrollMomentumBeginonMomentumScrollEnd 等。
  • 对于从这些事件中成功触发的每个事件,都会在 ReactScrollView 中设置一个时间戳 lastScrollDispatchTime。在触发下一个事件之前,会检查条件 scrollEventThrottle > currentTimeStamp - lastScrollDispatchTime
  • 进一步的调试表明,大多数情况下,onScroll 事件会在上述条件为 false 时触发,因此将 lastDispatchTimestamp 设置为 currentTimeStamp。在此情况下,之后触发的任何事件都会被限制。在这种情况下,它是 onScrollEndDrag

我认为这种行为是根据文档设计的。@cortinico 可以对此进行更详细的解释。

apeeds0o

apeeds0o3#

@kunalchavhan 这是一个很棒的见解;
我认为这种行为是根据文档设计的。
对我来说,即使有共享事件节流,每次滚动类型的事件在这里被节流似乎有些奇怪。

m3eecexj

m3eecexj4#

升级从0.72.4到0.74.1后,同样存在问题。

相关问题