-
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 APIs for invalidating single and many items in section controller #443
Conversation
@Sherlouk updated the pull request - view changes |
@Sherlouk updated the pull request - view changes |
Was building against macOS scheme so Xcode wasn't flagging errors, should be fixed now. |
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.
@Sherlouk super cool! This is going to be so useful.
Unsure the best way to test these new methods, so a suggestion would be welcomed!
These should probably go in IGListAdapterTests and IGListStackSectionControllerTests.
For the tests, we'll want to:
- Be able to control what is returned in a test section controller's
sizeForItem:
- Lay everything out and assert the size is correct
- Get the section controller and update the size
- Call invalidate
- Assert the sizes are correct
Something along these lines:
self.dataSource.objects = @[@1, @2];
[self.adapter reloadDataWithCompletion:nil];
UICollectionViewCell *cell = [self.colectionView cellForItemAtIndexpath:[NSIndexPath indexPathForItem:0 section:0]];
XCTAssertEqual(cell.frame.size.width, 100);
XCTAssertEqual(cell.frame.size.height, 10);
IGListSectionController<IGListSectionType> *controller = [self.adapter sectionControllerForObject:@1];
controller.customHeight = 30;
[controller.collectionContext invalidateLayoutForSectionController:controller];
UICollectionViewCell *cell = [self.colectionView cellForItemAtIndexpath:[NSIndexPath indexPathForItem:0 section:0]];
XCTAssertEqual(cell.frame.size.width, 100);
XCTAssertEqual(cell.frame.size.height, 30);
We don't have any test section controller's w/ variable sizes though, so it might require some work. We could do w/ more centralized test objects, section controllers, etc.
|
||
@param indexPaths The index path array to invalidate. | ||
*/ | ||
- (void)invalidateLayoutForIndexPaths:(NSArray<NSIndexPath *> *) indexPaths; |
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.
Since section controllers shouldn't know about index paths, can we change this to:
- (void)invalidateLayoutForSectionController:(IGListSectionController<IGListSectionType> *)sectionController indexes:(NSIndexSet *)indexes;
I wonder, maybe we should just have a single API for this?
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.
Will reduce down to just a single API, if a user wants to reset the whole section then it's not that difficult to create an index set for the entire range
IGAssertMainThread(); | ||
IGParameterAssert(sectionController != nil); | ||
|
||
NSInteger itemCount = [sectionController numberOfItems]; |
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: const
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.
Don't mind adding this, but for the sake of learning -- Is putting const here the same as using 'let' in Swift? "A non mutable version"
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.
Yup! Though its only going to stop from writing these primitives. It's not like you can do
const UILabel *label = [UILabel new];
label.text = @"foo";
Swift works basically the same w/ class
.
const
also works w/ structs in ObjC too, so you can't do
const CGRect frame = CGRectMake(0, 0, 100, 10);
frame.size.height = 20; // compiler error
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.
Removed the need for this variable by having a single API, though thanks for explaining it to me!
|
||
UICollectionViewLayoutInvalidationContext *context = [UICollectionViewLayoutInvalidationContext new]; | ||
[context invalidateItemsAtIndexPaths:indexPaths]; | ||
[self.collectionView.collectionViewLayout invalidateLayoutWithContext:context]; |
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.
Noting to myself that this is an iOS 8+ API, so we're covered w/ our min API
@Sherlouk updated the pull request - view changes |
Will work on the tests ASAP, as you say I think a bit more work is needed just to create a different sort of test object that is usable for more complicated tests. Amateur hour over here, but fun nonetheless! |
@Sherlouk no hurry on this 😄 we don't need to bundle it w/ 2.2, take your time.
🙌 |
Going to close this PR for the time being until I get a chance to work on this piece, will reopen then! |
Changes in this pull request
-[IGListCollectionContext invalidateLayoutForIndexPaths]
-[IGListCollectionContext invalidateLayoutForSectionController]
Unsure the best way to test these new methods, so a suggestion would be welcomed!
Closes #360
Pull request checklist
CHANGELOG.md
for any breaking changes, enhancements, or bug fixes.