Skip to content
Permalink
Browse files
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
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Oct 11, 2019
1 parent 1ba67fd commit 4159e201462c346c456de1fa869d88a9cce7b6d4
Showing 1 changed file with 9 additions and 4 deletions.
@@ -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);

0 comments on commit 4159e20

Please sign in to comment.