diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index 0281d87c8a3418..d060dbf9fa6d28 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -1667,27 +1667,36 @@ class VirtualizedList extends React.PureComponent { } } -class CellRenderer extends React.Component< - { - CellRendererComponent?: ?React.ComponentType, - ItemSeparatorComponent: ?React.ComponentType<*>, - cellKey: string, - fillRateHelper: FillRateHelper, - horizontal: ?boolean, - index: number, - inversionStyle: ViewStyleProp, - item: Item, - onLayout: (event: Object) => void, // This is extracted by ScrollViewStickyHeader - onUnmount: (cellKey: string) => void, - onUpdateSeparators: (cellKeys: Array, props: Object) => void, - parentProps: { - getItemLayout?: ?Function, - renderItem?: ?RenderItemType, - ListItemComponent?: ?(React.ComponentType | React.Element), - }, - prevCellKey: ?string, +type CellRendererProps = { + CellRendererComponent?: ?React.ComponentType, + ItemSeparatorComponent: ?React.ComponentType<*>, + cellKey: string, + fillRateHelper: FillRateHelper, + horizontal: ?boolean, + index: number, + inversionStyle: ViewStyleProp, + item: Item, + onLayout: (event: Object) => void, // This is extracted by ScrollViewStickyHeader + onUnmount: (cellKey: string) => void, + onUpdateSeparators: (cellKeys: Array, props: Object) => void, + parentProps: { + getItemLayout?: ?Function, + renderItem?: ?RenderItemType, + ListItemComponent?: ?(React.ComponentType | React.Element), }, - $FlowFixMeState, + prevCellKey: ?string, +}; + +type CellRendererState = { + separatorProps: $ReadOnly<{| + highlighted: boolean, + leadingItem: ?Item, + |}>, +}; + +class CellRenderer extends React.Component< + CellRendererProps, + CellRendererState, > { state = { separatorProps: { @@ -1702,6 +1711,18 @@ class CellRenderer extends React.Component< }), }; + static getDerivedStateFromProps( + props: CellRendererProps, + prevState: CellRendererState, + ): ?CellRendererState { + return { + separatorProps: { + ...prevState.separatorProps, + leadingItem: props.item, + }, + }; + } + getChildContext() { return { virtualizedCell: {