-
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
Fix for #378 - emptyView not updated when items added #395
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -504,10 +504,13 @@ - (void)updateObjects:(NSArray *)objects dataSource:(id<IGListAdapterDataSource> | |
itemCount += [sectionController numberOfItems]; | ||
} | ||
|
||
[self updateBackgroundViewWithItemCount:itemCount]; | ||
[self updateBackgroundViewShouldHide:itemCount > 0]; | ||
} | ||
|
||
- (void)updateBackgroundViewWithItemCount:(NSUInteger)itemCount { | ||
- (void)updateBackgroundViewShouldHide:(BOOL)shouldHide { | ||
if (self.isInUpdateBlock) { | ||
return; // will be called again when update block completes | ||
} | ||
UIView *backgroundView = [self.dataSource emptyViewForListAdapter:self]; | ||
// don't do anything if the client is using the same view | ||
if (backgroundView != _collectionView.backgroundView) { | ||
|
@@ -516,7 +519,18 @@ - (void)updateBackgroundViewWithItemCount:(NSUInteger)itemCount { | |
[_collectionView.backgroundView removeFromSuperview]; | ||
_collectionView.backgroundView = backgroundView; | ||
} | ||
_collectionView.backgroundView.hidden = itemCount > 0; | ||
_collectionView.backgroundView.hidden = shouldHide; | ||
} | ||
|
||
- (BOOL)itemCountIsZero { | ||
__block BOOL isZero = YES; | ||
[self.sectionMap enumerateUsingBlock:^(id _Nonnull object, IGListSectionController<IGListSectionType> * _Nonnull sectionController, NSInteger section, BOOL * _Nonnull stop) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor nit: could we specify an explicit type for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, can we? it seems like
https://github.com/Instagram/IGListKit/blob/master/Source/Internal/IGListSectionMap.h#L103 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops! 😳 nevermind. 😄 |
||
if (sectionController.numberOfItems > 0) { | ||
isZero = NO; | ||
*stop = YES; | ||
} | ||
}]; | ||
return isZero; | ||
} | ||
|
||
- (IGListSectionMap *)sectionMapAdjustForUpdateBlock:(BOOL)adjustForUpdateBlock { | ||
|
@@ -918,6 +932,7 @@ - (void)reloadInSectionController:(IGListSectionController<IGListSectionType> *) | |
} else { | ||
NSArray *indexPaths = [self indexPathsFromSectionController:sectionController indexes:indexes adjustForUpdateBlock:YES]; | ||
[self.updater reloadItemsInCollectionView:collectionView indexPaths:indexPaths]; | ||
[self updateBackgroundViewShouldHide:![self itemCountIsZero]]; | ||
} | ||
} | ||
|
||
|
@@ -934,6 +949,7 @@ - (void)insertInSectionController:(IGListSectionController<IGListSectionType> *) | |
|
||
NSArray *indexPaths = [self indexPathsFromSectionController:sectionController indexes:indexes adjustForUpdateBlock:NO]; | ||
[self.updater insertItemsIntoCollectionView:collectionView indexPaths:indexPaths]; | ||
[self updateBackgroundViewShouldHide:![self itemCountIsZero]]; | ||
} | ||
|
||
- (void)deleteInSectionController:(IGListSectionController<IGListSectionType> *)sectionController atIndexes:(NSIndexSet *)indexes { | ||
|
@@ -949,6 +965,7 @@ - (void)deleteInSectionController:(IGListSectionController<IGListSectionType> *) | |
|
||
NSArray *indexPaths = [self indexPathsFromSectionController:sectionController indexes:indexes adjustForUpdateBlock:YES]; | ||
[self.updater deleteItemsFromCollectionView:collectionView indexPaths:indexPaths]; | ||
[self updateBackgroundViewShouldHide:![self itemCountIsZero]]; | ||
} | ||
|
||
- (void)reloadSectionController:(IGListSectionController <IGListSectionType> *)sectionController { | ||
|
@@ -965,6 +982,7 @@ - (void)reloadSectionController:(IGListSectionController <IGListSectionType> *)s | |
|
||
NSIndexSet *sections = [NSIndexSet indexSetWithIndex:section]; | ||
[self.updater reloadCollectionView:collectionView sections:sections]; | ||
[self updateBackgroundViewShouldHide:![self itemCountIsZero]]; | ||
} | ||
|
||
- (void)performBatchAnimated:(BOOL)animated updates:(void (^)())updates completion:(void (^)(BOOL))completion { | ||
|
@@ -978,7 +996,12 @@ - (void)performBatchAnimated:(BOOL)animated updates:(void (^)())updates completi | |
weakSelf.isInUpdateBlock = YES; | ||
updates(); | ||
weakSelf.isInUpdateBlock = NO; | ||
} completion:completion]; | ||
} completion: ^(BOOL finished) { | ||
[weakSelf updateBackgroundViewShouldHide:![weakSelf itemCountIsZero]]; | ||
if (completion) { | ||
completion(finished); | ||
} | ||
}]; | ||
} | ||
|
||
- (void)scrollToSectionController:(IGListSectionController<IGListSectionType> *)sectionController | ||
|
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.
Just for the sake of completion we should add a header for 2.2.0 with a link to the milestone
Also can you add a link to this pull request at the end of your contribution, following the same format as other changelog entries
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.
Sure thing,
CHANGELOG.md
updated.