Improve Our Handling of Flow Layout Headers/Footers (#2939)

* Rejigger our flow layout supplementary support to make more sense.

* Support old protocol

* Update

* Update deprecation message

* Undeprecate insetForSection method, because it actually _does_ still work

* Update the tests

* Remove irrelevant junk

* Remove cast, add pragma
This commit is contained in:
Adlai Holler
2017-01-27 15:58:43 -08:00
committed by GitHub
parent 7d68ce33bb
commit 295ed22c23
13 changed files with 156 additions and 108 deletions

View File

@@ -416,33 +416,71 @@ ASDISPLAYNODE_DEPRECATED_MSG("Renamed to ASCollectionDelegate.")
@end
/**
* Defines methods that let you coordinate with a `UICollectionViewFlowLayout` in combination with an `ASCollectionView`.
* Defines methods that let you coordinate a `UICollectionViewFlowLayout` in combination with an `ASCollectionNode`.
*/
@protocol ASCollectionViewDelegateFlowLayout <ASCollectionDelegate>
@protocol ASCollectionDelegateFlowLayout <ASCollectionDelegate>
@optional
/**
* @discussion This method is deprecated and does nothing from 1.9.7 and up
* Previously it applies the section inset to every cells within the corresponding section.
* The expected behavior is to apply the section inset to the whole section rather than
* shrinking each cell individually.
* If you want this behavior, you can integrate your insets calculation into
* `constrainedSizeForNodeAtIndexPath`
* please file a github issue if you would like this to be restored.
* Asks the delegate for the inset that should be applied to the given section.
*
* @see the same method in UICollectionViewDelegate.
*/
- (UIEdgeInsets)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section ASDISPLAYNODE_DEPRECATED_MSG("This method does nothing for 1.9.7+ due to incorrect implementation previously, see the header file for more information.");
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section;
/**
* Asks the delegate for the size range that should be used to measure the header in the given flow layout section.
*
* @param collectionNode The sender.
* @param section The section.
*
* @return The size range for the header, or @c ASSizeRangeZero if there is no header in this section.
*
* If you want the header to completely determine its own size, return @c ASSizeRangeUnconstrained.
*
* @note Only the scrollable dimension of the returned size range will be used. In a vertical flow,
* only the height will be used. In a horizontal flow, only the width will be used. The other dimension
* will be constrained to fill the collection node.
*
* @discussion If you do not implement this method, ASDK will fall back to calling @c collectionView:layout:referenceSizeForHeaderInSection:
* and using that as the exact constrained size. If you don't implement that method, ASDK will read the @c headerReferenceSize from the layout.
*/
- (ASSizeRange)collectionNode:(ASCollectionNode *)collectionNode sizeRangeForHeaderInSection:(NSInteger)section;
/**
* Asks the delegate for the size range that should be used to measure the footer in the given flow layout section.
*
* @param collectionNode The sender.
* @param section The section.
*
* @return The size range for the footer, or @c ASSizeRangeZero if there is no footer in this section.
*
* If you want the footer to completely determine its own size, return @c ASSizeRangeUnconstrained.
*
* @note Only the scrollable dimension of the returned size range will be used. In a vertical flow,
* only the height will be used. In a horizontal flow, only the width will be used. The other dimension
* will be constrained to fill the collection node.
*
* @discussion If you do not implement this method, ASDK will fall back to calling @c collectionView:layout:referenceSizeForFooterInSection:
* and using that as the exact constrained size. If you don't implement that method, ASDK will read the @c footerReferenceSize from the layout.
*/
- (ASSizeRange)collectionNode:(ASCollectionNode *)collectionNode sizeRangeForFooterInSection:(NSInteger)section;
/**
* Asks the delegate for the size of the header in the specified section.
*/
- (CGSize)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section;
- (CGSize)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section ASDISPLAYNODE_DEPRECATED_MSG("Implement collectionNode:sizeRangeForHeaderInSection: instead.");
/**
* Asks the delegate for the size of the footer in the specified section.
*/
- (CGSize)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section;
- (CGSize)collectionView:(ASCollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section ASDISPLAYNODE_DEPRECATED_MSG("Implement collectionNode:sizeRangeForFooterInSection: instead.");
@end
ASDISPLAYNODE_DEPRECATED_MSG("Renamed to ASCollectionDelegateFlowLayout.")
@protocol ASCollectionViewDelegateFlowLayout <ASCollectionDelegateFlowLayout>
@end
NS_ASSUME_NONNULL_END