From d4af736985eef11621c4dae605a42bce16aa9c4a Mon Sep 17 00:00:00 2001 From: appleguy Date: Sun, 2 Apr 2017 12:11:44 -0700 Subject: [PATCH] [ASCollectionView] Improve interop to silence invalid layout warnings, fix supplementary passthrough. (#3178) * [ASCollectionView] Improve interop to silence invalid layout warnings, fix supplementary passthrough. Before this change, passthrough of supplementary elements didn't work properly -- it would get rehosted into the blank ASCellNode. * [ASCollectionView] Ensure that IGListKit-handled supplementary views are sent through ASRangeController. * [ASCellNode] When .shouldUseUIKitCell == YES, don't remove the subviews of the .contentView --- Source/ASCollectionView.mm | 10 +++++----- Source/Details/ASRangeController.mm | 10 ++++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Source/ASCollectionView.mm b/Source/ASCollectionView.mm index f997359b7b..d8ab5c0a1c 100644 --- a/Source/ASCollectionView.mm +++ b/Source/ASCollectionView.mm @@ -924,7 +924,9 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier"; ASCellNode *cell = [self nodeForItemAtIndexPath:indexPath]; if (cell.shouldUseUIKitCell) { if ([_asyncDelegate respondsToSelector:@selector(collectionView:layout:sizeForItemAtIndexPath:)]) { - return [(id)_asyncDelegate collectionView:collectionView layout:collectionViewLayout sizeForItemAtIndexPath:indexPath]; + CGSize size = [(id)_asyncDelegate collectionView:collectionView layout:collectionViewLayout sizeForItemAtIndexPath:indexPath]; + cell.style.preferredSize = size; + return size; } } ASCollectionElement *e = [_dataController.visibleMap elementForItemAtIndexPath:indexPath]; @@ -972,13 +974,11 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier"; BOOL shouldDequeueExternally = _asyncDataSourceFlags.interopViewForSupplementaryElement && (_asyncDataSourceFlags.interopAlwaysDequeue || node.shouldUseUIKitCell); if (shouldDequeueExternally) { + // This codepath is used for both IGListKit mode, and app-level UICollectionView interop. view = [(id)_asyncDataSource collectionView:collectionView viewForSupplementaryElementOfKind:kind atIndexPath:indexPath]; } else { - view = [self dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:kReuseIdentifier forIndexPath:indexPath]; - } - - if (!node.shouldUseUIKitCell) { ASDisplayNodeAssert(node != nil, @"Supplementary node should exist. Kind = %@, indexPath = %@, collectionDataSource = %@", kind, indexPath, self); + view = [self dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:kReuseIdentifier forIndexPath:indexPath]; } if (node) { diff --git a/Source/Details/ASRangeController.mm b/Source/Details/ASRangeController.mm index 024c99384b..5bc4cfb191 100644 --- a/Source/Details/ASRangeController.mm +++ b/Source/Details/ASRangeController.mm @@ -12,7 +12,7 @@ #import #import -#import +#import #import #import #import // Required for interfaceState and hierarchyState setter methods. @@ -444,7 +444,13 @@ static UIApplicationState __ApplicationState = UIApplicationStateActive; ASDisplayNodeAssertMainThread(); ASDisplayNodeAssert(node, @"Cannot move a nil node to a view"); ASDisplayNodeAssert(contentView, @"Cannot move a node to a non-existent view"); - + + if (node.shouldUseUIKitCell) { + // When using UIKit cells, the ASCellNode is just a placeholder object with a preferredSize. + // In this case, we should not disrupt the subviews of the contentView. + return; + } + if (node.view.superview == contentView) { // this content view is already correctly configured return;