@@ -369,6 +369,7 @@ - (void)relayoutItems
369369{
370370 [_dataController relayoutAllNodesWithInvalidationBlock: ^{
371371 [self .collectionViewLayout invalidateLayout ];
372+ [self invalidateFlowLayoutDelegateMetrics ];
372373 }];
373374}
374375
@@ -1165,9 +1166,8 @@ - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICol
11651166{
11661167 if (_asyncDelegateFlags.interopWillDisplayCell ) {
11671168 ASCellNode *node = [self nodeForItemAtIndexPath: indexPath];
1168- NSIndexPath *modelIndexPath = [self indexPathForNode: node];
1169- if (modelIndexPath && node.shouldUseUIKitCell ) {
1170- [(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView: collectionView willDisplayCell: rawCell forItemAtIndexPath: modelIndexPath];
1169+ if (node.shouldUseUIKitCell ) {
1170+ [(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView: collectionView willDisplayCell: rawCell forItemAtIndexPath: indexPath];
11711171 }
11721172 }
11731173
@@ -1226,9 +1226,8 @@ - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(
12261226{
12271227 if (_asyncDelegateFlags.interopDidEndDisplayingCell ) {
12281228 ASCellNode *node = [self nodeForItemAtIndexPath: indexPath];
1229- NSIndexPath *modelIndexPath = [self indexPathForNode: node];
1230- if (modelIndexPath && node.shouldUseUIKitCell ) {
1231- [(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView: collectionView didEndDisplayingCell: rawCell forItemAtIndexPath: modelIndexPath];
1229+ if (node.shouldUseUIKitCell ) {
1230+ [(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView: collectionView didEndDisplayingCell: rawCell forItemAtIndexPath: indexPath];
12321231 }
12331232 }
12341233
@@ -1271,10 +1270,9 @@ - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(
12711270- (void )collectionView : (UICollectionView *)collectionView willDisplaySupplementaryView : (UICollectionReusableView *)rawView forElementKind : (NSString *)elementKind atIndexPath : (NSIndexPath *)indexPath
12721271{
12731272 if (_asyncDelegateFlags.interopWillDisplaySupplementaryView ) {
1274- ASCellNode *node = [self nodeForItemAtIndexPath: indexPath];
1275- NSIndexPath *modelIndexPath = [self indexPathForNode: node];
1276- if (modelIndexPath && node.shouldUseUIKitCell ) {
1277- [(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView: collectionView willDisplaySupplementaryView: rawView forElementKind: elementKind atIndexPath: modelIndexPath];
1273+ ASCellNode *node = [self supplementaryNodeForElementKind: elementKind atIndexPath: indexPath];
1274+ if (node.shouldUseUIKitCell ) {
1275+ [(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView: collectionView willDisplaySupplementaryView: rawView forElementKind: elementKind atIndexPath: indexPath];
12781276 }
12791277 }
12801278
@@ -1312,10 +1310,9 @@ - (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementa
13121310- (void )collectionView : (UICollectionView *)collectionView didEndDisplayingSupplementaryView : (UICollectionReusableView *)rawView forElementOfKind : (NSString *)elementKind atIndexPath : (NSIndexPath *)indexPath
13131311{
13141312 if (_asyncDelegateFlags.interopdidEndDisplayingSupplementaryView ) {
1315- ASCellNode *node = [self nodeForItemAtIndexPath: indexPath];
1316- NSIndexPath *modelIndexPath = [self indexPathForNode: node];
1317- if (modelIndexPath && node.shouldUseUIKitCell ) {
1318- [(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView: collectionView didEndDisplayingSupplementaryView: rawView forElementOfKind: elementKind atIndexPath: modelIndexPath];
1313+ ASCellNode *node = [self supplementaryNodeForElementKind: elementKind atIndexPath: indexPath];
1314+ if (node.shouldUseUIKitCell ) {
1315+ [(id <ASCollectionDelegateInterop>)_asyncDelegate collectionView: collectionView didEndDisplayingSupplementaryView: rawView forElementOfKind: elementKind atIndexPath: indexPath];
13191316 }
13201317 }
13211318
@@ -2253,34 +2250,32 @@ - (void)didMoveToWindow
22532250 */
22542251- (void )layer : (CALayer *)layer didChangeBoundsWithOldValue : (CGRect)oldBounds newValue : (CGRect)newBounds
22552252{
2256- if (_hasDataControllerLayoutDelegate) {
2257- // Let the layout delegate handle bounds changes if it's available.
2258- return ;
2259- }
2260- if (self.collectionViewLayout == nil ) {
2253+ CGSize newSize = newBounds.size ;
2254+ CGSize lastUsedSize = _lastBoundsSizeUsedForMeasuringNodes;
2255+ if (CGSizeEqualToSize (lastUsedSize, newSize)) {
22612256 return ;
22622257 }
2263- CGSize lastUsedSize = _lastBoundsSizeUsedForMeasuringNodes;
2264- if ( CGSizeEqualToSize (lastUsedSize, newBounds. size )) {
2258+ if (_hasDataControllerLayoutDelegate || self. collectionViewLayout == nil ) {
2259+ // Let the layout delegate handle bounds changes if it's available. If no layout, it will init in the new state.
22652260 return ;
22662261 }
2267- _lastBoundsSizeUsedForMeasuringNodes = newBounds.size ;
2262+
2263+ _lastBoundsSizeUsedForMeasuringNodes = newSize;
22682264
22692265 // Laying out all nodes is expensive.
22702266 // We only need to do this if the bounds changed in the non-scrollable direction.
22712267 // If, for example, a vertical flow layout has its height changed due to a status bar
22722268 // appearance update, we do not need to relayout all nodes.
22732269 // For a more permanent fix to the unsafety mentioned above, see https://github.com/facebook/AsyncDisplayKit/pull/2182
22742270 ASScrollDirection scrollDirection = self.scrollableDirections ;
2275- BOOL fixedVertically = (ASScrollDirectionContainsVerticalDirection (scrollDirection) == NO );
2271+ BOOL fixedVertically = (ASScrollDirectionContainsVerticalDirection (scrollDirection) == NO );
22762272 BOOL fixedHorizontally = (ASScrollDirectionContainsHorizontalDirection (scrollDirection) == NO );
22772273
2278- BOOL changedInNonScrollingDirection = (fixedHorizontally && newBounds.size .width != lastUsedSize.width ) || (fixedVertically && newBounds.size .height != lastUsedSize.height );
2274+ BOOL changedInNonScrollingDirection = (fixedHorizontally && newSize.width != lastUsedSize.width ) ||
2275+ (fixedVertically && newSize.height != lastUsedSize.height );
22792276
22802277 if (changedInNonScrollingDirection) {
2281- [_dataController relayoutAllNodesWithInvalidationBlock: ^{
2282- [self .collectionViewLayout invalidateLayout ];
2283- }];
2278+ [self relayoutItems ];
22842279 }
22852280}
22862281
0 commit comments