-
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
Show header when section item is empty #1129
Show header when section item is empty #1129
Conversation
For making a layout that can still show sticky header when data is empty
@marcuswu0814 has updated the pull request. View: changes |
Source/IGListCollectionViewLayout.h
Outdated
- (instancetype)initWithStickyHeaders:(BOOL)stickyHeaders | ||
showHeaderWhenEmpty:(BOOL)showHeaderWhenEmpty | ||
topContentInset:(CGFloat)topContentInset | ||
stretchToEdge:(BOOL)stretchToEdge; |
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.
Could we actually just include this as a mutable @property BOOL showHeaderWhenEmpty
? Trying to prevent some initializer creep here, ha!
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, I will rolling it back and extract the property showHeaderWhenEmpty
to public.
|
||
IGAssertEqualFrame([self headerForSection:0].frame, 0, 0, 0, 0); | ||
IGAssertEqualFrame([self headerForSection:1].frame, 0, 0, 0, 0); | ||
} |
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.
❤️ tests!
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.
😄
Source/IGListCollectionViewLayout.mm
Outdated
insets.top, | ||
headerSize.width, | ||
paddedLengthInFixedDirection); | ||
|
||
_sectionData[section].headerBounds = headerBounds; | ||
|
||
|
||
if (itemCount == 0) { |
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.
Could we capture itemCount == 0
in a variable?
const BOOL itemsEmpty = itemCount == 0;
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. 👍
Source/IGListCollectionViewLayout.mm
Outdated
const CGRect headerBounds = (self.scrollDirection == UICollectionViewScrollDirectionVertical) ? | ||
CGRectMake(insets.left, | ||
CGRectGetMinY(rollingSectionBounds) - headerSize.height, | ||
(itemCount == 0) ? CGRectGetMaxY(rollingSectionBounds) : CGRectGetMinY(rollingSectionBounds) - headerSize.height, |
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.
What happens if itemCount == 0
but showHeaderWhenEmpty
is 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.
When I trying this, found another bug and note it below.
1. Extract the property to public, remove initializer 2. Capture condition `itemCount == 0` to const var. 3. Modified the test case from using initializer setup to using property
@marcuswu0814 has updated the pull request. View: changes |
Keep the `rollingSectionBounds` and `headerBounds` original behavior. Adding condition `itemsEmpty && self.showHeaderWhenEmpty` to do my job.
@marcuswu0814 has updated the pull request. View: changes |
I think the bug is not cause by my change. The following demo is using this project. In branch
|
In previous version, the test didn't cover this specail case: Three sections, 0 and 2 had itmes and header, 1's items is empty. In this case, the header postion will be wrong. Change this test case for cover it.
…other section's header postion be wrong bugs
@marcuswu0814 has updated the pull request. View: changes |
@marcuswu0814 has updated the pull request. View: changes |
Hi @rnystrom, will this possible be merged in 3.3.0 release? |
@marcuswu0814 has updated the pull request. View: changes |
@marcuswu0814 has updated the pull request. View: changes |
@marcuswu0814 has updated the pull request. View: changes |
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.
@rnystrom is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Changes in this pull request
Issue fixed: #1117
I adding a new constructor for making a
IGListCollectionViewLayout
instance that can always show sticky header although section data is empty.It's working well and this is demo project.
But I'm not sure is any good way to let this much more readability. Is there any good advice?
Checklist
CHANGELOG.md
for any breaking changes, enhancements, or bug fixes.