mkko / DrawerView

A drop-in view, to be used as a drawer anywhere in your app
MIT License
373 stars 57 forks source link

childReachedTheTop calculation ignores contentInset #30

Open bingosabi opened 4 years ago

bingosabi commented 4 years ago

I have a DrawerView with a descendent UITableView inside a containerView. That tableview extends under a sibling header view so that the header can be collapsed to reveal more of the tableview on scroll. (Similar to how Apple collapses the Navigation Bar to show more content when you scroll).

To achieve this I set a contentInset for the top of the tableview so content can be fully exposed while the header view is fully expanded.

tableview.contentInset = UIEdgeInset(top:175, left:0, bottom:view.safeAreaInsets.bottom, right:0)

However, DrawerView's handlePan() is not taking the content inset into account when determining if there is more content in the scrollview to be shown

The fix is to change the line 810 in DrawerView:

let childReachedTheTop = activeScrollViews.contains { $0.contentOffset.y <= 0 }

to:

let childReachedTheTop = activeScrollViews.contains { $0.contentOffset.y <= -$0.contentInset.top }

and this also necessitates a change to line 837:

let minContentOffset = activeScrollViews.map { $0.contentOffset.y }.min() ?? 0

to

let minContentOffset = activeScrollViews.map { $0.contentOffset.y + $0.contentInset.top}.min()?? 0

Happy to make a pull request with the fix, but need to take a look at the unit test setup you have first, if it even something you'd want to add a unit test for.

Great component BTW!

mkko commented 4 years ago

Hi! Thank you for the feedback! I must apologize that I haven't had the time to check this any further, but if you have the time, I'd be happy to review the PR. Unit tests are more or less nonexistent, only some utility function(s) are tested as far as I remember.