Skip to content

Commit 4159e20

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
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
1 parent 1ba67fd commit 4159e20

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm

+9-4
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,15 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
119119
// Zero means "send value only once per significant logical event".
120120
// Prop value is in milliseconds.
121121
// iOS implementation uses `NSTimeInterval` (in seconds).
122-
// 16 ms is the minimum allowed value.
123-
_scrollEventThrottle = newScrollViewProps.scrollEventThrottle <= 0
124-
? INFINITY
125-
: std::max(newScrollViewProps.scrollEventThrottle / 1000.0, 1.0 / 60.0);
122+
CGFloat throttleInSeconds = newScrollViewProps.scrollEventThrottle / 1000.0;
123+
CGFloat msPerFrame = 1.0 / 60.0;
124+
if (throttleInSeconds < 0) {
125+
_scrollEventThrottle = INFINITY;
126+
} else if (throttleInSeconds <= msPerFrame) {
127+
_scrollEventThrottle = 0;
128+
} else {
129+
_scrollEventThrottle = throttleInSeconds;
130+
}
126131
}
127132

128133
MAP_SCROLL_VIEW_PROP(zoomScale);

0 commit comments

Comments
 (0)