Fix mis-use of the post animated value when predict fling distance

Summary:
This diff fixes an edge case where scroll to the end of the list may trigger a bounce back effect.

This issue is a regression from D32487846 (https://github.com/facebook/react-native/commit/f70018b37532622f08f20b2c51cdbfca55d730ea) (See [this comment](https://www.internalfb.com/diff/D32487846 (https://github.com/facebook/react-native/commit/f70018b37532622f08f20b2c51cdbfca55d730ea)?dst_version_fbid=263960175698224&transaction_fbid=566201141113715)) that zero velocity fling at the end of the scroll view makes the next fling animator use previous post animation position. This is due to cached `postAnimationValue` is applied mistakenly.

- Pass velocity instead of velocity sign to the helper class
- Update helper class logic to decide if we need to use post animated value from last fling animation

Changelog:
[Internal]

Reviewed By: javache

Differential Revision: D32566010

fbshipit-source-id: 1c61659030151f8f2c7648ca901b8b4158835538
This commit is contained in:
Xin Chen
2021-12-06 09:39:08 -08:00
committed by Facebook GitHub Bot
parent ead7b97944
commit 1c1945569f
3 changed files with 6 additions and 6 deletions
@@ -816,7 +816,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
this,
getScrollX(),
getReactScrollViewScrollState().getFinalAnimatedPositionScroll().x,
velocityX > 0), // startX
velocityX), // startX
getScrollY(), // startY
velocityX, // velocityX
0, // velocityY
@@ -847,7 +847,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
this,
getScrollX(),
getReactScrollViewScrollState().getFinalAnimatedPositionScroll().x,
velocity > 0));
velocity));
double targetOffset = (double) predictFinalScrollPosition(velocity);
int previousPage = (int) Math.floor(currentOffset / interval);
@@ -606,7 +606,7 @@ public class ReactScrollView extends ScrollView
this,
getScrollY(),
getReactScrollViewScrollState().getFinalAnimatedPositionScroll().y,
velocityY > 0), // startY
velocityY), // startY
0, // velocityX
velocityY, // velocityY
0, // minX
@@ -636,7 +636,7 @@ public class ReactScrollView extends ScrollView
this,
getScrollY(),
getReactScrollViewScrollState().getFinalAnimatedPositionScroll().y,
velocity > 0));
velocity));
double targetOffset = (double) predictFinalScrollPosition(velocity);
int previousPage = (int) Math.floor(currentOffset / interval);
@@ -339,9 +339,9 @@ public class ReactScrollViewHelper {
final T scrollView,
final int currentValue,
final int postAnimationValue,
final boolean isPositiveVelocity) {
final int velocity) {
final ReactScrollViewScrollState scrollState = scrollView.getReactScrollViewScrollState();
final int velocityDirectionMask = isPositiveVelocity ? 1 : -1;
final int velocityDirectionMask = velocity != 0 ? velocity / Math.abs(velocity) : 0;
final boolean isMovingTowardsAnimatedValue =
velocityDirectionMask * (postAnimationValue - currentValue) > 0;