From 08a1d83652a3e33ce3b7fb71884f7e2c94accc40 Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Mon, 17 Apr 2023 20:41:49 -0700 Subject: [PATCH] Refactor code syntax in internal classes to be easier to provide code coverage Summary: Similar to the previous diff, this diff updates some of the code styling and syntax in IGListKit's internal classes to make it much easier to provide test coverage to each method in there. Reviewed By: candance Differential Revision: D45003471 fbshipit-source-id: 1267901fc7a917bf1c30783654a8fd0da941bff1 --- .../Internal/IGListUpdateTransactionBuilder.m | 3 +-- ...llectionViewLayout+InteractiveReordering.m | 26 ++++++++++++------- .../Internal/UIScrollView+IGListKit.m | 6 ++--- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Source/IGListKit/Internal/IGListUpdateTransactionBuilder.m b/Source/IGListKit/Internal/IGListUpdateTransactionBuilder.m index 96e839a1..1fdc2e19 100644 --- a/Source/IGListKit/Internal/IGListUpdateTransactionBuilder.m +++ b/Source/IGListKit/Internal/IGListUpdateTransactionBuilder.m @@ -147,7 +147,7 @@ typedef NS_ENUM (NSInteger, IGListUpdateTransactionBuilderMode) { } switch (self.mode) { - case IGListUpdateTransactionBuilderModeBatchUpdate: { + case IGListUpdateTransactionBuilderModeBatchUpdate: return [[IGListBatchUpdateTransaction alloc] initWithCollectionViewBlock:collectionViewBlock updater:updater delegate:delegate @@ -157,7 +157,6 @@ typedef NS_ENUM (NSInteger, IGListUpdateTransactionBuilderMode) { applySectionDataBlock:self.applySectionDataBlock itemUpdateBlocks:self.itemUpdateBlocks completionBlocks:self.completionBlocks]; - } case IGListUpdateTransactionBuilderModeReload: { IGListReloadUpdateBlock reloadBlock = self.reloadBlock; if (!reloadBlock) { diff --git a/Source/IGListKit/Internal/UICollectionViewLayout+InteractiveReordering.m b/Source/IGListKit/Internal/UICollectionViewLayout+InteractiveReordering.m index 5e3dcf91..4c950b09 100644 --- a/Source/IGListKit/Internal/UICollectionViewLayout+InteractiveReordering.m +++ b/Source/IGListKit/Internal/UICollectionViewLayout+InteractiveReordering.m @@ -70,10 +70,8 @@ static void * kIGListAdapterKey = &kIGListAdapterKey; NSIndexPath *updatedTarget = [self updatedTargetForInteractivelyMovingItem:previousIndexPath toIndexPath:originalTarget adapter:adapter]; - if (updatedTarget) { - return updatedTarget; - } - return originalTarget; + + return updatedTarget ?: originalTarget; } - (nullable NSIndexPath *)updatedTargetForInteractivelyMovingItem:(NSIndexPath *)previousIndexPath @@ -177,12 +175,9 @@ static void * kIGListAdapterKey = &kIGListAdapterKey; } [modifiedContext invalidateItemsAtIndexPaths:invalidatedItemIndexPaths]; - [originalContext.invalidatedSupplementaryIndexPaths enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSArray * _Nonnull obj, BOOL * _Nonnull stop) { - [modifiedContext invalidateSupplementaryElementsOfKind:key atIndexPaths:obj]; - }]; - [originalContext.invalidatedDecorationIndexPaths enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSArray * _Nonnull obj, BOOL * _Nonnull stop) { - [modifiedContext invalidateDecorationElementsOfKind:key atIndexPaths:obj]; - }]; + [self ig_invalidateAccessoryElementsWithSupplementaryIndexPaths:originalContext.invalidatedSupplementaryIndexPaths + decorationIndexPaths:originalContext.invalidatedDecorationIndexPaths + inContext:modifiedContext]; modifiedContext.contentOffsetAdjustment = originalContext.contentOffsetAdjustment; modifiedContext.contentSizeAdjustment = originalContext.contentSizeAdjustment; @@ -192,4 +187,15 @@ static void * kIGListAdapterKey = &kIGListAdapterKey; return originalContext; } +- (void)ig_invalidateAccessoryElementsWithSupplementaryIndexPaths:(NSDictionary *> *)supplementaryIndexPaths + decorationIndexPaths:(NSDictionary *> *)decorationIndexPaths + inContext:(UICollectionViewLayoutInvalidationContext *)context { + [supplementaryIndexPaths enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSArray *obj, BOOL *stop) { + [context invalidateSupplementaryElementsOfKind:key atIndexPaths:obj]; + }]; + [decorationIndexPaths enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSArray *obj, BOOL *stop) { + [context invalidateDecorationElementsOfKind:key atIndexPaths:obj]; + }]; +} + @end diff --git a/Source/IGListKit/Internal/UIScrollView+IGListKit.m b/Source/IGListKit/Internal/UIScrollView+IGListKit.m index fcfac925..a19d68e7 100644 --- a/Source/IGListKit/Internal/UIScrollView+IGListKit.m +++ b/Source/IGListKit/Internal/UIScrollView+IGListKit.m @@ -11,11 +11,11 @@ - (UIEdgeInsets) ig_contentInset { + UIEdgeInsets contentInset = self.contentInset; if (@available(iOS 11.0, tvOS 11.0, *)) { - return self.adjustedContentInset; - } else { - return self.contentInset; + contentInset = self.adjustedContentInset; } + return contentInset; } @end