Skip to content

Commit b971c5b

Browse files
mandriginfacebook-github-bot
authored andcommitted
Workaround a wrong fling direction for inverted ScrollViews on Android P (#21117)
Summary: This is a safe workaround to an issue in Android P: https://issuetracker.google.com/issues/112385925 It is based on a fact that even though `fling` receive a wrong sign in `velocityY`, `mOnScrollDispatchHelper.getYFlingVelocity()` still returns a fling direction. Fixes #19434 Pull Request resolved: #21117 Differential Revision: D13082740 Pulled By: hramos fbshipit-source-id: 1b28586d2c7bdcae4a111d3cead4a0455cebb99a
1 parent 984eef8 commit b971c5b

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,18 @@ public void getClippingRect(Rect outClippingRect) {
309309

310310
@Override
311311
public void fling(int velocityY) {
312+
// Workaround.
313+
// On Android P if a ScrollView is inverted, we will get a wrong sign for
314+
// velocityY (see https://issuetracker.google.com/issues/112385925).
315+
// At the same time, mOnScrollDispatchHelper tracks the correct velocity direction.
316+
//
317+
// Hence, we can use the absolute value from whatever the OS gives
318+
// us and use the sign of what mOnScrollDispatchHelper has tracked.
319+
final int correctedVelocityY = (int)(Math.abs(velocityY) * Math.signum(mOnScrollDispatchHelper.getYFlingVelocity()));
320+
321+
312322
if (mPagingEnabled) {
313-
flingAndSnap(velocityY);
323+
flingAndSnap(correctedVelocityY);
314324
} else if (mScroller != null) {
315325
// FB SCROLLVIEW CHANGE
316326

@@ -326,7 +336,7 @@ public void fling(int velocityY) {
326336
getScrollX(), // startX
327337
getScrollY(), // startY
328338
0, // velocityX
329-
velocityY, // velocityY
339+
correctedVelocityY, // velocityY
330340
0, // minX
331341
0, // maxX
332342
0, // minY
@@ -339,9 +349,9 @@ public void fling(int velocityY) {
339349

340350
// END FB SCROLLVIEW CHANGE
341351
} else {
342-
super.fling(velocityY);
352+
super.fling(correctedVelocityY);
343353
}
344-
handlePostTouchScrolling(0, velocityY);
354+
handlePostTouchScrolling(0, correctedVelocityY);
345355
}
346356

347357
private void enableFpsListener() {

0 commit comments

Comments
 (0)