Fix `getItemLayout` flow type to include `index`
Summary: The index is used to make sure the layout corresponds to the correct index, which can get out of sync if cell layout is cached and then cells are re-ordered. Reviewed By: bvaughn Differential Revision: D4554721 fbshipit-source-id: 9acb37f390a6e40ad89f813b78f81b399ec11e9a
This commit is contained in:
parent
b2c545dcb6
commit
91bda43e56
|
@ -114,7 +114,7 @@ class MultiColumnExample extends React.PureComponent {
|
|||
</UIExplorerPage>
|
||||
);
|
||||
}
|
||||
_getItemLayout(data: any, index: number): {length: number, offset: number} {
|
||||
_getItemLayout(data: any, index: number): {length: number, offset: number, index: number} {
|
||||
return getItemLayout(data, index);
|
||||
}
|
||||
_renderItemComponent = ({item}) => {
|
||||
|
|
|
@ -74,12 +74,13 @@ type OptionalProps = {
|
|||
* you know the height of items a priori. getItemLayout is the most efficient, and is easy to use
|
||||
* if you have fixed height items, for example:
|
||||
*
|
||||
* getItemLayout={(data, index) => ({length: ITEM_HEIGHT, offset: ITEM_HEIGHT * index})}
|
||||
* getItemLayout={(data, index) => ({length: ITEM_HEIGHT, offset: ITEM_HEIGHT * index, index})}
|
||||
*
|
||||
* Remember to include separator length (height or width) in your offset calculation if you
|
||||
* specify `SeparatorComponent`.
|
||||
*/
|
||||
getItemLayout?: (data: ?Array<Item>, index: number) => {length: number, offset: number},
|
||||
getItemLayout?: (data: ?Array<Item>, index: number) =>
|
||||
{length: number, offset: number, index: number},
|
||||
/**
|
||||
* If true, renders items next to each other horizontally instead of stacked vertically.
|
||||
*/
|
||||
|
|
|
@ -87,7 +87,8 @@ type OptionalProps = {
|
|||
disableVirtualization: boolean,
|
||||
getItem: (items: any, index: number) => ?Item,
|
||||
getItemCount: (items: any) => number,
|
||||
getItemLayout?: (items: any, index: number) => {length: number, offset: number}, // e.g. height, y
|
||||
getItemLayout?: (items: any, index: number) =>
|
||||
{length: number, offset: number, index: number}, // e.g. height, y
|
||||
horizontal: boolean,
|
||||
initialNumToRender: number,
|
||||
keyExtractor: (item: Item, index: number) => string,
|
||||
|
|
Loading…
Reference in New Issue