FloatingPanel icon indicating copy to clipboard operation
FloatingPanel copied to clipboard

Allow animated FloatingPanelController relayout

Open groue opened this issue 6 years ago • 5 comments

Hello,

This PR introduces two new methods on FloatingPanelController: beginUpdateLayout(), and endUpdateLayout(). They extend the existing updateLayout() method, and allow applications to transition from one set of constraints to another without facing undesired "Unable to simultaneously satisfy constraints" errors.

My understanding is that those errors happen when the parent controller of the panel wants to change height, because of conflicts with the hard FloatingPanelLayoutAdapter.heightConstraint.

For example, this happens when the panel is embedded in a view controller which is not always fullscreen.

This PR lets the host application play a three-steps game:

  1. Remove the hard FloatingPanelLayoutAdapter.heightConstraint constraint.
  2. Perform custom relayout, without error.
  3. Reset the floating panel layout with an updated FloatingPanelLayoutAdapter.heightConstraint.

Usage:

func updateLayoutOfPanelParent() {
    // 1. Begin panel update
    self.panel.beginUpdateLayout()
    
    UIView.animate(withDuration: 0.25, animations: {
        // 2. Update layout of panel's parent
        ...
        // 3. End panel update
        self.panel.endUpdateLayout()
    })
}

This PR may also address #160, but I'm not sure.

groue avatar May 21 '19 08:05 groue

They extend the existing updateLayout() method, and allow applications to transition from one set of constraints to another without facing undesired "Unable to simultaneously satisfy constraints" errors.

Sounds great! I will check this more detail later.

scenee avatar Jun 01 '19 14:06 scenee

Hello @SCENEE. The pull request has been updated with the most recent changes from version 1.6.0.

groue avatar Jun 06 '19 08:06 groue

Please tell me if you'd like some tests to be added, or if you wonder how to trigger the constraint issues that this PR is solving.

groue avatar Jun 06 '19 08:06 groue

you wonder how to trigger the constraint issues that this PR is solving.

Yes, I would! And could you please check we're able to use the new APIs like this?

func updateLayoutOfPanelParent() {
    UIView.animate(withDuration: 0.25, animations: {
        // 1. Begin panel update
	self.panel.beginUpdateLayout()
        // 2. Update layout of panel’s parent
        …
        // 3. End panel update
        self.panel.endUpdateLayout()
    })
}

scenee avatar Jun 06 '19 23:06 scenee

Sure, @SCENEE, I will 👍

groue avatar Jun 07 '19 08:06 groue