6464 return __val; \
6565 }
6666
67- #define ASIndexPathForSection (section ) [NSIndexPath indexPathForItem: 0 inSection: section]
68-
6967#define ASFlowLayoutDefault (layout, property, default ) \
7068({ \
7169 UICollectionViewFlowLayout *flowLayout = ASDynamicCast (layout, UICollectionViewFlowLayout); \
@@ -679,19 +677,13 @@ - (NSIndexPath *)convertIndexPathFromCollectionNode:(NSIndexPath *)indexPath wai
679677 if (indexPath == nil ) {
680678 return nil ;
681679 }
682-
683- // If this is a section index path, we don't currently have a method
684- // to do a mapping.
685- if (indexPath.item == NSNotFound ) {
686- return indexPath;
687- } else {
688- NSIndexPath *viewIndexPath = [_dataController.visibleMap convertIndexPath: indexPath fromMap: _dataController.pendingMap];
689- if (viewIndexPath == nil && wait) {
690- [self waitUntilAllUpdatesAreCommitted ];
691- return [self convertIndexPathFromCollectionNode: indexPath waitingIfNeeded: NO ];
692- }
693- return viewIndexPath;
680+
681+ NSIndexPath *viewIndexPath = [_dataController.visibleMap convertIndexPath: indexPath fromMap: _dataController.pendingMap];
682+ if (viewIndexPath == nil && wait) {
683+ [self waitUntilAllUpdatesAreCommitted ];
684+ return [self convertIndexPathFromCollectionNode: indexPath waitingIfNeeded: NO ];
694685 }
686+ return viewIndexPath;
695687}
696688
697689/* *
@@ -725,13 +717,7 @@ - (NSIndexPath *)convertIndexPathToCollectionNode:(NSIndexPath *)indexPath
725717 return nil ;
726718 }
727719
728- // If this is a section index path, we don't currently have a method
729- // to do a mapping.
730- if (indexPath.item == NSNotFound ) {
731- return indexPath;
732- } else {
733- return [_dataController.pendingMap convertIndexPath: indexPath fromMap: _dataController.visibleMap];
734- }
720+ return [_dataController.pendingMap convertIndexPath: indexPath fromMap: _dataController.visibleMap];
735721}
736722
737723- (NSArray <NSIndexPath *> *)convertIndexPathsToCollectionNode : (NSArray <NSIndexPath *> *)indexPaths
@@ -1050,7 +1036,7 @@ - (CGSize)collectionView:(UICollectionView *)cv layout:(UICollectionViewLayout *
10501036 ASDisplayNodeAssertMainThread ();
10511037 ASElementMap *map = _dataController.visibleMap ;
10521038 ASCollectionElement *e = [map supplementaryElementOfKind: UICollectionElementKindSectionHeader
1053- atIndexPath: ASIndexPathForSection ( section) ];
1039+ atIndexPath: [ NSIndexPath indexPathForItem: 0 inSection: section] ];
10541040 return e ? [self sizeForElement: e] : ASFlowLayoutDefault (l, headerReferenceSize, CGSizeZero);
10551041}
10561042
@@ -1060,51 +1046,50 @@ - (CGSize)collectionView:(UICollectionView *)cv layout:(UICollectionViewLayout *
10601046 ASDisplayNodeAssertMainThread ();
10611047 ASElementMap *map = _dataController.visibleMap ;
10621048 ASCollectionElement *e = [map supplementaryElementOfKind: UICollectionElementKindSectionFooter
1063- atIndexPath: ASIndexPathForSection ( section) ];
1049+ atIndexPath: [ NSIndexPath indexPathForItem: 0 inSection: section] ];
10641050 return e ? [self sizeForElement: e] : ASFlowLayoutDefault (l, footerReferenceSize, CGSizeZero);
10651051}
10661052
10671053// For the methods that call delegateIndexPathForSection:withSelector:, translate the section from
10681054// visibleMap to pendingMap. If the section no longer exists, or the delegate doesn't implement
1069- // the selector, we will return a nil indexPath (and then use the ASFlowLayoutDefault).
1070- - (NSIndexPath *) delegateIndexPathForSection : (NSInteger )section withSelector : (SEL )selector
1055+ // the selector, we will return NSNotFound (and then use the ASFlowLayoutDefault).
1056+ - (NSInteger ) delegateIndexForSection : (NSInteger )section withSelector : (SEL )selector
10711057{
10721058 if ([_asyncDelegate respondsToSelector: selector]) {
1073- return [_dataController.pendingMap convertIndexPath: ASIndexPathForSection (section)
1074- fromMap: _dataController.visibleMap];
1059+ return [_dataController.pendingMap convertSection: section fromMap: _dataController.visibleMap];
10751060 } else {
1076- return nil ;
1061+ return NSNotFound ;
10771062 }
10781063}
10791064
10801065- (UIEdgeInsets)collectionView : (UICollectionView *)cv layout : (UICollectionViewLayout *)l
10811066 insetForSectionAtIndex : (NSInteger )section
10821067{
1083- NSIndexPath *indexPath = [self delegateIndexPathForSection : section withSelector: _cmd ];
1084- if (indexPath ) {
1085- return [(id )_asyncDelegate collectionView: cv layout: l insetForSectionAtIndex: indexPath. section];
1068+ section = [self delegateIndexForSection : section withSelector: _cmd ];
1069+ if (section != NSNotFound ) {
1070+ return [(id )_asyncDelegate collectionView: cv layout: l insetForSectionAtIndex: section];
10861071 }
10871072 return ASFlowLayoutDefault (l, sectionInset, UIEdgeInsetsZero);
10881073}
10891074
10901075- (CGFloat)collectionView : (UICollectionView *)cv layout : (UICollectionViewLayout *)l
10911076 minimumInteritemSpacingForSectionAtIndex : (NSInteger )section
10921077{
1093- NSIndexPath *indexPath = [self delegateIndexPathForSection : section withSelector: _cmd ];
1094- if (indexPath ) {
1078+ section = [self delegateIndexForSection : section withSelector: _cmd ];
1079+ if (section != NSNotFound ) {
10951080 return [(id )_asyncDelegate collectionView: cv layout: l
1096- minimumInteritemSpacingForSectionAtIndex: indexPath. section];
1081+ minimumInteritemSpacingForSectionAtIndex: section];
10971082 }
10981083 return ASFlowLayoutDefault (l, minimumInteritemSpacing, 10.0 ); // Default is documented as 10.0
10991084}
11001085
11011086- (CGFloat)collectionView : (UICollectionView *)cv layout : (UICollectionViewLayout *)l
11021087 minimumLineSpacingForSectionAtIndex : (NSInteger )section
11031088{
1104- NSIndexPath *indexPath = [self delegateIndexPathForSection : section withSelector: _cmd ];
1105- if (indexPath ) {
1089+ section = [self delegateIndexForSection : section withSelector: _cmd ];
1090+ if (section != NSNotFound ) {
11061091 return [(id )_asyncDelegate collectionView: cv layout: l
1107- minimumLineSpacingForSectionAtIndex: indexPath. section];
1092+ minimumLineSpacingForSectionAtIndex: section];
11081093 }
11091094 return ASFlowLayoutDefault (l, minimumLineSpacing, 10.0 ); // Default is documented as 10.0
11101095}
0 commit comments