Skip to content

Commit 1ae9b9a

Browse files
committed
Workaround a wrong fling direction if FlatList or VirtualizedList is inverted.
1 parent de60e86 commit 1ae9b9a

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)