FloatingPanel icon indicating copy to clipboard operation
FloatingPanel copied to clipboard

Cannot use autolayout and safe area with FloatingPanelIntrinsicLayoutAnchor properly

Open chilimovpasha opened this issue 4 years ago • 6 comments

Description

I want to show simple panel which height will depend on content height and want to use autolayout and save safe area insets.

Expected behavior

The panel is showing with height based on content layouted by constrained, panel's moves by gestures do not shift the content, and all insets ara used.

Actual behavior

When I setup constraint to safe area the panel behavior becomes strange - content inside shifting and floating by itself. Or I cant save safe area properly.

Steps to reproduce

Code example that reproduces the issue

This is the func from my service which embed a view controller to floating panel.

    func makeFloatingPanel(
        _ contentViewController: UIViewController,
        configuration: FloatingPanelConfiguration = .default) -> UIViewController
    {
        let floatingPanelController = FloatingPanelController()
        
        floatingPanelController.isRemovalInteractionEnabled = configuration.dismissOnBackgroundTap
        floatingPanelController.backdropView.dismissalTapGestureRecognizer.isEnabled = configuration.dismissOnBackgroundTap
        
        let bottomPadding = UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0
        floatingPanelController.surfaceView.contentPadding = .init(
            top: configuration.additionalContentPadding.top,
            left: configuration.additionalContentPadding.left,
            bottom: bottomPadding + configuration.additionalContentPadding.bottom,
            right: configuration.additionalContentPadding.right
        )
        
        floatingPanelController.set(contentViewController: contentViewController)
        floatingPanelController.layout = CustomFloatingPanelLayout()
        
        let appearance = SurfaceAppearance()
        appearance.cornerRadius = configuration.cornerRadius
        floatingPanelController.surfaceView.appearance = appearance
        
        return floatingPanelController
    }

The CustomFloatingPanelLayout

final class CustomFloatingPanelLayout: FloatingPanelLayout {
    
    // MARK: - FloatingPanelLayout
    let position: FloatingPanelPosition
    let initialState: FloatingPanelState
    
    var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] {
        [.full: FloatingPanelIntrinsicLayoutAnchor(absoluteOffset: 0)]
    }
    
    // MARK: - Init
    init(position: FloatingPanelPosition = .bottom, initialState: FloatingPanelState = .full) {
        self.position = position
        self.initialState = initialState
    }
    
}

How do you display panel(s)?

  • Present modally

How many panels do you displays?

  • 1

Environment

Library version

2.3.1

Installation method

  • CocoaPods

iOS version(s)

14.5.1

Xcode version

12.5

chilimovpasha avatar Jun 02 '21 16:06 chilimovpasha

Have the same problem. I see from readme that this FloatingPanelIntrinsicLayoutAnchor is deprecated. Is there an alternative way of providing the same behaviour?

armanarutiunov avatar Aug 10 '21 17:08 armanarutiunov

Have you tried with FloatingPanelAdaptiveLayoutAnchor?

warpling avatar Oct 13 '21 17:10 warpling

Yeah I actually did and it worked out in the end for me

armanarutiunov avatar Oct 14 '21 09:10 armanarutiunov