Fix ItemSeparatorComponent's leadingItem prop not being updated (#25114)

Summary:
Fix https://github.com/facebook/react-native/issues/24592

Just added a `getDerivedStateFromProps`, similar to what `VirtualizedSectionList` already does: 18fededae0/Libraries/Lists/VirtualizedSectionList.js (L470-L492)

## Changelog

[General] [Fixed] - Fix ItemSeparatorComponent's leadingItem prop not being updated
Pull Request resolved: https://github.com/facebook/react-native/pull/25114

Differential Revision: D15602460

Pulled By: cpojer

fbshipit-source-id: b16a82912fd746a956f6aa360d18ade53357f634
This commit is contained in:
Bruno Lemos 2019-06-03 07:30:56 -07:00 коммит произвёл Facebook Github Bot
Родитель 93dc403e1b
Коммит 1e428093e2
1 изменённых файлов: 41 добавлений и 20 удалений

Просмотреть файл

@ -1667,27 +1667,36 @@ class VirtualizedList extends React.PureComponent<Props, State> {
}
}
class CellRenderer extends React.Component<
{
CellRendererComponent?: ?React.ComponentType<any>,
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<?string>, props: Object) => void,
parentProps: {
getItemLayout?: ?Function,
renderItem?: ?RenderItemType<Item>,
ListItemComponent?: ?(React.ComponentType<any> | React.Element<any>),
},
prevCellKey: ?string,
type CellRendererProps = {
CellRendererComponent?: ?React.ComponentType<any>,
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<?string>, props: Object) => void,
parentProps: {
getItemLayout?: ?Function,
renderItem?: ?RenderItemType<Item>,
ListItemComponent?: ?(React.ComponentType<any> | React.Element<any>),
},
$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: {