From 4159e201462c346c456de1fa869d88a9cce7b6d4 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Fri, 11 Oct 2019 05:43:11 -0700 Subject: [PATCH] Fix throttling in scroll view Summary: Setting minimal throttle to 1/60 causes dropped updates. Let's take following example Each frame is 16.666 MS. Frame1: [________didScroll is called towards end of the frame_] Frame2: [_didScroll is called towards beginning of the frame_________] update from Frame 2 doesn't propagate because we set throttle to 16MS thinking that `onScroll` is called for each frame. If Javascript specified value below 1/60 it is basically asking for every update. Reviewed By: shergin, mdvacca Differential Revision: D17829926 fbshipit-source-id: e7b07fd09581cd5053aa27a62cf6f6ddb2193783 --- .../ScrollView/RCTScrollViewComponentView.mm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm index cec44323072f11..da56f23658518a 100644 --- a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm @@ -119,10 +119,15 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & // Zero means "send value only once per significant logical event". // Prop value is in milliseconds. // iOS implementation uses `NSTimeInterval` (in seconds). - // 16 ms is the minimum allowed value. - _scrollEventThrottle = newScrollViewProps.scrollEventThrottle <= 0 - ? INFINITY - : std::max(newScrollViewProps.scrollEventThrottle / 1000.0, 1.0 / 60.0); + CGFloat throttleInSeconds = newScrollViewProps.scrollEventThrottle / 1000.0; + CGFloat msPerFrame = 1.0 / 60.0; + if (throttleInSeconds < 0) { + _scrollEventThrottle = INFINITY; + } else if (throttleInSeconds <= msPerFrame) { + _scrollEventThrottle = 0; + } else { + _scrollEventThrottle = throttleInSeconds; + } } MAP_SCROLL_VIEW_PROP(zoomScale);