From 42f6749fd0966223ff663cd1f9a0530fab7dcc80 Mon Sep 17 00:00:00 2001 From: Bruno Lemos Date: Sat, 1 Jun 2019 15:51:04 -0300 Subject: [PATCH] Fix ItemSeparatorComponent not updating leadingItem prop Fix https://github.com/facebook/react-native/issues/24592 --- Libraries/Lists/VirtualizedList.js | 52 +++++++++++++++++++----------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index 0281d87c8a3418..5ab2a0b14f2223 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -1667,26 +1667,28 @@ 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), }, + prevCellKey: ?string, +} + +class CellRenderer extends React.Component< + CellRendererProps, $FlowFixMeState, > { state = { @@ -1702,6 +1704,18 @@ class CellRenderer extends React.Component< }), }; + static getDerivedStateFromProps( + props: CellRendererProps, + prevState: FlowFixMeState, + ): ?FlowFixMeState { + return { + separatorProps: { + ...prevState.separatorProps, + leadingItem: props.item, + }, + }; + }; + getChildContext() { return { virtualizedCell: {