From 5042bae259cefb2128361e5d798b4c92befec0a9 Mon Sep 17 00:00:00 2001 From: Spencer Ahrens Date: Thu, 16 Feb 2017 18:59:57 -0800 Subject: [PATCH] Clean up separator stuff Reviewed By: bvaughn Differential Revision: D4561262 fbshipit-source-id: 990f338c197851252bea4902fa86249d6e1c975b --- .../Experimental/VirtualizedSectionList.js | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/Libraries/Experimental/VirtualizedSectionList.js b/Libraries/Experimental/VirtualizedSectionList.js index 620c4f343bfcd9..b669aeafb32a58 100644 --- a/Libraries/Experimental/VirtualizedSectionList.js +++ b/Libraries/Experimental/VirtualizedSectionList.js @@ -219,36 +219,33 @@ class VirtualizedSectionList return ; } 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 ( - {shouldRenderItemSeparator ? : null} - {shouldRenderSectionSeparator ? : null} + {SeparatorComponent && } ); } }; - _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) => { @@ -256,14 +253,7 @@ class VirtualizedSectionList 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): State {