mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Horizontal/ScrollView: rename reactScrollTo to scrollTo
Summary: We can override the `scrollTo` method and it's likely/possible that Android internals are calling scrollTo directly. So, we can capture more cases where the scroll position is changing and needs to be updated in Fabric State. Unfortunately we still cannot override smoothScrollTo because it is marked as final. For now we just keep the custom `reactSmoothScrollTo` method and hope that we can catch more cases with `scrollTo`. Changelog: [Internal] Reviewed By: sammy-SC, mdvacca Differential Revision: D26887028 fbshipit-source-id: e2678f1a20640d598abbec9671d6102635f65bb2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
de5e16f55c
commit
1163599989
+1
-1
@@ -65,7 +65,7 @@ public class ReactHorizontalScrollContainerView extends ReactViewGroup {
|
||||
ReactHorizontalScrollView parent = (ReactHorizontalScrollView) getParent();
|
||||
// Fix the ScrollX position when using RTL language
|
||||
int offsetX = parent.getScrollX() + getWidth() - mCurrentWidth - parent.getWidth();
|
||||
parent.reactScrollTo(offsetX, parent.getScrollY());
|
||||
parent.scrollTo(offsetX, parent.getScrollY());
|
||||
}
|
||||
}
|
||||
mCurrentWidth = getWidth();
|
||||
|
||||
+11
-7
@@ -291,7 +291,7 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
|
||||
pendingContentOffsetX != UNSET_CONTENT_OFFSET ? pendingContentOffsetX : getScrollX();
|
||||
int scrollToY =
|
||||
pendingContentOffsetY != UNSET_CONTENT_OFFSET ? pendingContentOffsetY : getScrollY();
|
||||
reactScrollTo(scrollToX, scrollToY);
|
||||
scrollTo(scrollToX, scrollToY);
|
||||
ReactScrollViewHelper.emitLayoutEvent(this);
|
||||
}
|
||||
|
||||
@@ -1070,17 +1070,21 @@ public class ReactHorizontalScrollView extends HorizontalScrollView
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls `reactScrollTo` and updates state.
|
||||
* Calls `super.scrollTo` and updates state.
|
||||
*
|
||||
* <p>`reactScrollTo` changes `contentOffset` and we need to keep `contentOffset` in sync between
|
||||
* scroll view and state. Calling raw `reactScrollTo` doesn't update state.
|
||||
* <p>`super.scrollTo` changes `contentOffset` and we need to keep `contentOffset` in sync between
|
||||
* scroll view and state.
|
||||
*
|
||||
* <p>Note that while we can override scrollTo, we *cannot* override `smoothScrollTo` because it
|
||||
* is final. See `reactSmoothScrollTo`.
|
||||
*/
|
||||
public void reactScrollTo(int x, int y) {
|
||||
@Override
|
||||
public void scrollTo(int x, int y) {
|
||||
if (DEBUG_MODE) {
|
||||
FLog.i(TAG, "reactScrollTo[%d] x %d y %d", getId(), x, y);
|
||||
FLog.i(TAG, "scrollTo[%d] x %d y %d", getId(), x, y);
|
||||
}
|
||||
|
||||
scrollTo(x, y);
|
||||
super.scrollTo(x, y);
|
||||
updateStateOnScroll(x, y);
|
||||
setPendingContentOffsets(x, y);
|
||||
}
|
||||
|
||||
+4
-4
@@ -193,7 +193,7 @@ public class ReactHorizontalScrollViewManager extends ViewGroupManager<ReactHori
|
||||
if (data.mAnimated) {
|
||||
scrollView.reactSmoothScrollTo(data.mDestX, data.mDestY);
|
||||
} else {
|
||||
scrollView.reactScrollTo(data.mDestX, data.mDestY);
|
||||
scrollView.scrollTo(data.mDestX, data.mDestY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ public class ReactHorizontalScrollViewManager extends ViewGroupManager<ReactHori
|
||||
if (data.mAnimated) {
|
||||
scrollView.reactSmoothScrollTo(right, scrollView.getScrollY());
|
||||
} else {
|
||||
scrollView.reactScrollTo(right, scrollView.getScrollY());
|
||||
scrollView.scrollTo(right, scrollView.getScrollY());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,9 +306,9 @@ public class ReactHorizontalScrollViewManager extends ViewGroupManager<ReactHori
|
||||
if (value != null) {
|
||||
double x = value.hasKey("x") ? value.getDouble("x") : 0;
|
||||
double y = value.hasKey("y") ? value.getDouble("y") : 0;
|
||||
view.reactScrollTo((int) PixelUtil.toPixelFromDIP(x), (int) PixelUtil.toPixelFromDIP(y));
|
||||
view.scrollTo((int) PixelUtil.toPixelFromDIP(x), (int) PixelUtil.toPixelFromDIP(y));
|
||||
} else {
|
||||
view.reactScrollTo(0, 0);
|
||||
view.scrollTo(0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ public class ReactScrollView extends ScrollView
|
||||
pendingContentOffsetX != UNSET_CONTENT_OFFSET ? pendingContentOffsetX : getScrollX();
|
||||
int scrollToY =
|
||||
pendingContentOffsetY != UNSET_CONTENT_OFFSET ? pendingContentOffsetY : getScrollY();
|
||||
reactScrollTo(scrollToX, scrollToY);
|
||||
scrollTo(scrollToX, scrollToY);
|
||||
ReactScrollViewHelper.emitLayoutEvent(this);
|
||||
}
|
||||
|
||||
@@ -878,9 +878,13 @@ public class ReactScrollView extends ScrollView
|
||||
*
|
||||
* <p>`reactScrollTo` changes `contentOffset` and we need to keep `contentOffset` in sync between
|
||||
* scroll view and state. Calling raw `reactScrollTo` doesn't update state.
|
||||
*
|
||||
* <p>Note that while we can override scrollTo, we *cannot* override `smoothScrollTo` because it
|
||||
* is final. See `reactSmoothScrollTo`.
|
||||
*/
|
||||
public void reactScrollTo(int x, int y) {
|
||||
scrollTo(x, y);
|
||||
@Override
|
||||
public void scrollTo(int x, int y) {
|
||||
super.scrollTo(x, y);
|
||||
updateStateOnScroll(x, y);
|
||||
setPendingContentOffsets(x, y);
|
||||
}
|
||||
@@ -926,7 +930,7 @@ public class ReactScrollView extends ScrollView
|
||||
int currentScrollY = getScrollY();
|
||||
int maxScrollY = getMaxScrollY();
|
||||
if (currentScrollY > maxScrollY) {
|
||||
reactScrollTo(getScrollX(), maxScrollY);
|
||||
scrollTo(getScrollX(), maxScrollY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -206,7 +206,7 @@ public class ReactScrollViewManager extends ViewGroupManager<ReactScrollView>
|
||||
if (data.mAnimated) {
|
||||
scrollView.reactSmoothScrollTo(data.mDestX, data.mDestY);
|
||||
} else {
|
||||
scrollView.reactScrollTo(data.mDestX, data.mDestY);
|
||||
scrollView.scrollTo(data.mDestX, data.mDestY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ public class ReactScrollViewManager extends ViewGroupManager<ReactScrollView>
|
||||
if (data.mAnimated) {
|
||||
scrollView.reactSmoothScrollTo(scrollView.getScrollX(), bottom);
|
||||
} else {
|
||||
scrollView.reactScrollTo(scrollView.getScrollX(), bottom);
|
||||
scrollView.scrollTo(scrollView.getScrollX(), bottom);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,9 +310,9 @@ public class ReactScrollViewManager extends ViewGroupManager<ReactScrollView>
|
||||
if (value != null) {
|
||||
double x = value.hasKey("x") ? value.getDouble("x") : 0;
|
||||
double y = value.hasKey("y") ? value.getDouble("y") : 0;
|
||||
view.reactScrollTo((int) PixelUtil.toPixelFromDIP(x), (int) PixelUtil.toPixelFromDIP(y));
|
||||
view.scrollTo((int) PixelUtil.toPixelFromDIP(x), (int) PixelUtil.toPixelFromDIP(y));
|
||||
} else {
|
||||
view.reactScrollTo(0, 0);
|
||||
view.scrollTo(0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user