Skip to content

Commit 1e42809

Browse files
brunolemosfacebook-github-bot
authored andcommitted
Fix ItemSeparatorComponent's leadingItem prop not being updated (#25114)
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
1 parent 93dc403 commit 1e42809

File tree

1 file changed

+41
-20
lines changed

1 file changed

+41
-20
lines changed

Libraries/Lists/VirtualizedList.js

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,27 +1667,36 @@ class VirtualizedList extends React.PureComponent<Props, State> {
16671667
}
16681668
}
16691669

1670-
class CellRenderer extends React.Component<
1671-
{
1672-
CellRendererComponent?: ?React.ComponentType<any>,
1673-
ItemSeparatorComponent: ?React.ComponentType<*>,
1674-
cellKey: string,
1675-
fillRateHelper: FillRateHelper,
1676-
horizontal: ?boolean,
1677-
index: number,
1678-
inversionStyle: ViewStyleProp,
1679-
item: Item,
1680-
onLayout: (event: Object) => void, // This is extracted by ScrollViewStickyHeader
1681-
onUnmount: (cellKey: string) => void,
1682-
onUpdateSeparators: (cellKeys: Array<?string>, props: Object) => void,
1683-
parentProps: {
1684-
getItemLayout?: ?Function,
1685-
renderItem?: ?RenderItemType<Item>,
1686-
ListItemComponent?: ?(React.ComponentType<any> | React.Element<any>),
1687-
},
1688-
prevCellKey: ?string,
1670+
type CellRendererProps = {
1671+
CellRendererComponent?: ?React.ComponentType<any>,
1672+
ItemSeparatorComponent: ?React.ComponentType<*>,
1673+
cellKey: string,
1674+
fillRateHelper: FillRateHelper,
1675+
horizontal: ?boolean,
1676+
index: number,
1677+
inversionStyle: ViewStyleProp,
1678+
item: Item,
1679+
onLayout: (event: Object) => void, // This is extracted by ScrollViewStickyHeader
1680+
onUnmount: (cellKey: string) => void,
1681+
onUpdateSeparators: (cellKeys: Array<?string>, props: Object) => void,
1682+
parentProps: {
1683+
getItemLayout?: ?Function,
1684+
renderItem?: ?RenderItemType<Item>,
1685+
ListItemComponent?: ?(React.ComponentType<any> | React.Element<any>),
16891686
},
1690-
$FlowFixMeState,
1687+
prevCellKey: ?string,
1688+
};
1689+
1690+
type CellRendererState = {
1691+
separatorProps: $ReadOnly<{|
1692+
highlighted: boolean,
1693+
leadingItem: ?Item,
1694+
|}>,
1695+
};
1696+
1697+
class CellRenderer extends React.Component<
1698+
CellRendererProps,
1699+
CellRendererState,
16911700
> {
16921701
state = {
16931702
separatorProps: {
@@ -1702,6 +1711,18 @@ class CellRenderer extends React.Component<
17021711
}),
17031712
};
17041713

1714+
static getDerivedStateFromProps(
1715+
props: CellRendererProps,
1716+
prevState: CellRendererState,
1717+
): ?CellRendererState {
1718+
return {
1719+
separatorProps: {
1720+
...prevState.separatorProps,
1721+
leadingItem: props.item,
1722+
},
1723+
};
1724+
}
1725+
17051726
getChildContext() {
17061727
return {
17071728
virtualizedCell: {

0 commit comments

Comments
 (0)