diff --git a/src/MasonryList.js b/src/MasonryList.js index ac1ba32..652ee02 100644 --- a/src/MasonryList.js +++ b/src/MasonryList.js @@ -47,6 +47,11 @@ export type Props = { renderItem: ({ item: any, index: number, column: number }) => ?React.Element< any, >, + onViewableItemsChanged: ({ + viewableItems: Array, + changed: Array, + column: number, + }) => void, getHeightForItem: ({ item: any, index: number }) => number, ListHeaderComponent?: ?React.ComponentType, ListEmptyComponent?: ?React.ComponentType, @@ -221,6 +226,8 @@ export default class MasonryList extends React.Component { ListEmptyComponent, keyExtractor, onEndReached, + listKey, + onViewableItemsChanged, ...props } = this.props; let headerElement; @@ -238,7 +245,8 @@ export default class MasonryList extends React.Component { (this._listRefs[col.index] = ref)} - key={`$col_${col.index}`} + key={`${listKey}_${col.index}`} + listKey={`${listKey}_${col.index}`} data={col.data} getItemCount={this._getItemCount} getItem={this._getItem} @@ -251,6 +259,13 @@ export default class MasonryList extends React.Component { onEndReached={onEndReached} onEndReachedThreshold={this.props.onEndReachedThreshold} removeClippedSubviews={false} + onViewableItemsChanged={({ viewableItems, changed }) => + onViewableItemsChanged && + onViewableItemsChanged({ + viewableItems, + changed, + column: col.index, + })} />, )}