1010
1111#import < vector>
1212
13+ #if !__has_include(<IGListDiffKit/IGListDiffKit.h>)
1314#import " IGListAssert.h"
15+ #else
16+ #import < IGListDiffKit/IGListAssert.h>
17+ #endif
1418#import " IGListCollectionViewDelegateLayout.h"
1519
1620#import " UIScrollView+IGListKit.h"
@@ -500,32 +504,32 @@ - (void)_calculateLayoutIfNeeded {
500504 const UIEdgeInsets insets = [delegate collectionView: collectionView layout: self insetForSectionAtIndex: section];
501505 const CGFloat lineSpacing = [delegate collectionView: collectionView layout: self minimumLineSpacingForSectionAtIndex: section];
502506 const CGFloat interitemSpacing = [delegate collectionView: collectionView layout: self minimumInteritemSpacingForSectionAtIndex: section];
503-
507+
504508 const CGSize paddedCollectionViewSize = UIEdgeInsetsInsetRect (contentInsetAdjustedCollectionViewBounds, insets).size ;
505509 const UICollectionViewScrollDirection fixedDirection = self.scrollDirection == UICollectionViewScrollDirectionHorizontal ? UICollectionViewScrollDirectionVertical : UICollectionViewScrollDirectionHorizontal;
506510 const CGFloat paddedLengthInFixedDirection = CGSizeGetLengthInDirection (paddedCollectionViewSize, fixedDirection);
507511 const CGFloat headerLengthInScrollDirection = hideHeaderWhenItemsEmpty ? 0 : CGSizeGetLengthInDirection (headerSize, self.scrollDirection );
508512 const CGFloat footerLengthInScrollDirection = hideHeaderWhenItemsEmpty ? 0 : CGSizeGetLengthInDirection (footerSize, self.scrollDirection );
509513 const BOOL headerExists = headerLengthInScrollDirection > 0 ;
510514 const BOOL footerExists = footerLengthInScrollDirection > 0 ;
511-
515+
512516 // start the section accounting for the header size
513517 // header length in scroll direction is subtracted from the sectionBounds when calculating the header bounds after items are done
514518 // this bumps the first row of items over enough to make room for the header
515519 itemCoordInScrollDirection += headerLengthInScrollDirection;
516520 nextRowCoordInScrollDirection += headerLengthInScrollDirection;
517-
521+
518522 // add the leading inset in fixed direction in case the section falls on the same row as the previous
519523 // if the section is newlined then the coord in fixed direction is reset
520524 itemCoordInFixedDirection += UIEdgeInsetsLeadingInsetInDirection (insets, fixedDirection);
521-
525+
522526 // the farthest in the fixed direction the frame of an item in this section can go
523527 const CGFloat maxCoordinateInFixedDirection = CGRectGetLengthInDirection (contentInsetAdjustedCollectionViewBounds, fixedDirection) - UIEdgeInsetsTrailingInsetInDirection (insets, fixedDirection);
524-
528+
525529 for (NSInteger item = 0 ; item < itemCount; item++) {
526530 NSIndexPath *indexPath = [NSIndexPath indexPathForItem: item inSection: section];
527531 const CGSize size = [delegate collectionView: collectionView layout: self sizeForItemAtIndexPath: indexPath];
528-
532+
529533 IGAssert (CGSizeGetLengthInDirection (size, fixedDirection) <= paddedLengthInFixedDirection
530534 || fabs (CGSizeGetLengthInDirection (size, fixedDirection) - paddedLengthInFixedDirection) < FLT_EPSILON,
531535 @" %@ of item %li in section %li (%.0f pt) must be less than or equal to container (%.0f pt) accounting for section insets %@ " ,
@@ -535,9 +539,9 @@ - (void)_calculateLayoutIfNeeded {
535539 CGSizeGetLengthInDirection (size, fixedDirection),
536540 CGRectGetLengthInDirection (contentInsetAdjustedCollectionViewBounds, fixedDirection),
537541 NSStringFromUIEdgeInsets (insets));
538-
542+
539543 CGFloat itemLengthInFixedDirection = MIN (CGSizeGetLengthInDirection (size, fixedDirection), paddedLengthInFixedDirection);
540-
544+
541545 // if the origin and length in fixed direction of the item busts the size of the container
542546 // or if this is the first item and the header has a non-zero size
543547 // newline to the next row and reset
@@ -547,19 +551,19 @@ - (void)_calculateLayoutIfNeeded {
547551 || (item == 0 && headerExists)) {
548552 itemCoordInScrollDirection = nextRowCoordInScrollDirection;
549553 itemCoordInFixedDirection = UIEdgeInsetsLeadingInsetInDirection (insets, fixedDirection);
550-
551-
554+
555+
552556 // if newlining, always append line spacing unless its the very first item of the section
553557 if (item > 0 ) {
554558 itemCoordInScrollDirection += lineSpacing;
555559 }
556560 }
557-
561+
558562 const CGFloat distanceToEdge = paddedLengthInFixedDirection - (itemCoordInFixedDirection + itemLengthInFixedDirection);
559563 if (self.stretchToEdge && distanceToEdge > 0 && distanceToEdge <= epsilon) {
560564 itemLengthInFixedDirection = paddedLengthInFixedDirection - itemCoordInFixedDirection;
561565 }
562-
566+
563567 const CGRect rawFrame = (self.scrollDirection == UICollectionViewScrollDirectionVertical) ?
564568 CGRectMake (itemCoordInFixedDirection,
565569 itemCoordInScrollDirection + insets.top ,
@@ -570,23 +574,23 @@ - (void)_calculateLayoutIfNeeded {
570574 size.width ,
571575 itemLengthInFixedDirection);
572576 const CGRect frame = IGListRectIntegralScaled (rawFrame);
573-
577+
574578 _sectionData[section].itemBounds [item] = frame;
575-
579+
576580 // track the max size of the row to find the coord of the next row, adjust for leading inset while iterating items
577581 nextRowCoordInScrollDirection = MAX (CGRectGetMaxInDirection (frame, self.scrollDirection ) - UIEdgeInsetsLeadingInsetInDirection (insets, self.scrollDirection ), nextRowCoordInScrollDirection);
578-
582+
579583 // increase the rolling coord in fixed direction appropriately and add item spacing for all items on the same row
580584 itemCoordInFixedDirection += itemLengthInFixedDirection + interitemSpacing;
581-
585+
582586 // union the rolling section bounds
583587 if (item == 0 ) {
584588 rollingSectionBounds = frame;
585589 } else {
586590 rollingSectionBounds = CGRectUnion (rollingSectionBounds, frame);
587591 }
588592 }
589-
593+
590594 const CGRect headerBounds = self.scrollDirection == UICollectionViewScrollDirectionVertical ?
591595 CGRectMake (insets.left ,
592596 itemsEmpty ? CGRectGetMaxY (rollingSectionBounds) : CGRectGetMinY (rollingSectionBounds) - headerSize.height ,
@@ -596,13 +600,13 @@ - (void)_calculateLayoutIfNeeded {
596600 insets.top ,
597601 hideHeaderWhenItemsEmpty ? 0 : headerSize.width ,
598602 paddedLengthInFixedDirection);
599-
603+
600604 _sectionData[section].headerBounds = headerBounds;
601-
605+
602606 if (itemsEmpty) {
603607 rollingSectionBounds = headerBounds;
604608 }
605-
609+
606610 const CGRect footerBounds = (self.scrollDirection == UICollectionViewScrollDirectionVertical) ?
607611 CGRectMake (insets.left ,
608612 CGRectGetMaxY (rollingSectionBounds),
@@ -612,9 +616,9 @@ - (void)_calculateLayoutIfNeeded {
612616 insets.top ,
613617 hideHeaderWhenItemsEmpty ? 0 : footerSize.width ,
614618 paddedLengthInFixedDirection);
615-
619+
616620 _sectionData[section].footerBounds = footerBounds;
617-
621+
618622 // union the header before setting the bounds of the section
619623 // only do this when the header has a size, otherwise the union stretches to box empty space
620624 if (headerExists) {
@@ -623,28 +627,28 @@ - (void)_calculateLayoutIfNeeded {
623627 if (footerExists) {
624628 rollingSectionBounds = CGRectUnion (rollingSectionBounds, footerBounds);
625629 }
626-
630+
627631 _sectionData[section].bounds = rollingSectionBounds;
628632 _sectionData[section].insets = insets;
629-
633+
630634 // bump the coord for the next section with the right insets
631635 itemCoordInFixedDirection += UIEdgeInsetsTrailingInsetInDirection (insets, fixedDirection);
632-
636+
633637 // find the farthest point in the section and add the trailing inset to find the next row's coord
634638 nextRowCoordInScrollDirection = MAX (nextRowCoordInScrollDirection, CGRectGetMaxInDirection (rollingSectionBounds, self.scrollDirection ) + UIEdgeInsetsTrailingInsetInDirection (insets, self.scrollDirection ));
635-
639+
636640 // keep track of coordinates for partial invalidation
637641 _sectionData[section].lastItemCoordInScrollDirection = itemCoordInScrollDirection;
638642 _sectionData[section].lastItemCoordInFixedDirection = itemCoordInFixedDirection;
639643 _sectionData[section].lastNextRowCoordInScrollDirection = nextRowCoordInScrollDirection;
640644 }
641-
645+
642646 _minimumInvalidatedSection = NSNotFound ;
643647}
644648
645649- (NSRange )_rangeOfSectionsInRect : (CGRect)rect {
646650 NSRange result = NSMakeRange (NSNotFound , 0 );
647-
651+
648652 const NSInteger sectionCount = _sectionData.size ();
649653 for (NSInteger section = 0 ; section < sectionCount; section++) {
650654 IGListSectionEntry entry = _sectionData[section];
@@ -657,7 +661,7 @@ - (NSRange)_rangeOfSectionsInRect:(CGRect)rect {
657661 }
658662 }
659663 }
660-
664+
661665 return result;
662666}
663667
0 commit comments