Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 5c8818d

Browse files
author
Adlai Holler
authored
Route setDelegate: to setAsyncDelegate: (#3007)
* Make ASTableView/ASCollectionView delegate/dataSource unavailable, route setDelegate: to setAsyncDelegate: * Remove deprecated method from example * Drop down from unavailable to deprecated
1 parent e338098 commit 5c8818d

5 files changed

Lines changed: 16 additions & 17 deletions

File tree

AsyncDisplayKit/ASCollectionView.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ NS_ASSUME_NONNULL_BEGIN
125125

126126
@interface ASCollectionView (Deprecated)
127127

128+
@property (nonatomic, weak) id<UICollectionViewDelegate> 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.");
129+
@property (nonatomic, weak) id<UICollectionViewDataSource> 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.");
130+
128131
/**
129132
* The object that acts as the asynchronous delegate of the collection view
130133
*

AsyncDisplayKit/ASCollectionView.mm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,10 @@ - (void)setDataSource:(id<UICollectionViewDataSource>)dataSource
367367

368368
- (void)setDelegate:(id<UICollectionViewDelegate>)delegate
369369
{
370-
// 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.
371-
ASDisplayNodeAssert(_asyncDelegateFlags.interop || delegate == nil, @"ASCollectionView uses asyncDelegate, not UICollectionView's delegate property.");
370+
// The compiler will prevent users from calling this,
371+
// but we will automatically route to @c asyncDelegate
372+
// to support interop with frameworks like TLYShyNavBar.
373+
self.asyncDelegate = (id<ASCollectionDelegate>)delegate;
372374
}
373375

374376
- (void)proxyTargetHasDeallocated:(ASDelegateProxy *)proxy

AsyncDisplayKit/ASTableView.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ NS_ASSUME_NONNULL_BEGIN
6969

7070
@interface ASTableView (Deprecated)
7171

72+
@property (nonatomic, weak) id<UITableViewDelegate> 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.");
73+
@property (nonatomic, weak) id<UITableViewDataSource> 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.");
74+
7275
@property (nonatomic, weak) id<ASTableDelegate> asyncDelegate ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode's .delegate property instead.");
7376
@property (nonatomic, weak) id<ASTableDataSource> asyncDataSource ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode .dataSource property instead.");
7477

AsyncDisplayKit/ASTableView.mm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,10 @@ - (void)setDataSource:(id<UITableViewDataSource>)dataSource
337337

338338
- (void)setDelegate:(id<UITableViewDelegate>)delegate
339339
{
340-
// Our UIScrollView superclass sets its delegate to nil on dealloc. Only assert if we get a non-nil value here.
341-
ASDisplayNodeAssert(delegate == nil, @"ASTableView uses asyncDelegate, not UITableView's delegate property.");
340+
// The compiler will prevent users from calling this,
341+
// but we will automatically route to @c asyncDelegate
342+
// to support interop with frameworks like TLYShyNavBar.
343+
self.asyncDelegate = (id<ASTableDelegate>)delegate;
342344
}
343345

344346
- (id<ASTableDataSource>)asyncDataSource
@@ -355,7 +357,7 @@ - (void)setAsyncDataSource:(id<ASTableDataSource>)asyncDataSource
355357
// the (common) case of nilling the asyncDataSource in the ViewController's dealloc. In this case our _asyncDataSource
356358
// will return as nil (ARC magic) even though the _proxyDataSource still exists. It's really important to hold a strong
357359
// reference to the old dataSource in this case because calls to ASTableViewProxy will start failing and cause crashes.
358-
NS_VALID_UNTIL_END_OF_SCOPE id oldDataSource = self.dataSource;
360+
NS_VALID_UNTIL_END_OF_SCOPE id oldDataSource = super.dataSource;
359361

360362
if (asyncDataSource == nil) {
361363
_asyncDataSource = nil;

examples/CustomCollectionView-Swift/Sample/MosaicCollectionViewLayout.swift

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,17 +228,6 @@ class MosaicCollectionViewLayoutInspector: NSObject, ASCollectionViewLayoutInspe
228228
return ASSizeRange.init(min: CGSize.zero, max: layout._headerSizeForSection(section: atIndexPath.section))
229229
}
230230

231-
/**
232-
* Asks the inspector for the number of supplementary sections in the collection view for the given kind.
233-
*/
234-
func collectionView(_ collectionView: ASCollectionView, numberOfSectionsForSupplementaryNodeOfKind kind: String) -> UInt {
235-
if (kind == UICollectionElementKindSectionHeader) {
236-
return UInt((collectionView.dataSource?.numberOfSections!(in: collectionView))!)
237-
} else {
238-
return 0
239-
}
240-
}
241-
242231
/**
243232
* Asks the inspector for the number of supplementary views for the given kind in the specified section.
244233
*/
@@ -251,6 +240,6 @@ class MosaicCollectionViewLayoutInspector: NSObject, ASCollectionViewLayoutInspe
251240
}
252241

253242
func scrollableDirections() -> ASScrollDirection {
254-
return ASScrollDirectionVerticalDirections;
243+
return ASScrollDirectionVerticalDirections
255244
}
256245
}

0 commit comments

Comments
 (0)