diff --git a/AsyncDisplayKit/ASCollectionView.h b/AsyncDisplayKit/ASCollectionView.h index 72a6d73faa..f0f0eabd4f 100644 --- a/AsyncDisplayKit/ASCollectionView.h +++ b/AsyncDisplayKit/ASCollectionView.h @@ -125,6 +125,9 @@ NS_ASSUME_NONNULL_BEGIN @interface ASCollectionView (Deprecated) +@property (nonatomic, weak) id delegate ASDISPLAYNODE_DEPRECATED_MSG("Use ASCollectionNode.delegate instead. If you REALLY want to use this, cast to a UICollectionView but don't rely on the return value."); +@property (nonatomic, weak) id dataSource ASDISPLAYNODE_DEPRECATED_MSG("Use ASCollectionNode.dataSource instead. If you REALLY want to use this, cast to a UICollectionView but don't rely on the return value."); + /** * The object that acts as the asynchronous delegate of the collection view * diff --git a/AsyncDisplayKit/ASCollectionView.mm b/AsyncDisplayKit/ASCollectionView.mm index 2103d7b3f0..481e73a769 100644 --- a/AsyncDisplayKit/ASCollectionView.mm +++ b/AsyncDisplayKit/ASCollectionView.mm @@ -367,8 +367,10 @@ static NSString * const kReuseIdentifier = @"_ASCollectionReuseIdentifier"; - (void)setDelegate:(id)delegate { - // Our UIScrollView superclass sets its delegate to nil on dealloc. Only assert if we get a non-nil value here. We also allow this when we're doing interop. - ASDisplayNodeAssert(_asyncDelegateFlags.interop || delegate == nil, @"ASCollectionView uses asyncDelegate, not UICollectionView's delegate property."); + // The compiler will prevent users from calling this, + // but we will automatically route to @c asyncDelegate + // to support interop with frameworks like TLYShyNavBar. + self.asyncDelegate = (id)delegate; } - (void)proxyTargetHasDeallocated:(ASDelegateProxy *)proxy diff --git a/AsyncDisplayKit/ASTableView.h b/AsyncDisplayKit/ASTableView.h index 5d46f3c9a8..c544f121de 100644 --- a/AsyncDisplayKit/ASTableView.h +++ b/AsyncDisplayKit/ASTableView.h @@ -69,6 +69,9 @@ NS_ASSUME_NONNULL_BEGIN @interface ASTableView (Deprecated) +@property (nonatomic, weak) id delegate ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode.delegate instead. If you REALLY want to use this, cast to UITableView but don't rely on the return value."); +@property (nonatomic, weak) id dataSource ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode.dataSource instead. If you REALLY want to use this, cast to UITableView but don't rely on the return value."); + @property (nonatomic, weak) id asyncDelegate ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode's .delegate property instead."); @property (nonatomic, weak) id asyncDataSource ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode .dataSource property instead."); diff --git a/AsyncDisplayKit/ASTableView.mm b/AsyncDisplayKit/ASTableView.mm index 38ff2e91ed..3735539658 100644 --- a/AsyncDisplayKit/ASTableView.mm +++ b/AsyncDisplayKit/ASTableView.mm @@ -337,8 +337,10 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; - (void)setDelegate:(id)delegate { - // Our UIScrollView superclass sets its delegate to nil on dealloc. Only assert if we get a non-nil value here. - ASDisplayNodeAssert(delegate == nil, @"ASTableView uses asyncDelegate, not UITableView's delegate property."); + // The compiler will prevent users from calling this, + // but we will automatically route to @c asyncDelegate + // to support interop with frameworks like TLYShyNavBar. + self.asyncDelegate = (id)delegate; } - (id)asyncDataSource @@ -355,7 +357,7 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell"; // the (common) case of nilling the asyncDataSource in the ViewController's dealloc. In this case our _asyncDataSource // will return as nil (ARC magic) even though the _proxyDataSource still exists. It's really important to hold a strong // reference to the old dataSource in this case because calls to ASTableViewProxy will start failing and cause crashes. - NS_VALID_UNTIL_END_OF_SCOPE id oldDataSource = self.dataSource; + NS_VALID_UNTIL_END_OF_SCOPE id oldDataSource = super.dataSource; if (asyncDataSource == nil) { _asyncDataSource = nil; diff --git a/examples/CustomCollectionView-Swift/Sample/MosaicCollectionViewLayout.swift b/examples/CustomCollectionView-Swift/Sample/MosaicCollectionViewLayout.swift index a8770d5282..ae7db32b2f 100644 --- a/examples/CustomCollectionView-Swift/Sample/MosaicCollectionViewLayout.swift +++ b/examples/CustomCollectionView-Swift/Sample/MosaicCollectionViewLayout.swift @@ -228,17 +228,6 @@ class MosaicCollectionViewLayoutInspector: NSObject, ASCollectionViewLayoutInspe return ASSizeRange.init(min: CGSize.zero, max: layout._headerSizeForSection(section: atIndexPath.section)) } - /** - * Asks the inspector for the number of supplementary sections in the collection view for the given kind. - */ - func collectionView(_ collectionView: ASCollectionView, numberOfSectionsForSupplementaryNodeOfKind kind: String) -> UInt { - if (kind == UICollectionElementKindSectionHeader) { - return UInt((collectionView.dataSource?.numberOfSections!(in: collectionView))!) - } else { - return 0 - } - } - /** * Asks the inspector for the number of supplementary views for the given kind in the specified section. */ @@ -251,6 +240,6 @@ class MosaicCollectionViewLayoutInspector: NSObject, ASCollectionViewLayoutInspe } func scrollableDirections() -> ASScrollDirection { - return ASScrollDirectionVerticalDirections; + return ASScrollDirectionVerticalDirections } }