Skip to content

Commit

Permalink
Fix ItemSeparatorComponent not updating leadingItem prop
Browse files Browse the repository at this point in the history
Fix #24592
  • Loading branch information
brunolemos committed Jun 1, 2019
1 parent 18feded commit 9453284
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 9453284

Please sign in to comment.