Skip to content

Commit fcec815

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Fix what updateState in ScrollView when called from reactSmoothScrollTo
Summary: Changelog: [Internal] # Problem Fabric didn't know about content offset, even though `reactSmoothScrollTo` calls `updateStateOnScroll`, the value of content offset is {0, 0}. # Fix Call `updateStateOnScroll` from `reactSmoothScrollTo` with where the scroll view is going to be rather than where it is. Reviewed By: JoshuaGross, mdvacca Differential Revision: D20248959 fbshipit-source-id: b1da645576dd5e8dce29e7e1d90ab232e0df9fd5
1 parent 4f908a5 commit fcec815

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public boolean onTouchEvent(MotionEvent ev) {
299299
mVelocityHelper.calculateVelocity(ev);
300300
int action = ev.getAction() & MotionEvent.ACTION_MASK;
301301
if (action == MotionEvent.ACTION_UP && mDragging) {
302-
updateStateOnScroll();
302+
updateStateOnScroll(getScrollX(), getScrollY());
303303

304304
float velocityX = mVelocityHelper.getXVelocity();
305305
float velocityY = mVelocityHelper.getYVelocity();
@@ -502,7 +502,7 @@ public void run() {
502502
ViewCompat.postOnAnimationDelayed(
503503
ReactScrollView.this, this, ReactScrollViewHelper.MOMENTUM_DELAY);
504504
} else {
505-
updateStateOnScroll();
505+
updateStateOnScroll(getScrollX(), getScrollY());
506506

507507
if (mPagingEnabled && !mSnappingToPage) {
508508
// Only if we have pagingEnabled and we have not snapped to the page do we
@@ -776,7 +776,7 @@ public void onChildViewRemoved(View parent, View child) {
776776
*/
777777
public void reactSmoothScrollTo(int x, int y) {
778778
smoothScrollTo(x, y);
779-
updateStateOnScroll();
779+
updateStateOnScroll(x, y);
780780
}
781781

782782
/**
@@ -787,7 +787,7 @@ public void reactSmoothScrollTo(int x, int y) {
787787
*/
788788
public void reactScrollTo(int x, int y) {
789789
scrollTo(x, y);
790-
updateStateOnScroll();
790+
updateStateOnScroll(x, y);
791791
}
792792

793793
/**
@@ -849,14 +849,14 @@ public void updateState(@Nullable StateWrapper stateWrapper) {
849849
/**
850850
* Called on any stabilized onScroll change to propagate content offset value to a Shadow Node.
851851
*/
852-
private void updateStateOnScroll() {
852+
private void updateStateOnScroll(int scrollX, int scrollY) {
853853
if (mStateWrapper == null) {
854854
return;
855855
}
856856

857857
WritableMap map = new WritableNativeMap();
858-
map.putDouble(CONTENT_OFFSET_LEFT, PixelUtil.toDIPFromPixel(getScrollX()));
859-
map.putDouble(CONTENT_OFFSET_TOP, PixelUtil.toDIPFromPixel(getScrollY()));
858+
map.putDouble(CONTENT_OFFSET_LEFT, PixelUtil.toDIPFromPixel(scrollX));
859+
map.putDouble(CONTENT_OFFSET_TOP, PixelUtil.toDIPFromPixel(scrollY));
860860

861861
mStateWrapper.updateState(map);
862862
}

0 commit comments

Comments
 (0)