-
Couldn't load subscription status.
- Fork 2.2k
[ASCollectionView] Repopulate supplementary views on item-level changes #1629
[ASCollectionView] Repopulate supplementary views on item-level changes #1629
Conversation
| [self batchLayoutNodesFromContexts:contexts ofKind:kind completion:^(NSArray<ASCellNode *> *nodes, NSArray<NSIndexPath *> *indexPaths) { | ||
| [self insertNodes:nodes ofKind:kind atIndexPaths:indexPaths completion:nil]; | ||
| }]; | ||
| [_pendingContexts removeObjectForKey:kind]; |
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.
You are mutating _pendingContexts while enumerating over it. Shouldn't this be throwing an exception?
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.
It seems like it doesn't throw an exception but does not do what you expect either. Try this in a playground:
var mutableArray = NSMutableArray(array: [1,2,3,4,5,6])
mutableArray.enumerateObjectsUsingBlock { (object, idx, stop) in
print("\(idx): \(object)")
mutableArray.removeObject(object)
}
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.
Oh, I just realized that _pendingContexts is a dictionary not an array. Sorry about that.
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.
While I definitely agree that this is an issue, this is the precedent set by the code above in this file at https://github.com/facebook/AsyncDisplayKit/blob/master/AsyncDisplayKit/Details/ASCollectionDataController.mm#L90-L101
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.
@erichoracek please do fix that, as it seems to be an oversight.
|
This is really great, thanks Eric! Great to e-meet you by the way, would love to talk with you sometime soon to see if I can help out with any of your projects. As you no doubt noticed while working in this code, supplementary node support is scheduled to be revisited. This work is a valuable contribution to that effort and takes it in the right direction. One thing we’d like to do is better integrate supplementary node handling with regular cell handling, so that we can also use “supplementary” elements to support section header and footer nodes in ASTableView. That said, you shouldn’t worry about this, simply some context on what we’d like to see happen here in the next ~3 months. Send me a note at asyncdisplaykit@gmail.com mailto:asyncdisplaykit@gmail.com if you’re dealing with any blockers or have some highly desired features. I’ll try to get this reviewed and merged ASAP / in the next few days. We’re not too far from 1.9.8 as well.
|
|
@erichoracek really strong stuff! Thanks so much for this patch. Would you be able to add some test cases to the supplementary node example project? This will help outline the given scenario and prove the solution. I'm looking forward to getting this in! |
|
@levi Thanks! The one example project I see with supplementary nodes is the |
|
@erichoracek Could you update to fix conflicts? Sorry I didn't get to this in time to avoid them! I will land this as soon as I notice (feel free to send me a Slack) |
|
@maicki take a review pass here if you get a chance as you know this code as well as anyone :) |
| [self batchLayoutNodesFromContexts:contexts ofKind:kind completion:^(NSArray<ASCellNode *> *nodes, NSArray<NSIndexPath *> *indexPaths) { | ||
| [self insertNodes:nodes ofKind:kind atIndexPaths:indexPaths completion:nil]; | ||
| }]; | ||
| [_pendingContexts removeObjectForKey:kind]; |
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.
Do we remove the kind of pending contexts in some other place?
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 change is due to the fact that _pendingContexts is being enumerated in this block so mutating it has no effect. What change are you asking for here?
|
@appleguy One small comment, but overall looks good to me. |
|
@erichoracek Hi Eric - I'm back from Vietnam and Cambodia! I believe the same conflicts are still present. If you can ping me on Slack once they're fixed, I'll merge straight away. Thanks for working on this! |
b7e7bfc to
6f0a15e
Compare
Currently within `ASCollectionView`, there is an assumption that there will always be a static number of supplementary views per section—even when additional items are added or removed from that section. This is evidenced by the fact that when you invoke -[ASCollectionView insertItemsAtIndexPaths:], the data source method -[ASCollectionDataSource collectionView:nodeForSupplementaryElementOfKind:atIndexPath:] is not invoked, preventing consumers from specifying a new number of supplementary nodes for the new set of items. With this change, the set of supplementary nodes for a section is now recalculated not only on section-level mutations, but also on item-level mutations as well. This adds item-level counterparts to the section-level `-prepareFor...` subclassing hooks in `ASDataController+Subclasses.h` to make this possible. This should fix facebookarchive#1278 and facebookarchive#1322 This has been tested in my project and seen to fix the assertion. Open to suggestions on how to test in a more universal way.
6f0a15e to
ed9fcdc
Compare
|
@appleguy Awesome! Should be rebased with master—be sure to let me know if there's anything else that looks like it needs to be changed. Thanks! |
|
@erichoracek Diving save to join the 1.9.8 release!! Thanks for the super quick response, you are in :) I'd love to hear about your experiences with the framework sometime -- if you are on Slack, let's see if a call (or meet at WWDC!) would equip both of us with new information about our craft. |
…ve#1629) * Allow full color tinting on grayscale template images. * Signing a commit with the correct email address. * Add snapshot test for a grayscale image with ASExperimentalDrawingGlobal enabled.
Currently within
ASCollectionView, there is an assumption that there will always be a static number of supplementary views per section—even when additional items are added or removed from that section. This is evidenced by the fact that when you invoke -[ASCollectionView insertItemsAtIndexPaths:], the data source method -[ASCollectionDataSource collectionView:nodeForSupplementaryElementOfKind:atIndexPath:] is not invoked, preventing consumers from specifying a new number of supplementary nodes for the new set of items.With this change, the set of supplementary nodes for a section is now recalculated not only on section-level mutations, but also on item-level mutations as well. This adds item-level counterparts to the section-level
-prepareFor...subclassing hooks inASDataController+Subclasses.hto make this possible.This should fix #1278 and #1322
This has been tested in my project and seems to fix the assertion. Open to suggestions on how to test in a more universal way.