Skip to content

Commit

Permalink
Fix a regression for the backdrop behavior (#466,#471)
Browse files Browse the repository at this point in the history
The backdrop alpha of a panel must be updated only in `Controller.show(animated:completion:)`.
Because that prevents a backdrop flicking just before presenting a panel.

Resolve #466.
  • Loading branch information
scenee authored Jun 5, 2021
1 parent 895790f commit 9c45c31
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
16 changes: 2 additions & 14 deletions Sources/Controller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -398,20 +398,8 @@ open class FloatingPanelController: UIViewController {
}

private func activateLayout(forceLayout: Bool = false) {
floatingPanel.layoutAdapter.prepareLayout()

// preserve the current content offset if contentInsetAdjustmentBehavior is `.always`
var contentOffset: CGPoint?
if contentInsetAdjustmentBehavior == .always {
contentOffset = trackingScrollView?.contentOffset
}

floatingPanel.layoutAdapter.updateStaticConstraint()
floatingPanel.layoutAdapter.activateLayout(for: floatingPanel.state, forceLayout: forceLayout)

if let contentOffset = contentOffset {
trackingScrollView?.contentOffset = contentOffset
}
floatingPanel.activateLayout(forceLayout: forceLayout,
contentInsetAdjustmentBehavior: contentInsetAdjustmentBehavior)
}

func remove() {
Expand Down
24 changes: 24 additions & 0 deletions Sources/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,30 @@ class Core: NSObject, UIGestureRecognizerDelegate {

// MARK: - Layout update

func activateLayout(forceLayout: Bool = false,
contentInsetAdjustmentBehavior: FloatingPanelController.ContentInsetAdjustmentBehavior) {
layoutAdapter.prepareLayout()

// preserve the current content offset if contentInsetAdjustmentBehavior is `.always`
var contentOffset: CGPoint?
if contentInsetAdjustmentBehavior == .always {
contentOffset = scrollView?.contentOffset
}

layoutAdapter.updateStaticConstraint()
layoutAdapter.activateLayout(for: state, forceLayout: true)

// Update the backdrop alpha only when called in `Controller.show(animated:completion:)`
// Because that prevents a backdrop flicking just before presenting a panel(#466).
if forceLayout {
backdropView.alpha = getBackdropAlpha(for: state)
}

if let contentOffset = contentOffset {
scrollView?.contentOffset = contentOffset
}
}

private func updateLayout(to target: FloatingPanelState) {
self.layoutAdapter.activateLayout(for: target, forceLayout: true)
self.backdropView.alpha = self.getBackdropAlpha(for: target)
Expand Down

0 comments on commit 9c45c31

Please sign in to comment.