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,8 +1667,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
}
}
class CellRenderer extends React.Component<
{
type CellRendererProps = {
CellRendererComponent?: ?React.ComponentType<any>,
ItemSeparatorComponent: ?React.ComponentType<*>,
cellKey: string,
@ -1686,8 +1685,18 @@ class CellRenderer extends React.Component<
ListItemComponent?: ?(React.ComponentType<any> | React.Element<any>),
},
prevCellKey: ?string,
},
$FlowFixMeState,
};
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: {