Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Oct 31, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 22 additions & 27 deletions Source/ASCollectionView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ - (void)relayoutItems
{
[_dataController relayoutAllNodesWithInvalidationBlock:^{
[self.collectionViewLayout invalidateLayout];
[self invalidateFlowLayoutDelegateMetrics];
}];
}

Expand Down Expand Up @@ -1165,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 <ASCollectionDelegateInterop>)_asyncDelegate collectionView:collectionView willDisplayCell:rawCell forItemAtIndexPath:modelIndexPath];
if (node.shouldUseUIKitCell) {
[(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView:collectionView willDisplayCell:rawCell forItemAtIndexPath:indexPath];
}
}

Expand Down Expand Up @@ -1226,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 <ASCollectionDelegateInterop>)_asyncDelegate collectionView:collectionView didEndDisplayingCell:rawCell forItemAtIndexPath:modelIndexPath];
if (node.shouldUseUIKitCell) {
[(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView:collectionView didEndDisplayingCell:rawCell forItemAtIndexPath:indexPath];
}
}

Expand Down Expand Up @@ -1271,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 <ASCollectionDelegateInterop>)_asyncDelegate collectionView:collectionView willDisplaySupplementaryView:rawView forElementKind:elementKind atIndexPath:modelIndexPath];
ASCellNode *node = [self supplementaryNodeForElementKind:elementKind atIndexPath:indexPath];
if (node.shouldUseUIKitCell) {
[(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView:collectionView willDisplaySupplementaryView:rawView forElementKind:elementKind atIndexPath:indexPath];
}
}

Expand Down Expand Up @@ -1312,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 <ASCollectionDelegateInterop>)_asyncDelegate collectionView:collectionView didEndDisplayingSupplementaryView:rawView forElementOfKind:elementKind atIndexPath:modelIndexPath];
ASCellNode *node = [self supplementaryNodeForElementKind:elementKind atIndexPath:indexPath];
if (node.shouldUseUIKitCell) {
[(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView:collectionView didEndDisplayingSupplementaryView:rawView forElementOfKind:elementKind atIndexPath:indexPath];
}
}

Expand Down Expand Up @@ -2253,34 +2250,32 @@ - (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.
// If, for example, a vertical flow layout has its height changed due to a status bar
// 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delightful!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-D thanks for sharing your aesthetic approval, always good to see & re-align as a team


if (changedInNonScrollingDirection) {
[_dataController relayoutAllNodesWithInvalidationBlock:^{
[self.collectionViewLayout invalidateLayout];
}];
[self relayoutItems];
}
}

Expand Down