Skip to content

Commit

Permalink
Fix ItemSeparatorComponent's leadingItem prop not being updated (#25114)
Browse files Browse the repository at this point in the history
Summary:
Fix #24592

Just added a `getDerivedStateFromProps`, similar to what `VirtualizedSectionList` already does: https://github.com/facebook/react-native/blob/18fededae085b53b01e54a7ed27e32c2318e7cae/Libraries/Lists/VirtualizedSectionList.js#L470-L492

## Changelog

[General] [Fixed] - Fix ItemSeparatorComponent's leadingItem prop not being updated
Pull Request resolved: #25114

Differential Revision: D15602460

Pulled By: cpojer

fbshipit-source-id: b16a82912fd746a956f6aa360d18ade53357f634
  • Loading branch information
brunolemos authored and facebook-github-bot committed Jun 3, 2019
1 parent 93dc403 commit 1e42809
Showing 1 changed file with 41 additions and 20 deletions.
61 changes: 41 additions & 20 deletions Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down

0 comments on commit 1e42809

Please sign in to comment.