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

Commit 0badff6

Browse files
author
Adlai Holler
authored
Revert "Route setDelegate: to setAsyncDelegate: (#3007)" (#3023)
This reverts commit 5c8818d.
1 parent ec59c31 commit 0badff6

5 files changed

Lines changed: 17 additions & 16 deletions

File tree

AsyncDisplayKit/ASCollectionView.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ 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-
131128
/**
132129
* The object that acts as the asynchronous delegate of the collection view
133130
*

AsyncDisplayKit/ASCollectionView.mm

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

368368
- (void)setDelegate:(id<UICollectionViewDelegate>)delegate
369369
{
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;
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.");
374372
}
375373

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

AsyncDisplayKit/ASTableView.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ 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-
7572
@property (nonatomic, weak) id<ASTableDelegate> asyncDelegate ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode's .delegate property instead.");
7673
@property (nonatomic, weak) id<ASTableDataSource> asyncDataSource ASDISPLAYNODE_DEPRECATED_MSG("Use ASTableNode .dataSource property instead.");
7774

AsyncDisplayKit/ASTableView.mm

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

338338
- (void)setDelegate:(id<UITableViewDelegate>)delegate
339339
{
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;
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.");
344342
}
345343

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

362360
if (asyncDataSource == nil) {
363361
_asyncDataSource = nil;

examples/CustomCollectionView-Swift/Sample/MosaicCollectionViewLayout.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,17 @@ 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+
231242
/**
232243
* Asks the inspector for the number of supplementary views for the given kind in the specified section.
233244
*/
@@ -240,6 +251,6 @@ class MosaicCollectionViewLayoutInspector: NSObject, ASCollectionViewLayoutInspe
240251
}
241252

242253
func scrollableDirections() -> ASScrollDirection {
243-
return ASScrollDirectionVerticalDirections
254+
return ASScrollDirectionVerticalDirections;
244255
}
245256
}

0 commit comments

Comments
 (0)