From e960e68c0f0f4a915b662463a80d68195baff8ad Mon Sep 17 00:00:00 2001 From: Zhisheng Huang Date: Thu, 20 Feb 2020 15:20:51 -0800 Subject: [PATCH] Move the display delegate invokation into IGListSectionController Summary: Previously, IGListDisplayHandler took over the sectionController's displayDelegate and invoke directly. We have requirement in other cases where we want to control the displayDelegate invokation, e.t. Subclass of IGListSectionController can listen to the willDisplay/endDisplay events and do other processing. Moving the displayDelegate invokation inside IGListSectionController would allow us to have better control on the invokation timing. Differential Revision: D19973669 fbshipit-source-id: 33d23bc7efb235d2e1ed99737200e56bb320b678 --- Source/IGListKit/IGListSectionController.m | 16 ++++++++++++++++ Source/IGListKit/Internal/IGListDisplayHandler.m | 11 +++++------ .../Internal/IGListSectionControllerInternal.h | 8 ++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Source/IGListKit/IGListSectionController.m b/Source/IGListKit/IGListSectionController.m index d614523d..fdb9b7bd 100644 --- a/Source/IGListKit/IGListSectionController.m +++ b/Source/IGListKit/IGListSectionController.m @@ -100,4 +100,20 @@ void IGListSectionControllerPopThread(void) { IGFailAssert(@"Section controller %@ must override %s if interactive reordering is enabled.", self, __PRETTY_FUNCTION__); } +- (void)willDisplayCell:(UICollectionViewCell *)cell atIndex:(NSInteger)index listAdapter:(IGListAdapter *)listAdapter { + [_displayDelegate listAdapter:listAdapter willDisplaySectionController:self cell:cell atIndex:index]; +} + +- (void)didEndDisplayingCell:(UICollectionViewCell *)cell atIndex:(NSInteger)index listAdapter:(IGListAdapter *)listAdapter { + [_displayDelegate listAdapter:listAdapter didEndDisplayingSectionController:self cell:cell atIndex:index]; +} + +- (void)willDisplaySectionControllerWithListAdapter:(IGListAdapter *)listAdapter { + [_displayDelegate listAdapter:listAdapter willDisplaySectionController:self]; +} + +- (void)didEndDisplayingSectionControllerWithListAdapter:(IGListAdapter *)listAdapter { + [_displayDelegate listAdapter:listAdapter didEndDisplayingSectionController:self]; +} + @end diff --git a/Source/IGListKit/Internal/IGListDisplayHandler.m b/Source/IGListKit/Internal/IGListDisplayHandler.m index 3ca38f7f..cb1efd6f 100644 --- a/Source/IGListKit/Internal/IGListDisplayHandler.m +++ b/Source/IGListKit/Internal/IGListDisplayHandler.m @@ -11,6 +11,7 @@ #import #import #import +#import @interface IGListDisplayHandler () @@ -48,7 +49,7 @@ [self.visibleViewObjectMap setObject:object forKey:view]; NSCountedSet *visibleListSections = self.visibleListSections; if ([visibleListSections countForObject:sectionController] == 0) { - [sectionController.displayDelegate listAdapter:listAdapter willDisplaySectionController:sectionController]; + [sectionController willDisplaySectionControllerWithListAdapter:listAdapter]; [listAdapter.delegate listAdapter:listAdapter willDisplayObject:object atIndex:indexPath.section]; } [visibleListSections addObject:sectionController]; @@ -73,7 +74,7 @@ [visibleSections removeObject:sectionController]; if ([visibleSections countForObject:sectionController] == 0) { - [sectionController.displayDelegate listAdapter:listAdapter didEndDisplayingSectionController:sectionController]; + [sectionController didEndDisplayingSectionControllerWithListAdapter:listAdapter]; [listAdapter.delegate listAdapter:listAdapter didEndDisplayingObject:object atIndex:section]; } } @@ -100,8 +101,7 @@ sectionController:(IGListSectionController *)sectionController object:(id)object indexPath:(NSIndexPath *)indexPath { - id displayDelegate = [sectionController displayDelegate]; - [displayDelegate listAdapter:listAdapter willDisplaySectionController:sectionController cell:cell atIndex:indexPath.item]; + [sectionController willDisplayCell:cell atIndex:indexPath.item listAdapter:listAdapter]; [self _willDisplayReusableView:cell forListAdapter:listAdapter sectionController:sectionController object:object indexPath:indexPath]; } @@ -114,8 +114,7 @@ if (object == nil) { return; } - - [sectionController.displayDelegate listAdapter:listAdapter didEndDisplayingSectionController:sectionController cell:cell atIndex:indexPath.item]; + [sectionController didEndDisplayingCell:cell atIndex:indexPath.item listAdapter:listAdapter]; [self _didEndDisplayingReusableView:cell forListAdapter:listAdapter sectionController:sectionController object:object indexPath:indexPath]; } diff --git a/Source/IGListKit/Internal/IGListSectionControllerInternal.h b/Source/IGListKit/Internal/IGListSectionControllerInternal.h index 75160afe..11c745b3 100644 --- a/Source/IGListKit/Internal/IGListSectionControllerInternal.h +++ b/Source/IGListKit/Internal/IGListSectionControllerInternal.h @@ -28,4 +28,12 @@ FOUNDATION_EXTERN void IGListSectionControllerPopThread(void); */ - (BOOL)canMoveItemAtIndex:(NSInteger)sourceItemIndex toIndex:(NSInteger)destinationItemIndex; +- (void)willDisplayCell:(UICollectionViewCell *)cell atIndex:(NSInteger)index listAdapter:(IGListAdapter *)listAdapter; + +- (void)didEndDisplayingCell:(UICollectionViewCell *)cell atIndex:(NSInteger)index listAdapter:(IGListAdapter *)listAdapter; + +- (void)willDisplaySectionControllerWithListAdapter:(IGListAdapter *)listAdapter; + +- (void)didEndDisplayingSectionControllerWithListAdapter:(IGListAdapter *)listAdapter; + @end