diff --git a/CHANGELOG.md b/CHANGELOG.md index 4565679196..26d7771852 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Remove re-entrant access to self.view when applying initial pending state. [Adlai Holler](https://github.com/Adlai-Holler) [#510](https://github.com/TextureGroup/Texture/pull/510) - Small improvements in ASCollectionLayout [Huy Nguyen](https://github.com/nguyenhuy) [#509](https://github.com/TextureGroup/Texture/pull/509) [#513](https://github.com/TextureGroup/Texture/pull/513) - Fix retain cycle between ASImageNode and PINAnimatedImage [Phil Larson](https://github.com/plarson) [#520](https://github.com/TextureGroup/Texture/pull/520) +- Table and collection views to consider content inset when calculating (default) element size range [Huy Nguyen](https://github.com/nguyenhuy) [#525](https://github.com/TextureGroup/Texture/pull/525) ##2.4 - Fix an issue where inserting/deleting sections could lead to inconsistent supplementary element behavior. [Adlai Holler](https://github.com/Adlai-Holler) diff --git a/Source/ASCollectionView.mm b/Source/ASCollectionView.mm index 83bcc2447b..f7ce6859da 100644 --- a/Source/ASCollectionView.mm +++ b/Source/ASCollectionView.mm @@ -1536,10 +1536,6 @@ minimumLineSpacingForSectionAtIndex:(NSInteger)section return [self.layoutInspector scrollableDirections]; } -- (ASScrollDirection)flowLayoutScrollableDirections:(UICollectionViewFlowLayout *)flowLayout { - return (flowLayout.scrollDirection == UICollectionViewScrollDirectionHorizontal) ? ASScrollDirectionHorizontalDirections : ASScrollDirectionVerticalDirections; -} - - (void)layoutSubviews { if (_cellsForLayoutUpdates.count > 0) { diff --git a/Source/ASPagerNode.h b/Source/ASPagerNode.h index f5c0164120..51e57898c6 100644 --- a/Source/ASPagerNode.h +++ b/Source/ASPagerNode.h @@ -75,6 +75,9 @@ NS_ASSUME_NONNULL_BEGIN @end +/** + * A horizontal, paging collection node. + */ @interface ASPagerNode : ASCollectionNode /** @@ -84,6 +87,8 @@ NS_ASSUME_NONNULL_BEGIN /** * Initializer with custom-configured flow layout properties. + * + * NOTE: The flow layout must have a horizontal scroll direction. */ - (instancetype)initWithCollectionViewLayout:(ASPagerFlowLayout *)flowLayout; diff --git a/Source/ASPagerNode.m b/Source/ASPagerNode.m index 02666993e8..86062f6649 100644 --- a/Source/ASPagerNode.m +++ b/Source/ASPagerNode.m @@ -66,6 +66,7 @@ - (instancetype)initWithCollectionViewLayout:(ASPagerFlowLayout *)flowLayout; { ASDisplayNodeAssert([flowLayout isKindOfClass:[ASPagerFlowLayout class]], @"ASPagerNode requires a flow layout."); + ASDisplayNodeAssertTrue(flowLayout.scrollDirection == UICollectionViewScrollDirectionHorizontal); self = [super initWithCollectionViewLayout:flowLayout]; return self; } @@ -112,7 +113,15 @@ - (NSInteger)currentPageIndex { - return (self.view.contentOffset.x / CGRectGetWidth(self.view.bounds)); + return (self.view.contentOffset.x / [self pageSize].width); +} + +- (CGSize)pageSize +{ + UIEdgeInsets contentInset = self.view.contentInset; + CGSize pageSize = self.bounds.size; + pageSize.height -= (contentInset.top + contentInset.bottom); + return pageSize; } #pragma mark - Helpers @@ -142,7 +151,7 @@ - (CGSize)sizeForElements:(ASElementMap *)elements { ASDisplayNodeAssertMainThread(); - return self.bounds.size; + return [self pageSize]; } #pragma mark - ASCollectionDataSource @@ -179,7 +188,7 @@ } #pragma clang diagnostic pop - return ASSizeRangeMake(self.bounds.size); + return ASSizeRangeMake([self pageSize]); } #pragma mark - Data Source Proxy diff --git a/Source/ASTableView.mm b/Source/ASTableView.mm index d0e529c8bb..38bfe6836f 100644 --- a/Source/ASTableView.mm +++ b/Source/ASTableView.mm @@ -751,7 +751,8 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; { // Remeasure all rows if our row width has changed. _remeasuringCellNodes = YES; - CGFloat constrainedWidth = self.bounds.size.width - [self sectionIndexWidth]; + UIEdgeInsets contentInset = self.contentInset; + CGFloat constrainedWidth = self.bounds.size.width - [self sectionIndexWidth] - contentInset.left - contentInset.right; if (constrainedWidth > 0 && _nodesConstrainedWidth != constrainedWidth) { _nodesConstrainedWidth = constrainedWidth; diff --git a/Source/Details/ASCollectionViewLayoutInspector.m b/Source/Details/ASCollectionViewLayoutInspector.m index b77f22172e..26100cec66 100644 --- a/Source/Details/ASCollectionViewLayoutInspector.m +++ b/Source/Details/ASCollectionViewLayoutInspector.m @@ -27,9 +27,12 @@ // of the collection view ASSizeRange NodeConstrainedSizeForScrollDirection(ASCollectionView *collectionView) { CGSize maxSize = collectionView.bounds.size; + UIEdgeInsets contentInset = collectionView.contentInset; if (ASScrollDirectionContainsHorizontalDirection(collectionView.scrollableDirections)) { maxSize.width = CGFLOAT_MAX; + maxSize.height -= (contentInset.top + contentInset.bottom); } else { + maxSize.width -= (contentInset.left + contentInset.right); maxSize.height = CGFLOAT_MAX; } return ASSizeRangeMake(CGSizeZero, maxSize);