From 2b21cf6d1356e56114d67ff4410f4d3ad7fabdfe Mon Sep 17 00:00:00 2001 From: Scott Goodson Date: Fri, 13 Oct 2017 16:24:26 -0700 Subject: [PATCH 1/2] [ASCollectionView] Ensure -invalidateFlowLayoutDelegateMetrics is called for UIKit passthrough cells. This allows rotation to work properly when rotating UIKit passthrough cells that need to change width. --- Source/ASCollectionView.mm | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Source/ASCollectionView.mm b/Source/ASCollectionView.mm index 0c706faa4..e2e124efe 100644 --- a/Source/ASCollectionView.mm +++ b/Source/ASCollectionView.mm @@ -367,6 +367,7 @@ - (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UICol - (void)relayoutItems { + [self invalidateFlowLayoutDelegateMetrics]; [_dataController relayoutAllNodes]; } @@ -2246,18 +2247,17 @@ - (void)didMoveToWindow */ - (void)layer:(CALayer *)layer didChangeBoundsWithOldValue:(CGRect)oldBounds newValue:(CGRect)newBounds { - if (_hasDataControllerLayoutDelegate) { - // Let the layout delegate handle bounds changes if it's available. - return; - } - if (self.collectionViewLayout == nil) { + CGSize newSize = newBounds.size; + CGSize lastUsedSize = _lastBoundsSizeUsedForMeasuringNodes; + if (CGSizeEqualToSize(lastUsedSize, newSize)) { return; } - CGSize lastUsedSize = _lastBoundsSizeUsedForMeasuringNodes; - if (CGSizeEqualToSize(lastUsedSize, newBounds.size)) { + if (_hasDataControllerLayoutDelegate || self.collectionViewLayout == nil) { + // Let the layout delegate handle bounds changes if it's available. If no layout, it will init in the new state. return; } - _lastBoundsSizeUsedForMeasuringNodes = newBounds.size; + + _lastBoundsSizeUsedForMeasuringNodes = newSize; // Laying out all nodes is expensive. // We only need to do this if the bounds changed in the non-scrollable direction. @@ -2265,13 +2265,14 @@ - (void)layer:(CALayer *)layer didChangeBoundsWithOldValue:(CGRect)oldBounds new // appearance update, we do not need to relayout all nodes. // For a more permanent fix to the unsafety mentioned above, see https://github.com/facebook/AsyncDisplayKit/pull/2182 ASScrollDirection scrollDirection = self.scrollableDirections; - BOOL fixedVertically = (ASScrollDirectionContainsVerticalDirection(scrollDirection) == NO); + BOOL fixedVertically = (ASScrollDirectionContainsVerticalDirection (scrollDirection) == NO); BOOL fixedHorizontally = (ASScrollDirectionContainsHorizontalDirection(scrollDirection) == NO); - BOOL changedInNonScrollingDirection = (fixedHorizontally && newBounds.size.width != lastUsedSize.width) || (fixedVertically && newBounds.size.height != lastUsedSize.height); + BOOL changedInNonScrollingDirection = (fixedHorizontally && newSize.width != lastUsedSize.width) || + (fixedVertically && newSize.height != lastUsedSize.height); if (changedInNonScrollingDirection) { - [_dataController relayoutAllNodes]; + [self relayoutItems]; [_dataController waitUntilAllUpdatesAreProcessed]; // We need to ensure the size requery is done before we update our layout. [self.collectionViewLayout invalidateLayout]; From d35e57b34775a1eef8c76445c4b45b7d63e7834e Mon Sep 17 00:00:00 2001 From: Scott Goodson Date: Sat, 28 Oct 2017 23:36:10 -0700 Subject: [PATCH 2/2] [ASCollectionView] No need to verify node is still in model to handle view-only notifications. --- Source/ASCollectionView.mm | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Source/ASCollectionView.mm b/Source/ASCollectionView.mm index d85226a88..339728d83 100644 --- a/Source/ASCollectionView.mm +++ b/Source/ASCollectionView.mm @@ -1166,9 +1166,8 @@ - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICol { if (_asyncDelegateFlags.interopWillDisplayCell) { ASCellNode *node = [self nodeForItemAtIndexPath:indexPath]; - NSIndexPath *modelIndexPath = [self indexPathForNode:node]; - if (modelIndexPath && node.shouldUseUIKitCell) { - [(id )_asyncDelegate collectionView:collectionView willDisplayCell:rawCell forItemAtIndexPath:modelIndexPath]; + if (node.shouldUseUIKitCell) { + [(id )_asyncDelegate collectionView:collectionView willDisplayCell:rawCell forItemAtIndexPath:indexPath]; } } @@ -1227,9 +1226,8 @@ - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:( { if (_asyncDelegateFlags.interopDidEndDisplayingCell) { ASCellNode *node = [self nodeForItemAtIndexPath:indexPath]; - NSIndexPath *modelIndexPath = [self indexPathForNode:node]; - if (modelIndexPath && node.shouldUseUIKitCell) { - [(id )_asyncDelegate collectionView:collectionView didEndDisplayingCell:rawCell forItemAtIndexPath:modelIndexPath]; + if (node.shouldUseUIKitCell) { + [(id )_asyncDelegate collectionView:collectionView didEndDisplayingCell:rawCell forItemAtIndexPath:indexPath]; } } @@ -1272,10 +1270,9 @@ - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:( - (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(UICollectionReusableView *)rawView forElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath { if (_asyncDelegateFlags.interopWillDisplaySupplementaryView) { - ASCellNode *node = [self nodeForItemAtIndexPath:indexPath]; - NSIndexPath *modelIndexPath = [self indexPathForNode:node]; - if (modelIndexPath && node.shouldUseUIKitCell) { - [(id )_asyncDelegate collectionView:collectionView willDisplaySupplementaryView:rawView forElementKind:elementKind atIndexPath:modelIndexPath]; + ASCellNode *node = [self supplementaryNodeForElementKind:elementKind atIndexPath:indexPath]; + if (node.shouldUseUIKitCell) { + [(id )_asyncDelegate collectionView:collectionView willDisplaySupplementaryView:rawView forElementKind:elementKind atIndexPath:indexPath]; } } @@ -1313,10 +1310,9 @@ - (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementa - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingSupplementaryView:(UICollectionReusableView *)rawView forElementOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath { if (_asyncDelegateFlags.interopdidEndDisplayingSupplementaryView) { - ASCellNode *node = [self nodeForItemAtIndexPath:indexPath]; - NSIndexPath *modelIndexPath = [self indexPathForNode:node]; - if (modelIndexPath && node.shouldUseUIKitCell) { - [(id )_asyncDelegate collectionView:collectionView didEndDisplayingSupplementaryView:rawView forElementOfKind:elementKind atIndexPath:modelIndexPath]; + ASCellNode *node = [self supplementaryNodeForElementKind:elementKind atIndexPath:indexPath]; + if (node.shouldUseUIKitCell) { + [(id )_asyncDelegate collectionView:collectionView didEndDisplayingSupplementaryView:rawView forElementOfKind:elementKind atIndexPath:indexPath]; } }