-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conversation
Is #146 the right issue?? |
Off by one 😅 |
@rnystrom updated the pull request - view changes |
@rnystrom updated the pull request - view changes |
@rnystrom updated the pull request - view changes |
Ready for review! |
@rnystrom updated the pull request - view changes |
Can't offer much in terms of review for ObjC, sorry! 😅 Is this purely additive, or am I missing the breaking change here? |
Nope shouldn't be anything breaking, all new APIs |
Tests/IGListAdapterTests.m
Outdated
@@ -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]; |
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.
nit: off by one space?
Tests/IGListAdapterTests.m
Outdated
@@ -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]; |
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.
nit
@rnystrom updated the pull request - view changes |
Looks like this needs a test covering move w/out batch updates: https://coveralls.io/builds/9778932/source?filename=Source%2FIGListAdapterUpdater.m |
@rnystrom updated the pull request - view changes |
@jessesquires mind giving this a quick run through before I land? |
ping @jessesquires |
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.
Left a couple thoughts about naming.
@@ -48,6 +49,11 @@ IGLK_SUBCLASSING_RESTRICTED | |||
@property (nonatomic, strong, readonly) NSSet<NSIndexPath *> *deleteIndexPaths; | |||
|
|||
/** | |||
Item delete index paths. |
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 doc
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.
👍 we save doc updating for version cuts, keeps history cleaner
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.
Ah I just mean, this should read Item move index paths.
Source/IGListAdapter.m
Outdated
@@ -552,22 +552,22 @@ - (BOOL)itemCountIsZero { | |||
return isZero; | |||
} | |||
|
|||
- (IGListSectionMap *)sectionMapAdjustForUpdateBlock:(BOOL)adjustForUpdateBlock { | |||
- (IGListSectionMap *)sectionMapAdjustForUpdateBlock:(BOOL)usePreviousSection { |
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.
Would - (IGListSectionMap *)sectionMapUsingPreviousIfInUpdateBlock:(BOOL)usePreviousMapIfInUpdateBlock
or something be clearer?
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.
🤔 I like that!
Source/IGListAdapter.m
Outdated
const NSInteger section = [self.sectionMap sectionForSectionController:controller]; | ||
- (NSIndexPath *)indexPathForSectionController:(IGListSectionController *)controller | ||
index:(NSInteger)index | ||
usePreviousSection:(BOOL)usePreviousSection { |
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.
Would usePreviousMap
or usePreviousSectionMap
be clearer?
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.
I think I'll update this to match the previous comment so they are in sync. Good call outs!
Source/IGListAdapter.m
Outdated
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.", |
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.
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]; |
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.
❤️
[self.moveIndexPaths addObject:move]; | ||
} else { | ||
[self.delegate listAdapterUpdater:self willMoveFromIndexPath:fromIndexPath toIndexPath:toIndexPath collectionView:collectionView]; | ||
[collectionView moveItemAtIndexPath:fromIndexPath toIndexPath:toIndexPath]; |
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.
should we have a didMove:
delegate method?
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.
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; |
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.
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)
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.
👍 filed #466 to follow up
Source/IGListUpdatingDelegate.h
Outdated
|
||
@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. |
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.
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; |
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.
them :
😄
@@ -1189,4 +1189,152 @@ - (void)test_whenQueuingUpdate_withSectionControllerBatchUpdate_thatSectionContr | |||
XCTAssertNil(weakSectionController); | |||
} | |||
|
|||
- (void)test_whenMovingItems_withObjectMoving_thatCollectionViewWorks { |
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.
"thatCollectionViewWorks" lol
looks pretty good to me! 😎 |
@rnystrom updated the pull request - view changes |
@rnystrom updated the pull request - view changes |
@rnystrom has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
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
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
IGListBatchUpdateData
tests to check moves duringMoving within a reloaded section (no op)can't reload sectionsIGListAdapterUpdater
IGListReloadDataUpdater
(mostly for code coverage...)IGListStackedSectionController
CHANGELOG.md
entry for 3.0.0