From 6dfdce1d5eea31d78724bddeab74ebba6e8d8e54 Mon Sep 17 00:00:00 2001 From: Zhisheng Huang Date: Thu, 20 Feb 2020 15:20:51 -0800 Subject: [PATCH] Remove IGListBindingSingleSectionController's displayDelegate override Summary: There is a KP in IGListBindingSingleSectionController that we need to override the `displayDelegate` in order to track the displayingCell for performant update, when the section controller is not visible. With the newly refactoring in how IGListSectionController handles the displaying events, IGListBindingSingleSectionController can now override the willDisplay/endDisplay calls without manually adding itself as the `displayDelegate`, the behavior works as before. Differential Revision: D19973670 fbshipit-source-id: 1f9fec1bf88aa8755c163c636ebb49b377e6873c --- .../IGListBindingSingleSectionController.m | 46 +++++++------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/Source/IGListKit/IGListBindingSingleSectionController.m b/Source/IGListKit/IGListBindingSingleSectionController.m index f57bdc55..82f76908 100644 --- a/Source/IGListKit/IGListBindingSingleSectionController.m +++ b/Source/IGListKit/IGListBindingSingleSectionController.m @@ -8,8 +8,9 @@ #import "IGListBindingSingleSectionController.h" #import +#import "IGListSectionControllerInternal.h" -@interface IGListBindingSingleSectionController () +@interface IGListBindingSingleSectionController () @end @@ -18,13 +19,6 @@ __weak UICollectionViewCell *_displayingCell; } -- (instancetype)init { - if (self = [super init]) { - self.displayDelegate = self; - } - return self; -} - - (void)didSelectItemWithCell:(UICollectionViewCell *)cell { // no-op } @@ -55,28 +49,6 @@ return CGSizeZero; } -#pragma mark - IGListDisplayDelegate - -- (void)listAdapter:(nonnull IGListAdapter *)listAdapter willDisplaySectionController:(nonnull IGListSectionController *)sectionController { - // no-op -} - -- (void)listAdapter:(nonnull IGListAdapter *)listAdapter didEndDisplayingSectionController:(nonnull IGListSectionController *)sectionController { - // no-op -} - -- (void)listAdapter:(nonnull IGListAdapter *)listAdapter willDisplaySectionController:(nonnull IGListSectionController *)sectionController cell:(nonnull UICollectionViewCell *)cell atIndex:(NSInteger)index { - IGParameterAssert(index == 0); - _displayingCell = cell; -} - -- (void)listAdapter:(nonnull IGListAdapter *)listAdapter didEndDisplayingSectionController:(nonnull IGListSectionController *)sectionController cell:(nonnull UICollectionViewCell *)cell atIndex:(NSInteger)index { - IGParameterAssert(index == 0); - if (cell == _displayingCell) { - _displayingCell = nil; - } -} - #pragma mark - IGListSectionController Overrides - (NSInteger)numberOfItems { @@ -130,4 +102,18 @@ [self didUnhighlightItemWithCell:cell]; } +- (void)willDisplayCell:(UICollectionViewCell *)cell atIndex:(NSInteger)index listAdapter:(IGListAdapter *)listAdapter { + IGParameterAssert(index == 0); + _displayingCell = cell; + [super willDisplayCell:cell atIndex:index listAdapter:listAdapter]; +} + +- (void)didEndDisplayingCell:(UICollectionViewCell *)cell atIndex:(NSInteger)index listAdapter:(IGListAdapter *)listAdapter { + IGParameterAssert(index == 0); + if (cell == _displayingCell) { + _displayingCell = nil; + } + [super didEndDisplayingCell:cell atIndex:index listAdapter:listAdapter]; +} + @end