Cannot use autolayout and safe area with FloatingPanelIntrinsicLayoutAnchor properly
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
Have the same problem. I see from readme that this FloatingPanelIntrinsicLayoutAnchor is deprecated. Is there an alternative way of providing the same behaviour?
Have you tried with FloatingPanelAdaptiveLayoutAnchor?
Yeah I actually did and it worked out in the end for me