mkko / DrawerView

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

Drawer does not change size on pan #7

Closed twiedow closed 3 years ago

twiedow commented 5 years ago

First of all thanks for your great work!

I have a problem when panning the drawer. In your example project the drawer grows and shrinks when panning up or down. In my app nothing happens when I start panning. Only when the panning finishes the drawer opens or collapses.

Do you have an idea what I'm doing wrong?

Here is how I'm adding the drawer:

` boxMapDrawerViewController.view.cornerRadius = 8

    drawerView = addDrawerView(withViewController: boxMapDrawerViewController)
    drawerView?.snapPositions = [.open, .collapsed]
    drawerView?.setPosition(.collapsed, animated: false)
    drawerView?.collapsedHeight = 130
    drawerView?.backgroundEffect = nil
    drawerView?.shadowRadius = 20
    drawerView?.shadowOpacity = 0.25

`

The boxMapDrawerViewController only contains a one simple UIView, I also tried one with a scroll view inside. It does not make a difference adding the drawer in loadView or viewDidLoad.

I can't see what I'm doing different in comparison to your sample app.

Btw, I'm using Xcode 10.2.1, Swift 5 and deployment target is 12.0. Version of DrawerView is 1.1.1.

twiedow commented 5 years ago

I have found the problem. It occurs when the topMargin is changed within viewDidLayoutSubviews. I do this because I want the drawer to stay below some other views.

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        drawerView?.topMargin = goBackButton.frame.maxY + 10
    }

Any suggestions?

mkko commented 5 years ago

Hi @twiedow! Thank you for the compliments.

I can see the issue, the position gets reset when changing topMargin. I don't think there's any reason to re-evaluate the position, so I'll try to see if there's another way.

mkko commented 5 years ago

How would the following work:

    public var topMargin: CGFloat = 68.0 {
        didSet {
            if panGestureRecognizer.state == .ended {
                self.updateSnapPosition(animated: false)
            }
        }
    }

Since the drawer is based on auto layout, dragging will trigger layoutSubviews continuously. When changing topMargin, drawer position needs to be evaluated only if it is in rest. If the above fix works in your case, I'll push a new version with the fix.

mkko commented 5 years ago

@twiedow, I pushed a minor fix into master that ought to fix your issue. The scroll position is not updated if pan is active. Can you check it if it works in your use case?

mkko commented 3 years ago

Please, let me know if this issue is still valid. I'm closing this for now.