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
This commit is contained in:
Xin Chen
2023-07-17 16:42:03 -07:00
committed by Facebook GitHub Bot
parent ab3c00de2c
commit 777934ec3a
@@ -101,6 +101,15 @@ public class ReactScrollViewHelper {
private static <T extends ViewGroup & HasScrollEventThrottle> 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) {