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
This commit is contained in:
Brent Vatne
2016-01-13 07:30:20 -08:00
committed by facebook-github-bot-2
parent cac56a61fc
commit f8f5cb1fcf

View File

@@ -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();