Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add item-level moves to IGListCollectionContext #418

Closed
wants to merge 11 commits into from
Closed

Conversation

rnystrom
Copy link
Contributor

@rnystrom rnystrom commented Jan 13, 2017

Changes in this pull request

Adding an API to do item-level (cell) moves on the collection view. This complicates things a little bit because of all the issues that moving sections have while in batch updates (e.g. simultaneous animation UICV bugs). Thankfully we use pretty strict types so the compiler does most of the work for us.

Closes #145

TODO

  • Tests build and pass
  • Add IGListBatchUpdateData tests to check moves during
    • Moving within a reloaded section (no op) can't reload sections
    • Moving within a deleted section (no op)
    • Moving within a moved section (convert section ops to delete+insert)
    • Moving an index path that is also reloaded (convert to delete+insert path)
  • Add move unit tests to IGListAdapterUpdater
  • Add move unit tests to IGListReloadDataUpdater (mostly for code coverage...)
  • Add move unit tests to IGListStackedSectionController
  • Add CHANGELOG.md entry for 3.0.0
  • Test moving without batch updates

@jessesquires
Copy link
Contributor

Is #146 the right issue??

@jessesquires jessesquires added this to the 3.0.0 milestone Jan 15, 2017
@rnystrom
Copy link
Contributor Author

Off by one 😅

@facebook-github-bot
Copy link
Contributor

@rnystrom updated the pull request - view changes

@facebook-github-bot
Copy link
Contributor

@rnystrom updated the pull request - view changes

@rnystrom rnystrom changed the title WIP: Add item-level moves to IGListCollectionContext Add item-level moves to IGListCollectionContext Jan 20, 2017
@facebook-github-bot
Copy link
Contributor

@rnystrom updated the pull request - view changes

@rnystrom
Copy link
Contributor Author

Ready for review!

@facebook-github-bot
Copy link
Contributor

@rnystrom updated the pull request - view changes

@Sherlouk
Copy link
Contributor

Can't offer much in terms of review for ObjC, sorry! 😅

Is this purely additive, or am I missing the breaking change here?

@rnystrom rnystrom requested review from zhubofei and removed request for Sherlouk January 20, 2017 17:43
@rnystrom
Copy link
Contributor Author

Nope shouldn't be anything breaking, all new APIs

@@ -134,7 +134,7 @@ - (void)test_whenQueryingIndexPaths_withSectionController_thatPathsAreEqual {
IGListSectionController <IGListSectionType> * second = [self.adapter sectionControllerForObject:@1];
NSArray *paths0 = [self.adapter indexPathsFromSectionController:second
indexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(2, 4)]
adjustForUpdateBlock:NO];
usePreviousSection:NO];

Choose a reason for hiding this comment

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

nit: off by one space?

