-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[Umbrella] ASCollectionView -> ASCollectionNode Migration, Separate Index Spaces #2372
Conversation
4b8a691
to
57de591
Compare
@@ -440,6 +440,7 @@ | |||
CC7FD9DF1BB5E962005CCB2B /* ASPhotosFrameworkImageRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = CC7FD9DD1BB5E962005CCB2B /* ASPhotosFrameworkImageRequest.m */; }; | |||
CC7FD9E11BB5F750005CCB2B /* ASPhotosFrameworkImageRequestTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC7FD9E01BB5F750005CCB2B /* ASPhotosFrameworkImageRequestTests.m */; }; | |||
CC7FD9E21BB603FF005CCB2B /* ASPhotosFrameworkImageRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = CC7FD9DC1BB5E962005CCB2B /* ASPhotosFrameworkImageRequest.h */; settings = {ATTRIBUTES = (Public, ); }; }; | |||
CC87BB951DA8193C0090E380 /* ASCellNode+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = CC87BB941DA8193C0090E380 /* ASCellNode+Internal.h */; }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file existed before, but wasn't part of the project for some reason.
NSIndexPath *ip = [(ASCollectionNode *)owningNode indexPathForNode:self]; | ||
if (ip != nil) { | ||
[result addObject:@{ @"indexPath" : ip }]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is sort of unrelated and should have been here before. Really helps logging.
57de591
to
dc0c956
Compare
/** | ||
* This is a node-based UICollectionViewDataSource. | ||
*/ | ||
@protocol ASCollectionDataSource <ASCommonCollectionDataSource> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (and ASCollectionDelegate
ASTableDataSource
and ASTableDelegate
) was kept as-is, but moved from the View.h
file to the Node.h
file.
return [_dataController nodeAtCompletedIndexPath:indexPath]; | ||
} | ||
|
||
- (NSIndexPath *)convertIndexPathFromCollectionNode:(NSIndexPath *)indexPath waitingIfNeeded:(BOOL)wait |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is private, and only here for backwards-compatibility reasons. Currently the scrollToItemAtIndexPath
methods on ASTableView
and ASCollectionView
take index paths in the data source space, and so for the time being we use this as a shim to maintain that behavior. In the future, after some testing, we'll remove our override on that method, and remove this with it.
- (void)collectionNode:(ASCollectionNode *)collectionNode didEndDisplayingItemWithNode:(ASCellNode *)node; | ||
|
||
- (BOOL)collectionNode:(ASCollectionNode *)collectionNode shouldHighlightItemWithNode:(ASCellNode *)node; | ||
- (void)collectionNode:(ASCollectionNode *)collectionNode didHighlightItemWithNode:(ASCellNode *)node; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a tough question. I could have gone with didSelectItemAtIndexPath
etc but since the item/section may have been deleted or reloaded, the argument would have to be nullable
which would be really wacky, giving users no information at all. I could filter out cases like that, but there could be legitimate arguments for behaviors like "whenever a header node of X class is showing, the background color of my view should be Y" so filtering out these callbacks would break that. Or if the user happened to select an item just before a section is reloaded, the select would get ignored.
So the user can either 1) build their architecture around nodes directly, and check the node class or 2) call [collectionNode indexPathForNode:node]
. The only trouble here is, if they don't nil-check the index path, they'll get {0,0} for item and section, and they may do something even worse! Tough calls… @appleguy @maicki
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I've reversed stance on this. In order to keep things simple, all delegate callbacks except willDisplayRow
and didEndDisplayingRow
will pass a nonnull NSIndexPath *
. In the extremely unlikely case that the user selected an item that is pending deletion/reload, the event won't get sent.
59ba5ab
to
55d787f
Compare
* Boolean parameter that contains the value YES if all of the related animations completed successfully or | ||
* NO if they were interrupted. This parameter may be nil. If supplied, the block is run on the main thread. | ||
*/ | ||
- (void)performBatchAnimated:(BOOL)animated updates:(nullable __attribute((noescape)) void (^)())updates completion:(nullable void (^)(BOOL finished))completion; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add back in performBatchUpdates without the animated flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
/** | ||
* Asks the data source for the number of items in the given section of the collection node. | ||
* | ||
* @see @c numberOfSectionsInCollectionView: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update
@@ -209,33 +238,19 @@ + (Class)layerClass | |||
|
|||
- (instancetype)initWithCollectionViewLayout:(UICollectionViewLayout *)layout | |||
{ | |||
return [self _initWithFrame:CGRectZero collectionViewLayout:layout ownedByNode:NO]; | |||
return [self _initWithFrame:CGRectZero collectionViewLayout:layout layoutFacilitator:nil]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super nit: can this call through into initWithFrame:
@Adlai-Holler: Want me to push these example project updates?
|
@hannahmbanana Sure – feel free to push them onto this branch. |
These examples were updated to use ASCollectionNode instead of ASCollectionView as part of PR #2372
@Adlai-Holler: could you review the example file updates? |
Beef up our supplementary node support Make the API way better Go nuts Add a unit test for UICollectionView's handling of reloadData inside batch updates Wrap indexPathForNode: in a cache Convert index paths in delegate methods Go back on table view Put collection view back Switch up the API Move most ASCollectionView API to ASCollectionNode Move most table logic over to ASTableNode Do the things More conversion work Keep on keepin' on Get table view delegate API done More porting Simplify Clear the delegate More cleanup Move more stuff around Remove pointless file Re-add some API Put back more API Use the right flag
f867ccc
to
372f2ca
Compare
@@ -192,7 +192,7 @@ - (void)tableView:(ASTableView *)tableView willBeginBatchFetchWithContext:(ASBat | |||
- (void)resetAllData | |||
{ | |||
[_photoFeed clearFeed]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hannahmbanana Change tableView:willBeginBatchFetchWithContext:
above to tableNode:willBeginBatchFetchWithContext:
. Is that not showing a deprecation warning? Bummer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also change the other ASTableDelegate methods to tableNode:numberOfRowsInSection:
etc.
@@ -92,6 +96,8 @@ - (void)viewDidLoad | |||
|
|||
- (void)reloadTapped | |||
{ | |||
// This method is deprecated because we reccommend using ASCollectionNode instead of ASCollectionView. | |||
// This functionality & example project remains for users who insist on using ASCollectionView. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hannahmbanana Since ASCollectionView
outside of the node isn't going to be supported for long, this sample should either be changed majorly or discarded entirely.
40c49d8
to
2444505
Compare
@Adlai-Holler: There's a bug with ASTableNode /
I'll push the fix when I push the example updates. |
Here we go! |
I've tested this thoroughly with Pinterest using the deprecated API.
Supersedes #2348 .
Methods involving the
ASCollectionNode
always use data source index space. Methods on the view always use UIKit index space. I may removenodeForRowAtIndexPath
andindexPathForNode
fromASTableView
to avoid confusion but I'm still thinking about possibly legitimate use cases for them such as interactive reordering andscrollToRowAtIndexPath:
or after they callindexPathForCell:
for some reason, which they shouldn't do but we can't stop them.