Skip to content

Commit

Permalink
Clean up separator stuff
Browse files Browse the repository at this point in the history
Reviewed By: bvaughn

Differential Revision: D4561262

fbshipit-source-id: 990f338c197851252bea4902fa86249d6e1c975b
  • Loading branch information
sahrens authored and facebook-github-bot committed Feb 17, 2017
1 parent 63d3ea1 commit 5042bae
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions Libraries/Experimental/VirtualizedSectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,51 +219,41 @@ class VirtualizedSectionList<SectionT: SectionBase>
return <this.props.SectionHeaderComponent section={info.section} />;
} else {
const ItemComponent = info.section.ItemComponent || this.props.ItemComponent;
const SeparatorComponent = info.section.SeparatorComponent || this.props.SeparatorComponent;
const {SectionSeparatorComponent} = this.props;
const [shouldRenderSectionSeparator, shouldRenderItemSeparator] =
this._shouldRenderSeparators(index, info);
const SeparatorComponent = this._getSeparatorComponent(index, info);
return (
<View>
<ItemComponent item={item} index={info.index} />
{shouldRenderItemSeparator ? <SeparatorComponent /> : null}
{shouldRenderSectionSeparator ? <SectionSeparatorComponent /> : null}
{SeparatorComponent && <SeparatorComponent />}
</View>
);
}
};

_shouldRenderSeparators(index: number, info?: ?Object): [boolean, boolean] {
_getSeparatorComponent(index: number, info?: ?Object): ?ReactClass<*> {
info = info || this._subExtractor(index);
if (!info) {
return [false, false];
return null;
}
const SeparatorComponent = info.section.SeparatorComponent || this.props.SeparatorComponent;
const {SectionSeparatorComponent} = this.props;
const lastItemIndex = this.state.childProps.getItemCount() - 1;
let shouldRenderSectionSeparator = false;
if (SectionSeparatorComponent) {
shouldRenderSectionSeparator =
info.index === info.section.data.length - 1 && index < lastItemIndex;
if (SectionSeparatorComponent &&
info.index === info.section.data.length - 1 &&
index < lastItemIndex) {
return SectionSeparatorComponent;
}
if (SeparatorComponent && index < lastItemIndex) {
return SeparatorComponent;
}
const shouldRenderItemSeparator = SeparatorComponent && !shouldRenderSectionSeparator &&
index < lastItemIndex;
return [shouldRenderSectionSeparator, shouldRenderItemSeparator];
return null;
}

_shouldItemUpdate = (prev, next) => {
const {shouldItemUpdate} = this.props;
if (!shouldItemUpdate || shouldItemUpdate(prev, next)) {
return true;
}
if (prev.index !== next.index) {
const [secSepPrev, itSepPrev] = this._shouldRenderSeparators(prev.index);
const [secSepNext, itSepNext] = this._shouldRenderSeparators(next.index);
if (secSepPrev !== secSepNext || itSepPrev !== itSepNext) {
return true;
}
}
return false;
return this._getSeparatorComponent(prev.index) !== this._getSeparatorComponent(next.index);
}

_computeState(props: Props<SectionT>): State {
Expand Down

1 comment on commit 5042bae

@hramos
Copy link
Contributor

@hramos hramos commented on 5042bae Feb 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit is breaking open source tests in Circle and will be reverted in #12526.

Please sign in to comment.