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

Fix CollectionView scroll behaviour when section is empty #808

Closed

Conversation

gmoledina
Copy link
Contributor

Changes in this pull request

Issue fixed: When a section is empty (0 cells) but has a header/footer supplementary views, calling scrollToObject:supplementaryKinds:scrollDirection:scrollPosition:animated wouldn't do anything as the method implementation has an early return if the section doesn't have any cells:
screen shot 2017-06-15 at 14 07 18

As the section does have supplementary views and is displayed on screen, there's no reason not to scroll to it. This minor change fixes this detail.

Checklist

Change in internal implementation of one method - all current tests pass. No tests added.

  • 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

@gmoledina
Copy link
Contributor Author

1 Travis check failed, looks like the parameter for the device is wrong : "Unsupported device specifier option.".

Copy link
Contributor

@jessesquires jessesquires left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me 👍 💯

cc @rnystrom

@rnystrom
Copy link
Contributor

@gmoledina awesome! Do you mind adding a unit test to make sure this doesn't regress in the future?

@gmoledina gmoledina force-pushed the fix/scroll_to_empty_section branch from 9f9da15 to 40893dc Compare June 19, 2017 18:42
@facebook-github-bot
Copy link
Contributor

@gmoledina updated the pull request - view changes

@gmoledina
Copy link
Contributor Author

@jessesquires @rnystrom Sure thing ! I've added some simple tests.

While adding the tests, I noticed 2 things :

1- calling [layout layoutAttributesForSupplementaryViewOfKind:supplementaryKind atIndexPath:indexPath]; with supplementaryKind footer for example, returns the frame the footer would have even if the section doesn't have a footer.

2- if we choose UICollectionViewScrollPositionBottom as the position parameter to call the scrollToObject... method, the contentOffset might be a negative number even if the collectionView doesn't have any insets.

For the 1st point, I would ignore it as it's the default UICVFlowLayout behaviour.
But for the 2nd point, I think we need to define the behaviour we'd like to have. Should I create an issue for this point ?

@facebook-github-bot
Copy link
Contributor

@gmoledina updated the pull request - view changes

@facebook-github-bot
Copy link
Contributor

@rnystrom has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@rnystrom has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@gmoledina
Copy link
Contributor Author

gmoledina commented Jul 5, 2017

@rnystrom Let me know if you need more details regarding the 2 points I mentioned in my last comment ! I could write failing tests in a separate branch for point 2.

@rnystrom
Copy link
Contributor

rnystrom commented Jul 6, 2017

@gmoledina good points! Agree let's skip 1 b/c that's flow layout's behavior. I don't want to work around it too much as some people could expect it or it might change.

Let's whip up another issue for 2 though and include some failing unit tests in the issue if you have them on hand.

@rnystrom
Copy link
Contributor

rnystrom commented Jul 6, 2017

@gmoledina quick heads up that the test_whenScrollVerticallyToItemInASectionWithNoCellsAndNoSupplymentaryView test is actually failing both on Travis and internally atm. Mind taking a look?

@jessesquires jessesquires modified the milestone: 3.1.0 Jul 12, 2017
@rnystrom
Copy link
Contributor

rnystrom commented Jul 14, 2017

@gmoledina checking in on this?

@facebook-github-bot
Copy link
Contributor

@gmoledina updated the pull request - view changes - changes since last import

@gmoledina gmoledina force-pushed the fix/scroll_to_empty_section branch from 6595ad7 to c71868a Compare July 18, 2017 15:37
@facebook-github-bot
Copy link
Contributor

@gmoledina updated the pull request - view changes - changes since last import

@gmoledina
Copy link
Contributor Author

@rnystrom Indeed, tests were failing on my side as well - weird. The reason was that collectionView.contentSize.height was smaller then collectionView.frame.size.height and thus no scrolling would occur. I must have changed the array contents last minute as the tests were passing when I wrote them 🤔
PR updated with the fix !
I'll open a new PR for the other issue as well.

@rnystrom
Copy link
Contributor

Hell ya! Going to land this when I'm back from a vacation early next week. That way if something breaks, nobody has to scramble to fix while I'm out. Pumped for this!

@gmoledina
Copy link
Contributor Author

@rnystrom sounds good - enjoy your vacation !

@facebook-github-bot
Copy link
Contributor

@gmoledina updated the pull request - view changes - changes since last import

@facebook-github-bot
Copy link
Contributor

@rnystrom has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@gmoledina gmoledina deleted the fix/scroll_to_empty_section branch August 14, 2017 14:10
@rnystrom
Copy link
Contributor

rnystrom commented Aug 14, 2017

FYI this caused a regression internally b/c calling numberOfItemsInSection: triggers a prepareLayout pass early. I'll work on a unit test that repros this issue and we can retry this PR. Backing it out for now.

@gmoledina gmoledina restored the fix/scroll_to_empty_section branch August 14, 2017 16:21
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.

4 participants