@@ -7,7 +7,7 @@ import FloatingPanel
77
88private var AssociatedDelegateHandle : UInt8 = 0
99
10- @objc public class DateBottomSheetController : NSObject , FloatingPanelControllerDelegate {
10+ @objc public class DateBottomSheetController : NSObject {
1111
1212 private weak var controller : FloatingPanelController ?
1313 private var onDismiss : ( ( Bool ) -> Void ) ?
@@ -41,9 +41,8 @@ private var AssociatedDelegateHandle: UInt8 = 0
4141 fpc. backdropView. backgroundColor = UIColor . black
4242 fpc. isRemovalInteractionEnabled = true
4343 fpc. surfaceView. grabberHandle. isHidden = true
44- fpc. surfaceView. grabberHandleHeight = 0
45- fpc. surfaceView. grabberTopPadding = 0
46- fpc. surfaceView. contentInsets = . zero
44+ fpc. surfaceView. grabberHandleSize. height = 0
45+ fpc. surfaceView. grabberHandlePadding = 0
4746
4847 controller = fpc
4948 self . onDismiss = onDismiss
@@ -68,12 +67,12 @@ class FloatingDelegate: FloatingPanelControllerDelegate {
6867 self . onDismiss = onDismiss
6968 }
7069
71- func floatingPanel( _ vc: FloatingPanelController , layoutFor newCollection: UITraitCollection ) -> FloatingPanelLayout ? {
70+ func floatingPanel( _ vc: FloatingPanelController , layoutFor newCollection: UITraitCollection ) -> FloatingPanelLayout {
7271 return floatingLayout
7372 }
7473
7574 func floatingPanelDidEndDecelerating( _ vc: FloatingPanelController ) {
76- if vc. position == . hidden {
75+ if vc. state == . hidden {
7776 vc. removePanelFromParent ( animated: true )
7877 vc. dismiss ( animated: false , completion: nil )
7978 onDismiss ( false )
@@ -86,26 +85,34 @@ class FloatingDelegate: FloatingPanelControllerDelegate {
8685}
8786
8887class BottomSheetLayout : FloatingPanelLayout {
89- var initialPosition : FloatingPanelPosition = . half
90-
91- private let preferredHeight : CGFloat
92-
93- init ( preferredHeight: CGFloat ) {
94- self . preferredHeight = preferredHeight
95- }
96-
97- func insetFor( position: FloatingPanelPosition ) -> CGFloat ? {
98- switch ( position) {
99- case . half: return preferredHeight
100- case . full: return 0
101- case . tip: return 0
102- case . hidden: return 0
88+ private let preferredHeight : CGFloat
89+
90+ var position : FloatingPanelPosition {
91+ return . bottom
92+ }
93+
94+ var initialState : FloatingPanelState {
95+ return . half
96+ }
97+
98+ var anchors : [ FloatingPanelState : FloatingPanelLayoutAnchoring ] {
99+ return [
100+ . half: FloatingPanelLayoutAnchor ( absoluteInset: preferredHeight, edge: . bottom, referenceGuide: . safeArea)
101+ ]
102+ }
103+
104+ init ( preferredHeight: CGFloat ) {
105+ self . preferredHeight = preferredHeight
106+ }
107+
108+ func prepareLayout( surfaceView: UIView , in view: UIView ) -> [ NSLayoutConstraint ] {
109+ return [
110+ surfaceView. leftAnchor. constraint ( equalTo: view. safeAreaLayoutGuide. leftAnchor, constant: 0.0 ) ,
111+ surfaceView. rightAnchor. constraint ( equalTo: view. safeAreaLayoutGuide. rightAnchor, constant: 0.0 ) ,
112+ ]
113+ }
114+
115+ func backdropAlpha( for state: FloatingPanelState ) -> CGFloat {
116+ return 0.3
103117 }
104- }
105-
106- var supportedPositions : Set < FloatingPanelPosition > = [ . half, . hidden]
107-
108- func backdropAlphaFor( position: FloatingPanelPosition ) -> CGFloat {
109- return 0.3
110- }
111118}
0 commit comments