Skip to content

Commit

Permalink
[ASCollectionView] Call -invalidateFlowLayoutDelegateMetrics when rot…
Browse files Browse the repository at this point in the history
…ating. #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.
  • Loading branch information
appleguy authored and nguyenhuy committed Oct 31, 2017
1 parent af99ff5 commit 63efdbd
Showing 1 changed file with 22 additions and 27 deletions.
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);

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

Expand Down

0 comments on commit 63efdbd

Please sign in to comment.