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

Content size awareness #102

Open
ilyapuchka opened this issue Apr 30, 2019 · 1 comment
Open

Content size awareness #102

ilyapuchka opened this issue Apr 30, 2019 · 1 comment

Comments

@ilyapuchka
Copy link
Contributor

ilyapuchka commented Apr 30, 2019

Similarly to the issues described in #101 there seems to be no good way to consider content size of the view presented in the drawer for it's partially expanded state (as well as for fully expanded).
I've tried to solve that by adopting DrawerPresentable and return the content size from its heightOfPartiallyExpandedDrawer like this:

extension DrawerMapPlaceDetailsViewController: DrawerPresentable, DrawerAnimationParticipant {
    public var heightOfPartiallyExpandedDrawer: CGFloat {
        return self.tableView.contentSize.height + (view.window?.safeAreaInsets.bottom ?? 0)
    }
}

This seems to work visually without issues but internally the state of the drawer changes and it is not in the partially expanded state because during transition the value returned by this method changes from 0 to final value (for some reason it changes one more time adding 4 pixels, but that's probably for reasons unrelated to DrawerKit) and as a result drawer is in the transitioning state, which breaks interactions with background view a they are only considering "final" states (collapsed, partially expanded and fully expanded).
One fix for that might be to consider transition state while detecting touches, but that does not seem like a solution of underlying problem.

@ilyapuchka
Copy link
Contributor Author

ilyapuchka commented May 1, 2019

I managed to solve this issue in following steps:

  • pre-calculate the content size when creating the view controller (Bento allows to do that using it's Box type) using initial content
  • observing changes in the content to recalculate the size
  • return calculated content size value from heightOfPartiallyExpandedDrawer property of the view controller
  • observe changes of the content size and on each change call drawerPresentationController?.setDrawerState(.partiallyExpanded) to update the state of the drawer and force it to recalculate its geometry based on the new content size

While it works and seems a sensible approach (even though it might be not optimal to calculate size additionally every time content changes) it still would be nice to have a support for that kind of behaviour out of the box, also for fully expanded state, as this approach only works for partially expanded state.

Update: making the same approach to work for fully expanded behaviour is much more tricky and is not possible without DrawerKit changing to allow mutating drawer configuration on the presentation controller, or changing the expanded behaviour from being fixed in the configuration to being computed the same way as partially expanded height (implemented with #103)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant