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

Show header when section item is empty #1129

Conversation

marcuswu0814
Copy link
Contributor

@marcuswu0814 marcuswu0814 commented Mar 18, 2018

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?

const CGRect headerBounds = (self.scrollDirection == UICollectionViewScrollDirectionVertical) ?
                CGRectMake(insets.left,
                        (itemCount == 0) ? CGRectGetMaxY(rollingSectionBounds) : CGRectGetMinY(rollingSectionBounds) - headerSize.height,
                        paddedLengthInFixedDirection,
                        headerSize.height) :
                CGRectMake((itemCount == 0) ? CGRectGetMaxX(rollingSectionBounds) : CGRectGetMinX(rollingSectionBounds) - headerSize.width,
                        insets.top,
                        headerSize.width,
                        paddedLengthInFixedDirection);

Checklist

  • All tests pass. Demo project builds and runs.
  • I added tests, an experiment, or detailed why my change isn't tested.
  • I added an entry to the CHANGELOG.md for any breaking changes, enhancements, or bug fixes.
  • I have reviewed the contributing guide

@facebook-github-bot
Copy link
Contributor

@marcuswu0814 has updated the pull request. View: changes

@marcuswu0814 marcuswu0814 changed the title Show header when section item empty Show header when section item is empty Mar 18, 2018
- (instancetype)initWithStickyHeaders:(BOOL)stickyHeaders
showHeaderWhenEmpty:(BOOL)showHeaderWhenEmpty
topContentInset:(CGFloat)topContentInset
stretchToEdge:(BOOL)stretchToEdge;
Copy link
Contributor

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!

Copy link
Contributor Author

@marcuswu0814 marcuswu0814 Mar 22, 2018

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);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️ tests!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😄

insets.top,
headerSize.width,
paddedLengthInFixedDirection);

_sectionData[section].headerBounds = headerBounds;


if (itemCount == 0) {
Copy link
Contributor

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;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. 👍

const CGRect headerBounds = (self.scrollDirection == UICollectionViewScrollDirectionVertical) ?
CGRectMake(insets.left,
CGRectGetMinY(rollingSectionBounds) - headerSize.height,
(itemCount == 0) ? CGRectGetMaxY(rollingSectionBounds) : CGRectGetMinY(rollingSectionBounds) - headerSize.height,
Copy link
Contributor

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?

Copy link
Contributor Author

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
@facebook-github-bot
Copy link
Contributor

@marcuswu0814 has updated the pull request. View: changes

Keep the `rollingSectionBounds` and `headerBounds` original behavior.
Adding condition `itemsEmpty && self.showHeaderWhenEmpty` to do my job.
@facebook-github-bot
Copy link
Contributor

@marcuswu0814 has updated the pull request. View: changes

@marcuswu0814
Copy link
Contributor Author

marcuswu0814 commented Mar 22, 2018

I think the bug is not cause by my change.

The following demo is using this project.

In branch IG/release

Before any thing change, used release version install by current pod latest version:
ig release

Both header and footer had some bug.

In branch IG/master

ig master

The footer work well, maybe fixed it #1094, but header got some bug like release version.

In my change, branch marcuswu0814/feature

marcus0814 feature

If set property showHeaderWhenEmpty to NO and the header position will getting wrong.

So, In current master branch, if section item is empty and using sticky header, sticky header position will getting some bugs.

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
@facebook-github-bot
Copy link
Contributor

@marcuswu0814 has updated the pull request. View: changes

@marcuswu0814
Copy link
Contributor Author

marcuswu0814 commented Mar 22, 2018

I fixed this bug on my branch latest commit, and the old test case didn't cover this bug, I already modified the test case and pass it. Now, avoid this bug! 😎

bugfix

Need open another issue to track this?
And if having any new issue, feel free to tell me, thanks. 😅

@facebook-github-bot
Copy link
Contributor

@marcuswu0814 has updated the pull request. View: changes

@marcuswu0814
Copy link
Contributor Author

Hi @rnystrom, will this possible be merged in 3.3.0 release?

@facebook-github-bot
Copy link
Contributor

@marcuswu0814 has updated the pull request. View: changes

@facebook-github-bot
Copy link
Contributor

@marcuswu0814 has updated the pull request. View: changes

@rnystrom rnystrom added this to the 3.3.0 milestone Mar 27, 2018
@facebook-github-bot
Copy link
Contributor

@marcuswu0814 has updated the pull request. View: changes

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

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.

Section is invisible when numberOfItems is 0
3 participants