From 46743ad12f1ed252248f2ffc74bd299c6b95fbe2 Mon Sep 17 00:00:00 2001 From: Scott Goodson Date: Sun, 9 Jul 2017 16:27:11 -0700 Subject: [PATCH] [ASCollectionView] Improve performance and behavior of rotation / bounds changes. See #430 for details. --- Source/ASCollectionView.mm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/ASCollectionView.mm b/Source/ASCollectionView.mm index 36cd29c93..d9a5dbf3c 100644 --- a/Source/ASCollectionView.mm +++ b/Source/ASCollectionView.mm @@ -2156,10 +2156,12 @@ - (void)layer:(CALayer *)layer didChangeBoundsWithOldValue:(CGRect)oldBounds new BOOL changedInNonScrollingDirection = (fixedHorizontally && newBounds.size.width != lastUsedSize.width) || (fixedVertically && newBounds.size.height != lastUsedSize.height); if (changedInNonScrollingDirection) { - [_dataController relayoutAllNodes]; - [_dataController waitUntilAllUpdatesAreCommitted]; - // We need to ensure the size requery is done before we update our layout. + // Because -invalidateLayout doesn't trigger any operations by itself, and we answer queries from UICollectionView using layoutThatFits:, + // we invalidate the layout before we have updated all of the cells. Any cells that the collection needs the size of immediately will get + // -layoutThatFits: with a new constraint, on the main thread, and synchronously calculate them. Meanwhile, relayoutAllNodes will update + // the layout of any remaining nodes on background threads (and fast-return for any nodes that the UICV got to first). [self.collectionViewLayout invalidateLayout]; + [_dataController relayoutAllNodes]; } }