Skip to content

Commit 90cb45f

Browse files
mandriginkelset
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 695784a commit 90cb45f

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
@@ -299,8 +299,18 @@ public void getClippingRect(Rect outClippingRect) {
299299

300300
@Override
301301
public void fling(int velocityY) {
302+
// Workaround.
303+
// On Android P if a ScrollView is inverted, we will get a wrong sign for
304+
// velocityY (see https://issuetracker.google.com/issues/112385925).
305+
// At the same time, mOnScrollDispatchHelper tracks the correct velocity direction.
306+
//
307+
// Hence, we can use the absolute value from whatever the OS gives
308+
// us and use the sign of what mOnScrollDispatchHelper has tracked.
309+
final int correctedVelocityY = (int)(Math.abs(velocityY) * Math.signum(mOnScrollDispatchHelper.getYFlingVelocity()));
310+
311+
302312
if (mPagingEnabled) {
303-
flingAndSnap(velocityY);
313+
flingAndSnap(correctedVelocityY);
304314
} else if (mScroller != null) {
305315
// FB SCROLLVIEW CHANGE
306316

@@ -316,7 +326,7 @@ public void fling(int velocityY) {
316326
getScrollX(), // startX
317327
getScrollY(), // startY
318328
0, // velocityX
319-
velocityY, // velocityY
329+
correctedVelocityY, // velocityY
320330
0, // minX
321331
0, // maxX
322332
0, // minY
@@ -329,9 +339,9 @@ public void fling(int velocityY) {
329339

330340
// END FB SCROLLVIEW CHANGE
331341
} else {
332-
super.fling(velocityY);
342+
super.fling(correctedVelocityY);
333343
}
334-
handlePostTouchScrolling(0, velocityY);
344+
handlePostTouchScrolling(0, correctedVelocityY);
335345
}
336346

337347
private void enableFpsListener() {

0 commit comments

Comments
 (0)