From e868a20eee6f1257b39768f223f87c26c35088e3 Mon Sep 17 00:00:00 2001 From: Xin Chen Date: Mon, 17 Jul 2023 16:42:03 -0700 Subject: [PATCH] Reenable scrollEventThrottle prop for ScrollView and HorizontalScrollView (#38475) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38475 We added `scrollEventThrottle` for android in D35735978, but the experiment was never executed and the flag got removed in D39449184. Since the same feature is on iOS and the implementation here is the same to iOS (https://fburl.com/code/htcuhq4w), it should be safe to support. Changelog: [Android][Add] - Add scrollEventThrottle prop support for android Reviewed By: cortinico Differential Revision: D47492259 fbshipit-source-id: 09a2bead652bfef4a2c70b996cf66f6983604db2 --- .../react/views/scroll/ReactScrollViewHelper.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.java index e16dd1cad29358..ac34e2541bf3a2 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.java @@ -101,6 +101,15 @@ private static void emitScrollEve private static void emitScrollEvent( T scrollView, ScrollEventType scrollEventType, float xVelocity, float yVelocity) { long now = System.currentTimeMillis(); + // Throttle the scroll event if scrollEventThrottle is set to be equal or more than 17 ms. + // We limit the delta to 17ms so that small throttles intended to enable 60fps updates will not + // inadvertently filter out any scroll events. + if (scrollView.getScrollEventThrottle() + >= Math.max(17, now - scrollView.getLastScrollDispatchTime())) { + // Scroll events are throttled. + return; + } + View contentView = scrollView.getChildAt(0); if (contentView == null) {