Skip to content

Commit 488a4c7

Browse files
sahrensfacebook-github-bot
authored andcommittedMay 25, 2018
Fix VirtualizedSectionList:ItemWithSeparators
Reviewed By: yungsters Differential Revision: D8021407 fbshipit-source-id: 480547d867eda476fe6ddf4af74072ad1851a427
1 parent 4fd5946 commit 488a4c7

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed
 

‎Libraries/Lists/VirtualizedSectionList.js

+33-15
Original file line numberDiff line numberDiff line change
@@ -378,25 +378,40 @@ class VirtualizedSectionList<SectionT: SectionBase> extends React.PureComponent<
378378
};
379379
}
380380

381-
type ItemWithSeparatorProps = {
382-
LeadingSeparatorComponent: ?React.ComponentType<*>,
383-
SeparatorComponent: ?React.ComponentType<*>,
381+
type ItemWithSeparatorCommonProps = $ReadOnly<{|
382+
leadingItem: ?Item,
383+
leadingSection: ?Object,
384+
section: Object,
385+
trailingItem: ?Item,
386+
trailingSection: ?Object,
387+
|}>;
388+
389+
type ItemWithSeparatorProps = $ReadOnly<{|
390+
...ItemWithSeparatorCommonProps,
391+
LeadingSeparatorComponent: ?React.ComponentType<any>,
392+
SeparatorComponent: ?React.ComponentType<any>,
384393
cellKey: string,
385394
index: number,
386395
item: Item,
387396
onUpdateSeparator: (cellKey: string, newProps: Object) => void,
388397
prevCellKey?: ?string,
389398
renderItem: Function,
390-
section: Object,
391-
leadingItem: ?Item,
392-
leadingSection: ?Object,
393-
trailingItem: ?Item,
394-
trailingSection: ?Object,
399+
|}>;
400+
401+
type ItemWithSeparatorState = {
402+
separatorProps: $ReadOnly<{|
403+
highlighted: false,
404+
...ItemWithSeparatorCommonProps,
405+
|}>,
406+
leadingSeparatorProps: $ReadOnly<{|
407+
highlighted: false,
408+
...ItemWithSeparatorCommonProps,
409+
|}>,
395410
};
396411

397412
class ItemWithSeparator extends React.Component<
398413
ItemWithSeparatorProps,
399-
$FlowFixMeState,
414+
ItemWithSeparatorState,
400415
> {
401416
state = {
402417
separatorProps: {
@@ -430,7 +445,7 @@ class ItemWithSeparator extends React.Component<
430445
},
431446
updateProps: (select: 'leading' | 'trailing', newProps: Object) => {
432447
const {LeadingSeparatorComponent, cellKey, prevCellKey} = this.props;
433-
if (select === 'leading' && LeadingSeparatorComponent) {
448+
if (select === 'leading' && LeadingSeparatorComponent != null) {
434449
this.setState(state => ({
435450
leadingSeparatorProps: {...state.leadingSeparatorProps, ...newProps},
436451
}));
@@ -443,25 +458,28 @@ class ItemWithSeparator extends React.Component<
443458
},
444459
};
445460

446-
UNSAFE_componentWillReceiveProps(props: ItemWithSeparatorProps) {
447-
this.setState(state => ({
461+
static getDerivedStateFromProps(
462+
props: ItemWithSeparatorProps,
463+
prevState: ItemWithSeparatorState,
464+
): ?ItemWithSeparatorState {
465+
return {
448466
separatorProps: {
449-
...this.state.separatorProps,
467+
...prevState.separatorProps,
450468
leadingItem: props.item,
451469
leadingSection: props.leadingSection,
452470
section: props.section,
453471
trailingItem: props.trailingItem,
454472
trailingSection: props.trailingSection,
455473
},
456474
leadingSeparatorProps: {
457-
...this.state.leadingSeparatorProps,
475+
...prevState.leadingSeparatorProps,
458476
leadingItem: props.leadingItem,
459477
leadingSection: props.leadingSection,
460478
section: props.section,
461479
trailingItem: props.item,
462480
trailingSection: props.trailingSection,
463481
},
464-
}));
482+
};
465483
}
466484

467485
updateSeparatorProps(newProps: Object) {

0 commit comments

Comments
 (0)
Please sign in to comment.