[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
This commit is contained in:
appleguy
2017-04-02 12:11:44 -07:00
committed by GitHub
parent 6abccf5841
commit d4af736985
2 changed files with 13 additions and 7 deletions

View File

@@ -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<ASCollectionDataSourceInterop>)_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) {

View File

@@ -12,7 +12,7 @@
#import <AsyncDisplayKit/_ASHierarchyChangeSet.h>
#import <AsyncDisplayKit/ASAssert.h>
#import <AsyncDisplayKit/ASCellNode.h>
#import <AsyncDisplayKit/ASCellNode+Internal.h>
#import <AsyncDisplayKit/ASCollectionElement.h>
#import <AsyncDisplayKit/ASDisplayNodeExtras.h>
#import <AsyncDisplayKit/ASDisplayNodeInternal.h> // 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;