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

[ASCollectionView][Architecture] Introduce ASSectionContext#2178

Merged
Adlai-Holler merged 1 commit intofacebookarchive:masterfrom
nguyenhuy:ASSectionContext
Oct 1, 2016
Merged

[ASCollectionView][Architecture] Introduce ASSectionContext#2178
Adlai-Holler merged 1 commit intofacebookarchive:masterfrom
nguyenhuy:ASSectionContext

Conversation

@nguyenhuy
Copy link
Contributor

@nguyenhuy nguyenhuy commented Sep 1, 2016

It is a custom object that can be optionally provided by ASCollectionDataSource and later retrieved from the collection view to be used in collection view layout. The idea was first proposed by @Adlai-Holler in #2067.

I've been playing around with different ways to implement this feature, including having an ASSection that is a proxy of cell nodes array (here), or an ASSection that is a subclass of NSMutableArray<ASCellNode *> (here). I think the implementation in this PR is simpler and thus, more elegant.

Please let me know what you think, @Adlai-Holler @maicki @appleguy @garrettmoon @levi. Thanks!

TODO:

@ghost ghost added the CLA Signed label Sep 1, 2016
@nguyenhuy nguyenhuy changed the title Introduce ASSectionContext [ASColelctionView][Architecture]Introduce ASSectionContext Sep 1, 2016
@nguyenhuy nguyenhuy changed the title [ASColelctionView][Architecture]Introduce ASSectionContext [ASCollectionView][Architecture]Introduce ASSectionContext Sep 1, 2016
@nguyenhuy nguyenhuy changed the title [ASCollectionView][Architecture]Introduce ASSectionContext [ASCollectionView][Architecture] Introduce ASSectionContext Sep 1, 2016
@ghost ghost added the CLA Signed label Sep 1, 2016
*/
- (void)collectionViewUnlockDataSource:(ASCollectionView *)collectionView ASDISPLAYNODE_DEPRECATED;

- (_Nonnull id<ASSectionContext>)collectionView:(ASCollectionView *)collectionView contextForSectionAtIndex:(NSInteger)sectionIndex;
Copy link
Contributor

@Adlai-Holler Adlai-Holler Sep 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be nullable?

I see – if you implement this we assume you always want to provide one. OK!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. This method is optional and if users implement it, they need to provide a context.

That's said, in some cases, they may want to provide contexts for just a subset of sections. @Adlai-Holler Should we support it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually if we create an object for each section that holds a nullable context, we can relax on the nullability of this method. Will work on it.

@Adlai-Holler
Copy link
Contributor

@nguyenhuy This is looking perfect! This will be a huge boon for Pinterest, where synchronizing section info has been a major pain point.

Looking toward the future, I think creating an object for each section even if they don't provide us with a context is valuable. I have some pretty ambitious plans for collection view debugging tools, and reifying the section abstraction (with an auto-incrementing ID) will help move us toward that.

These section objects do not need to hold any nodes or anything – I agree with you that those other two approaches got too messy too fast. Just an ID and optionally a context. Thoughts?

@Adlai-Holler
Copy link
Contributor

@nguyenhuy How's this going? Let me know if there's something that seems wonky or not quite right – once landed this will resolve an entire class of possible inconsistency issues in one shot, so I'm really excited to get it dialed in.

@ghost ghost added the CLA Signed label Sep 12, 2016
@ghost ghost added the CLA Signed label Sep 15, 2016
@nguyenhuy
Copy link
Contributor Author

@Adlai-Holler: Sorry this took so long. I've added ASSection and addressed your comments. Please give this PR another review. Thank you!

@ghost ghost added the CLA Signed label Sep 15, 2016
Copy link
Contributor

@Adlai-Holler Adlai-Holler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nguyenhuy This is absolutely excellent! I'm champing at the bit to deploy this and see how it works!

I left a couple notes, and I think in terms of unit tests some very basic cases will be sufficient to get the ball rolling:

  • Test that after the initial layout, the collection view returns the correct context objects.
  • Test that after section move, the collection view returns the correct context objects.
  • Test that after reload data, the collection view returns the correct context objects.
  • Test that after reloading a section, the collection view returns the correct context objects.

I can't wait to have this up and running, so don't hesitate to reach out if anything could be clearer or seems wonky.

- (id<ASSectionContext>)dataController:(ASDataController *)dataController contextForSection:(NSInteger)section
{
ASDisplayNodeAssertMainThread();
id<ASSectionContext> context;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialize this to nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

*/
- (void)collectionViewUnlockDataSource:(ASCollectionView *)collectionView ASDISPLAYNODE_DEPRECATED;

- (id<ASSectionContext> _Nullable)collectionView:(ASCollectionView *)collectionView contextForSection:(NSInteger)section;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the prettier - (nullable id<ASSectionContext>)collectionView: style throughout.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@appleguy
Copy link
Contributor

@Adlai-Holler — is it OK if we merge this before @nguyenhuy 's final changes? He's getting ready for the big move and so any polishing touches here would be better to do after integrating it, but only if they don't have important functional impacts.

@ghost ghost added the CLA Signed label Sep 27, 2016
@ghost ghost added the CLA Signed label Sep 27, 2016
@nguyenhuy
Copy link
Contributor Author

@Adlai-Holler @appleguy: Addressed comments and added test cases.

@Adlai-Holler
Copy link
Contributor

@nguyenhuy Wow excellent! I really appreciate the quality of your work. If you'll rebase or merge latest master, the CI should be fixed and this should be ready for primetime.

I'm confident this will work well, but for the sake of due diligence we'll test this against Pinterest via a cherry-pick and then land it immediately after.

@ghost ghost added the CLA Signed label Sep 27, 2016
@ghost ghost added the CLA Signed label Sep 27, 2016
@ghost ghost added the CLA Signed label Sep 28, 2016
@nguyenhuy
Copy link
Contributor Author

nguyenhuy commented Sep 28, 2016

@Adlai-Holler: Squashed all commits into one and rebased it on top of latest master. Waiting for Travis to finish which seems to take forever :(

Appreciate your test against Pinterest. Let me know what you find!

Edit: Apparently Travis failed because of a misconfiguration in xcodeproj (i.e ASSectionContext.h should be a public header). Fixed it and we're good to go :)

- Objects conform to ASSectionContext protocol can be provided via ASCollectionDataSource and later retrieved from the collection view. They are guaranteed to be in sync with sections of the collection view. They can be used to store additional data associated with each section, to be used in collection view layout and the like.
- ASSection is an internal object that is the foundation for coming debugging tools.
- Unit tests included.
@Adlai-Holler
Copy link
Contributor

Hannah has tested it for a while and I did the same. This is running excellently! Thanks so much Huy – I'm going to start building on this system immediately. Let's do this again sometime!

@Adlai-Holler Adlai-Holler merged commit 066351b into facebookarchive:master Oct 1, 2016
@nguyenhuy
Copy link
Contributor Author

@Adlai-Holler: I'm really glad it works. More than happy to do this again, anytime!

hannahmbanana pushed a commit that referenced this pull request Oct 3, 2016
- Objects conform to ASSectionContext protocol can be provided via ASCollectionDataSource and later retrieved from the collection view. They are guaranteed to be in sync with sections of the collection view. They can be used to store additional data associated with each section, to be used in collection view layout and the like.
- ASSection is an internal object that is the foundation for coming debugging tools.
- Unit tests included.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants