From f8f5cb1fcf893397ccb8172921e8dfaad8ff6150 Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Wed, 13 Jan 2016 07:30:20 -0800 Subject: [PATCH] Fix content offset calculations when scrolling up Summary: The offset is cached so it doesn't need to calculate the entire height on each scroll, but the cached value was being thrown away when you scroll up -- this fixes that. Found this because it was breaking an infinite scroll view that depended on the contentOffset.y value reported from onScroll. Closes https://github.com/facebook/react-native/pull/5278 Reviewed By: svcscm Differential Revision: D2827556 Pulled By: dmmiller fb-gh-sync-id: 0897b89de427cada7389113991444f57c970f980 --- .../recyclerview/RecyclerViewBackedScrollView.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/recyclerview/RecyclerViewBackedScrollView.java b/ReactAndroid/src/main/java/com/facebook/react/views/recyclerview/RecyclerViewBackedScrollView.java index 6ebfb211c..919764f84 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/recyclerview/RecyclerViewBackedScrollView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/recyclerview/RecyclerViewBackedScrollView.java @@ -117,16 +117,17 @@ public class RecyclerViewBackedScrollView extends RecyclerView { if (mLastRequestedPosition != index) { int sum = 0; int startIndex = 0; + + if (mLastRequestedPosition != -1) { + sum = mOffsetForLastPosition; + startIndex = mLastRequestedPosition; + } + if (mLastRequestedPosition < index) { - if (mLastRequestedPosition != -1) { - sum = mOffsetForLastPosition; - startIndex = mLastRequestedPosition; - } for (int i = startIndex; i < index; i++) { sum += mReactListAdapter.mViews.get(i).getMeasuredHeight(); } - } - else { + } else { if (index < (mLastRequestedPosition - index)) { for (int i = 0; i < index; i++) { sum += mReactListAdapter.mViews.get(i).getMeasuredHeight();