From cad2d9b07290a49ea2a05ca9d88e64bdb799aac2 Mon Sep 17 00:00:00 2001 From: Maarten Schumacher Date: Wed, 12 Jul 2017 23:57:55 -0700 Subject: [PATCH] Be able to scroll to last item in list Summary: The invariant condition doesn't allow scrolling to the last index Here is a simple reproduction of the problem: https://snack.expo.io/BJ59gzWrZ Surely, if the last item is rendered, we should be able to scroll to it without an invariant failing? Tested locally that this change fixes the issue. Closes https://github.com/facebook/react-native/pull/14934 Differential Revision: D5414535 Pulled By: shergin fbshipit-source-id: 38dac4c0e2ae5e1e199a67ca0e98e8f7325e77f4 --- Libraries/Lists/VirtualizedList.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index 19f7a79bc..0638a6b20 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -235,7 +235,7 @@ class VirtualizedList extends React.PureComponent { `scrollToIndex out of range: ${index} vs ${getItemCount(data) - 1}`, ); invariant( - getItemLayout || index < this._highestMeasuredFrameIndex, + getItemLayout || index <= this._highestMeasuredFrameIndex, 'scrollToIndex should be used in conjunction with getItemLayout, ' + 'otherwise there is no way to know the location of an arbitrary index.', );