diff --git a/Source/IGListKit/IGListBindingSingleSectionController.h b/Source/IGListKit/IGListBindingSingleSectionController.h index aa619c15..dac74192 100644 --- a/Source/IGListKit/IGListBindingSingleSectionController.h +++ b/Source/IGListKit/IGListBindingSingleSectionController.h @@ -20,6 +20,9 @@ NS_ASSUME_NONNULL_BEGIN NS_SWIFT_NAME(ListBindingSingleSectionController) @interface IGListBindingSingleSectionController<__covariant ViewModel : id, Cell : UICollectionViewCell *> : IGListSectionController +// Testing the stability of this infra. Defaults to NO. +@property (nonatomic, readwrite, assign) BOOL enabledCellConfigurationDuringUpdate; + #pragma mark - Subclass // Required to be implemented by subclass. diff --git a/Source/IGListKit/IGListBindingSingleSectionController.m b/Source/IGListKit/IGListBindingSingleSectionController.m index e00c28e8..768f2235 100644 --- a/Source/IGListKit/IGListBindingSingleSectionController.m +++ b/Source/IGListKit/IGListBindingSingleSectionController.m @@ -9,9 +9,20 @@ #import +@interface IGListBindingSingleSectionController () + +@end @implementation IGListBindingSingleSectionController { id _item; + __weak UICollectionViewCell *_displayingCell; +} + +- (instancetype)init { + if (self = [super init]) { + self.displayDelegate = self; + } + return self; } - (void)didSelectItemWithCell:(UICollectionViewCell *)cell { @@ -44,6 +55,26 @@ 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); + _displayingCell = nil; +} + #pragma mark - IGListSectionController Overrides - (NSInteger)numberOfItems { @@ -66,9 +97,10 @@ - (void)didUpdateToObject:(id)object { _item = object; - UICollectionViewCell *cell = [self.collectionContext cellForItemAtIndex:0 sectionController:self]; - if (cell) { - [self configureCell:cell withViewModel:_item]; + if (_enabledCellConfigurationDuringUpdate) { + if (_displayingCell) { + [self configureCell:_displayingCell withViewModel:_item]; + } } }