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 authored Jun 1, 2019
1 parent 18feded commit 42f6749
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -1667,26 +1667,28 @@ 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>),
},
prevCellKey: ?string,
}

class CellRenderer extends React.Component<
CellRendererProps,
$FlowFixMeState,
> {
state = {
Expand All @@ -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: {
Expand Down

0 comments on commit 42f6749

Please sign in to comment.