[ASCollectionView] Call -invalidateFlowLayoutDelegateMetrics when rotating. #trivial (#616)

* [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.

* [ASCollectionView] No need to verify node is still in model to handle view-only notifications.
This commit is contained in:
appleguy
2017-10-31 06:20:58 -07:00
committed by Huy Nguyen
parent af99ff5ef2
commit 63efdbde8f

View File

@@ -369,6 +369,7 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
{ {
[_dataController relayoutAllNodesWithInvalidationBlock:^{ [_dataController relayoutAllNodesWithInvalidationBlock:^{
[self.collectionViewLayout invalidateLayout]; [self.collectionViewLayout invalidateLayout];
[self invalidateFlowLayoutDelegateMetrics];
}]; }];
} }
@@ -1165,9 +1166,8 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
{ {
if (_asyncDelegateFlags.interopWillDisplayCell) { if (_asyncDelegateFlags.interopWillDisplayCell) {
ASCellNode *node = [self nodeForItemAtIndexPath:indexPath]; ASCellNode *node = [self nodeForItemAtIndexPath:indexPath];
NSIndexPath *modelIndexPath = [self indexPathForNode:node]; if (node.shouldUseUIKitCell) {
if (modelIndexPath && node.shouldUseUIKitCell) { [(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView:collectionView willDisplayCell:rawCell forItemAtIndexPath:indexPath];
[(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView:collectionView willDisplayCell:rawCell forItemAtIndexPath:modelIndexPath];
} }
} }
@@ -1226,9 +1226,8 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
{ {
if (_asyncDelegateFlags.interopDidEndDisplayingCell) { if (_asyncDelegateFlags.interopDidEndDisplayingCell) {
ASCellNode *node = [self nodeForItemAtIndexPath:indexPath]; ASCellNode *node = [self nodeForItemAtIndexPath:indexPath];
NSIndexPath *modelIndexPath = [self indexPathForNode:node]; if (node.shouldUseUIKitCell) {
if (modelIndexPath && node.shouldUseUIKitCell) { [(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView:collectionView didEndDisplayingCell:rawCell forItemAtIndexPath:indexPath];
[(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView:collectionView didEndDisplayingCell:rawCell forItemAtIndexPath:modelIndexPath];
} }
} }
@@ -1271,10 +1270,9 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
- (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(UICollectionReusableView *)rawView forElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath - (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(UICollectionReusableView *)rawView forElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath
{ {
if (_asyncDelegateFlags.interopWillDisplaySupplementaryView) { if (_asyncDelegateFlags.interopWillDisplaySupplementaryView) {
ASCellNode *node = [self nodeForItemAtIndexPath:indexPath]; ASCellNode *node = [self supplementaryNodeForElementKind:elementKind atIndexPath:indexPath];
NSIndexPath *modelIndexPath = [self indexPathForNode:node]; if (node.shouldUseUIKitCell) {
if (modelIndexPath && node.shouldUseUIKitCell) { [(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView:collectionView willDisplaySupplementaryView:rawView forElementKind:elementKind atIndexPath:indexPath];
[(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView:collectionView willDisplaySupplementaryView:rawView forElementKind:elementKind atIndexPath:modelIndexPath];
} }
} }
@@ -1312,10 +1310,9 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingSupplementaryView:(UICollectionReusableView *)rawView forElementOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingSupplementaryView:(UICollectionReusableView *)rawView forElementOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath
{ {
if (_asyncDelegateFlags.interopdidEndDisplayingSupplementaryView) { if (_asyncDelegateFlags.interopdidEndDisplayingSupplementaryView) {
ASCellNode *node = [self nodeForItemAtIndexPath:indexPath]; ASCellNode *node = [self supplementaryNodeForElementKind:elementKind atIndexPath:indexPath];
NSIndexPath *modelIndexPath = [self indexPathForNode:node]; if (node.shouldUseUIKitCell) {
if (modelIndexPath && node.shouldUseUIKitCell) { [(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView:collectionView didEndDisplayingSupplementaryView:rawView forElementOfKind:elementKind atIndexPath:indexPath];
[(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView:collectionView didEndDisplayingSupplementaryView:rawView forElementOfKind:elementKind atIndexPath:modelIndexPath];
} }
} }
@@ -2253,18 +2250,17 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
*/ */
- (void)layer:(CALayer *)layer didChangeBoundsWithOldValue:(CGRect)oldBounds newValue:(CGRect)newBounds - (void)layer:(CALayer *)layer didChangeBoundsWithOldValue:(CGRect)oldBounds newValue:(CGRect)newBounds
{ {
if (_hasDataControllerLayoutDelegate) { CGSize newSize = newBounds.size;
// Let the layout delegate handle bounds changes if it's available.
return;
}
if (self.collectionViewLayout == nil) {
return;
}
CGSize lastUsedSize = _lastBoundsSizeUsedForMeasuringNodes; CGSize lastUsedSize = _lastBoundsSizeUsedForMeasuringNodes;
if (CGSizeEqualToSize(lastUsedSize, newBounds.size)) { if (CGSizeEqualToSize(lastUsedSize, newSize)) {
return; return;
} }
_lastBoundsSizeUsedForMeasuringNodes = 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 = newSize;
// Laying out all nodes is expensive. // Laying out all nodes is expensive.
// We only need to do this if the bounds changed in the non-scrollable direction. // We only need to do this if the bounds changed in the non-scrollable direction.
@@ -2272,15 +2268,14 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier";
// appearance update, we do not need to relayout all nodes. // 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 // For a more permanent fix to the unsafety mentioned above, see https://github.com/facebook/AsyncDisplayKit/pull/2182
ASScrollDirection scrollDirection = self.scrollableDirections; ASScrollDirection scrollDirection = self.scrollableDirections;
BOOL fixedVertically = (ASScrollDirectionContainsVerticalDirection(scrollDirection) == NO); BOOL fixedVertically = (ASScrollDirectionContainsVerticalDirection (scrollDirection) == NO);
BOOL fixedHorizontally = (ASScrollDirectionContainsHorizontalDirection(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) { if (changedInNonScrollingDirection) {
[_dataController relayoutAllNodesWithInvalidationBlock:^{ [self relayoutItems];
[self.collectionViewLayout invalidateLayout];
}];
} }
} }