mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Merge scroll changed workflow into scroll helper class
Summary: This diff address [comment](https://www.internalfb.com/diff/D32372180 (https://github.com/facebook/react-native/commit/073195991bfdf4c96490c65f9c0cf00d09356188)?dst_version_fbid=444635297227339&transaction_fbid=636262217544650) to merge workflow that notify Fabric state changes when scroll changed. Changelog: [Internal] Reviewed By: javache Differential Revision: D32500423 fbshipit-source-id: 8701f7ac885bf755e026b70554cb4a2ebb1af527
This commit is contained in:
committed by
Facebook GitHub Bot
parent
f70018b375
commit
8ab2cbb78f
+4
-10
@@ -432,13 +432,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
|
||||
updateClippingRect();
|
||||
}
|
||||
|
||||
// Race an UpdateState with every onScroll. This makes it more likely that, in Fabric,
|
||||
// when JS processes the scroll event, the C++ ShadowNode representation will have a
|
||||
// "more correct" scroll position. It will frequently be /incorrect/ but this decreases
|
||||
// the error as much as possible.
|
||||
ReactScrollViewHelper.updateStateOnScroll(this);
|
||||
|
||||
ReactScrollViewHelper.emitScrollEvent(
|
||||
ReactScrollViewHelper.updateStateOnScrollChanged(
|
||||
this,
|
||||
mOnScrollDispatchHelper.getXFlingVelocity(),
|
||||
mOnScrollDispatchHelper.getYFlingVelocity());
|
||||
@@ -521,7 +515,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
|
||||
mVelocityHelper.calculateVelocity(ev);
|
||||
int action = ev.getAction() & MotionEvent.ACTION_MASK;
|
||||
if (action == MotionEvent.ACTION_UP && mDragging) {
|
||||
ReactScrollViewHelper.updateStateOnScroll(this);
|
||||
ReactScrollViewHelper.updateFabricScrollState(this);
|
||||
|
||||
float velocityX = mVelocityHelper.getXVelocity();
|
||||
float velocityY = mVelocityHelper.getYVelocity();
|
||||
@@ -769,7 +763,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
|
||||
mRunning = true;
|
||||
} else {
|
||||
// There has not been a scroll update since the last time this Runnable executed.
|
||||
ReactScrollViewHelper.updateStateOnScroll(ReactHorizontalScrollView.this);
|
||||
ReactScrollViewHelper.updateFabricScrollState(ReactHorizontalScrollView.this);
|
||||
|
||||
// We keep checking for updates until the ScrollView has "stabilized" and hasn't
|
||||
// scrolled for N consecutive frames. This number is arbitrary: big enough to catch
|
||||
@@ -1178,7 +1172,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
|
||||
// to the last item in the list, but that item cannot be move to the start position of the view.
|
||||
final int actualX = getScrollX();
|
||||
final int actualY = getScrollY();
|
||||
ReactScrollViewHelper.updateStateOnScroll(this, actualX, actualY);
|
||||
ReactScrollViewHelper.updateFabricScrollState(this, actualX, actualY);
|
||||
setPendingContentOffsets(actualX, actualY);
|
||||
}
|
||||
|
||||
|
||||
@@ -312,13 +312,7 @@ public class ReactScrollView extends ScrollView
|
||||
updateClippingRect();
|
||||
}
|
||||
|
||||
// Race an UpdateState with every onScroll. This makes it more likely that, in Fabric,
|
||||
// when JS processes the scroll event, the C++ ShadowNode representation will have a
|
||||
// "more correct" scroll position. It will frequently be /incorrect/ but this decreases
|
||||
// the error as much as possible.
|
||||
ReactScrollViewHelper.updateStateOnScroll(this);
|
||||
|
||||
ReactScrollViewHelper.emitScrollEvent(
|
||||
ReactScrollViewHelper.updateStateOnScrollChanged(
|
||||
this,
|
||||
mOnScrollDispatchHelper.getXFlingVelocity(),
|
||||
mOnScrollDispatchHelper.getYFlingVelocity());
|
||||
@@ -359,7 +353,7 @@ public class ReactScrollView extends ScrollView
|
||||
mVelocityHelper.calculateVelocity(ev);
|
||||
int action = ev.getAction() & MotionEvent.ACTION_MASK;
|
||||
if (action == MotionEvent.ACTION_UP && mDragging) {
|
||||
ReactScrollViewHelper.updateStateOnScroll(this);
|
||||
ReactScrollViewHelper.updateFabricScrollState(this);
|
||||
|
||||
float velocityX = mVelocityHelper.getXVelocity();
|
||||
float velocityY = mVelocityHelper.getYVelocity();
|
||||
@@ -558,7 +552,7 @@ public class ReactScrollView extends ScrollView
|
||||
mRunning = true;
|
||||
} else {
|
||||
// There has not been a scroll update since the last time this Runnable executed.
|
||||
ReactScrollViewHelper.updateStateOnScroll(ReactScrollView.this);
|
||||
ReactScrollViewHelper.updateFabricScrollState(ReactScrollView.this);
|
||||
|
||||
// We keep checking for updates until the ScrollView has "stabilized" and hasn't
|
||||
// scrolled for N consecutive frames. This number is arbitrary: big enough to catch
|
||||
@@ -953,7 +947,7 @@ public class ReactScrollView extends ScrollView
|
||||
// to the last item in the list, but that item cannot be move to the start position of the view.
|
||||
final int actualX = getScrollX();
|
||||
final int actualY = getScrollY();
|
||||
ReactScrollViewHelper.updateStateOnScroll(this, actualX, actualY);
|
||||
ReactScrollViewHelper.updateFabricScrollState(this, actualX, actualY);
|
||||
setPendingContentOffsets(actualX, actualY);
|
||||
}
|
||||
|
||||
|
||||
+21
-7
@@ -342,7 +342,7 @@ public class ReactScrollViewHelper {
|
||||
scrollView.startFlingAnimator(scrollY, y);
|
||||
}
|
||||
|
||||
updateStateOnScroll(scrollView, x, y);
|
||||
updateFabricScrollState(scrollView, x, y);
|
||||
}
|
||||
|
||||
/** Get current (x, y) position or position after current animation finishes, if any. */
|
||||
@@ -386,8 +386,8 @@ public class ReactScrollViewHelper {
|
||||
T extends
|
||||
ViewGroup & FabricViewStateManager.HasFabricViewStateManager & HasScrollState
|
||||
& HasFlingAnimator>
|
||||
boolean updateStateOnScroll(final T scrollView) {
|
||||
return updateStateOnScroll(scrollView, scrollView.getScrollX(), scrollView.getScrollY());
|
||||
boolean updateFabricScrollState(final T scrollView) {
|
||||
return updateFabricScrollState(scrollView, scrollView.getScrollX(), scrollView.getScrollY());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -397,11 +397,11 @@ public class ReactScrollViewHelper {
|
||||
T extends
|
||||
ViewGroup & FabricViewStateManager.HasFabricViewStateManager & HasScrollState
|
||||
& HasFlingAnimator>
|
||||
boolean updateStateOnScroll(final T scrollView, final int scrollX, final int scrollY) {
|
||||
boolean updateFabricScrollState(final T scrollView, final int scrollX, final int scrollY) {
|
||||
if (DEBUG_MODE) {
|
||||
FLog.i(
|
||||
TAG,
|
||||
"updateStateOnScroll[%d] scrollX %d scrollY %d",
|
||||
"updateFabricScrollState[%d] scrollX %d scrollY %d",
|
||||
scrollView.getId(),
|
||||
scrollX,
|
||||
scrollY);
|
||||
@@ -448,7 +448,7 @@ public class ReactScrollViewHelper {
|
||||
if (DEBUG_MODE) {
|
||||
FLog.i(
|
||||
TAG,
|
||||
"updateStateOnScroll[%d] scrollX %d scrollY %d fabricScrollX",
|
||||
"updateFabricScrollState[%d] scrollX %d scrollY %d fabricScrollX",
|
||||
scrollView.getId(),
|
||||
scrollX,
|
||||
scrollY,
|
||||
@@ -471,6 +471,20 @@ public class ReactScrollViewHelper {
|
||||
});
|
||||
}
|
||||
|
||||
public static <
|
||||
T extends
|
||||
ViewGroup & FabricViewStateManager.HasFabricViewStateManager & HasScrollState
|
||||
& HasFlingAnimator>
|
||||
void updateStateOnScrollChanged(
|
||||
final T scrollView, final float xVelocity, final float yVelocity) {
|
||||
// Race an UpdateState with every onScroll. This makes it more likely that, in Fabric,
|
||||
// when JS processes the scroll event, the C++ ShadowNode representation will have a
|
||||
// "more correct" scroll position. It will frequently be /incorrect/ but this decreases
|
||||
// the error as much as possible.
|
||||
updateFabricScrollState(scrollView);
|
||||
emitScrollEvent(scrollView, xVelocity, yVelocity);
|
||||
}
|
||||
|
||||
public static <
|
||||
T extends
|
||||
ViewGroup & FabricViewStateManager.HasFabricViewStateManager & HasScrollState
|
||||
@@ -491,7 +505,7 @@ public class ReactScrollViewHelper {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animator) {
|
||||
scrollView.getReactScrollViewScrollState().setIsFinished(true);
|
||||
ReactScrollViewHelper.updateStateOnScroll(scrollView);
|
||||
updateFabricScrollState(scrollView);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user