@@ -153,7 +153,7 @@ - (void)test_whenQueryingIndexPaths_insideBatchUpdateBlock_thatPathsAreEqual {
[self.adapter performBatchAnimated:YES updates:^{
NSArray *paths = [self.adapter indexPathsFromSectionController:second
indexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(2, 2)]
adjustForUpdateBlock:YES];
usePreviousSection:YES];

Choose a reason for hiding this comment

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

nit

@facebook-github-bot
Copy link
Contributor

@rnystrom updated the pull request - view changes

@rnystrom
Copy link
Contributor Author

Looks like this needs a test covering move w/out batch updates:

https://coveralls.io/builds/9778932/source?filename=Source%2FIGListAdapterUpdater.m

@facebook-github-bot
Copy link
Contributor

@rnystrom updated the pull request - view changes

@rnystrom
Copy link
Contributor Author

@jessesquires mind giving this a quick run through before I land?

@rnystrom
Copy link
Contributor Author

rnystrom commented Feb 2, 2017

ping @jessesquires

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.

Left a couple thoughts about naming.

@@ -48,6 +49,11 @@ IGLK_SUBCLASSING_RESTRICTED
@property (nonatomic, strong, readonly) NSSet<NSIndexPath *> *deleteIndexPaths;

/**
Item delete index paths.
Copy link
Contributor

Choose a reason for hiding this comment

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

Update doc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 we save doc updating for version cuts, keeps history cleaner

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I just mean, this should read Item move index paths.

@@ -552,22 +552,22 @@ - (BOOL)itemCountIsZero {
return isZero;
}

- (IGListSectionMap *)sectionMapAdjustForUpdateBlock:(BOOL)adjustForUpdateBlock {
- (IGListSectionMap *)sectionMapAdjustForUpdateBlock:(BOOL)usePreviousSection {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would - (IGListSectionMap *)sectionMapUsingPreviousIfInUpdateBlock:(BOOL)usePreviousMapIfInUpdateBlock or something be clearer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 I like that!

const NSInteger section = [self.sectionMap sectionForSectionController:controller];
- (NSIndexPath *)indexPathForSectionController:(IGListSectionController *)controller
index:(NSInteger)index
usePreviousSection:(BOOL)usePreviousSection {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would usePreviousMap or usePreviousSectionMap be clearer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I'll update this to match the previous comment so they are in sync. Good call outs!

IGParameterAssert(fromIndex >= 0);
IGParameterAssert(toIndex >= 0);
UICollectionView *collectionView = self.collectionView;
IGAssert(collectionView != nil, @"Moving items from %@ without a collection view from index to %zi index %zi.",
Copy link
Contributor

Choose a reason for hiding this comment

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

assert message:

from index to %zi index %zi.

should be:

index %zi to index %zi.

_deleteIndexPaths = [NSMutableSet new];
_insertIndexPaths = [NSMutableSet new];
_moveIndexPaths = [NSMutableSet new];
_reloadIndexPaths = [NSMutableSet new];
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

[self.moveIndexPaths addObject:move];
} else {
[self.delegate listAdapterUpdater:self willMoveFromIndexPath:fromIndexPath toIndexPath:toIndexPath collectionView:collectionView];
[collectionView moveItemAtIndexPath:fromIndexPath toIndexPath:toIndexPath];
Copy link
Contributor

Choose a reason for hiding this comment

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

should we have a didMove: delegate method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we're ok since we don't have any did* for insert/delete/reload

- (void)listAdapterUpdater:(IGListAdapterUpdater *)listAdapterUpdater didPerformBatchUpdates:(IGListBatchUpdateData *)updates withCollectionView:(UICollectionView *)collectionView;
- (void)listAdapterUpdater:(IGListAdapterUpdater *)listAdapterUpdater
didPerformBatchUpdates:(IGListBatchUpdateData *)updates
withCollectionView:(UICollectionView *)collectionView;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

this is the only delegate method spelled withCollectionView:. 😞 the others are simply spelled collectionView:.

I'd prefer to remove the "with" here. (could be another diff. will require changelog entry)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 filed #466 to follow up


@param collectionView The collection view on which to perform the transition.
@param fromIndexPath The original index path of the item to move.
@param toIndexPath The index path to move the item to.
Copy link
Contributor

@jessesquires jessesquires Feb 3, 2017

Choose a reason for hiding this comment

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

how about:

@param fromIndexPath The source index path of the item to move.
@param toIndexPath The destination index path of the item to move.

usePreviousSection:(BOOL)usePreviousSection;
- (nullable NSIndexPath *)indexPathForSectionController:(IGListSectionController *)controller
index:(NSInteger)index
usePreviousSection:(BOOL)usePreviousSection;
Copy link
Contributor

Choose a reason for hiding this comment

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

them : 😄

@@ -1189,4 +1189,152 @@ - (void)test_whenQueuingUpdate_withSectionControllerBatchUpdate_thatSectionContr
XCTAssertNil(weakSectionController);
}

- (void)test_whenMovingItems_withObjectMoving_thatCollectionViewWorks {
Copy link
Contributor

Choose a reason for hiding this comment

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

"thatCollectionViewWorks" lol

@jessesquires
Copy link
Contributor

looks pretty good to me! 😎

@facebook-github-bot
Copy link
Contributor

@rnystrom updated the pull request - view changes

@facebook-github-bot
Copy link
Contributor

@rnystrom updated the pull request - view changes

@facebook-github-bot
Copy link
Contributor

@rnystrom has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@rnystrom rnystrom mentioned this pull request Feb 15, 2017
10 tasks
@jessesquires jessesquires deleted the move-items branch February 23, 2017 23:49
facebook-github-bot pushed a commit that referenced this pull request Mar 15, 2017
Summary:
Started work on the plane to get this moving since #418  is up and ready to land. We'll likely need to spend some time fleshing out the API of this, and I think I'll split it up into a couple different PRs once ready for review. Putting this up now to get early feedback.

This adds an auto-diffing section controller as outlined in #38. There are several key parts:

- Subclass a new section controller `IGListAutoSectionController` (naming wip)
- Connect a data source
- Implement the data source methods that do 3 things:
  - Given a top-level object, transform it into an array of **diffable** view models
  - Given a view model, return a cell
  - Given a view model, return a size for a cell
- A new protocol for the cell `IGListBindable` so that we can control when the cell is updated w/ the view model.
  - The most important part of this is that it unlocks moving and reloading a cell, which you can't do w/ `UICollectionView`

- [ ] Unit test `reloadObjects:`
- [x] Add
Closes #494

Reviewed By: amonshiz

Differential Revision: D4696966

Pulled By: rnystrom

fbshipit-source-id: f21b8341b3ed4389f2a4a106d0d316f481ba6943
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants