@@ -15,6 +15,7 @@ struct MainView: View {
1515 @State private var panelLayout : FloatingPanelLayout ? = MyFloatingPanelLayout ( )
1616 @State private var panelState : FloatingPanelState ?
1717 @State private var selectedContent : CardContent = . list
18+ @State private var lastEvent : MyPanelCoordinator . Event ?
1819
1920 var body : some View {
2021 ZStack {
@@ -28,6 +29,9 @@ struct MainView: View {
2829 }
2930 }
3031 . pickerStyle ( . segmented)
32+
33+ Text ( " Last event: \( lastEvent? . rawValue ?? " None " ) " )
34+
3135 Button ( " Move to full " ) {
3236 withAnimation ( . interactiveSpring) {
3337 panelState = . full
@@ -52,7 +56,8 @@ struct MainView: View {
5256 }
5357 }
5458 . floatingPanel (
55- coordinator: MyPanelCoordinator . self
59+ coordinator: MyPanelCoordinator . self,
60+ onEvent: onEvent
5661 ) { proxy in
5762 switch selectedContent {
5863 case . list:
@@ -80,11 +85,18 @@ struct MainView: View {
8085 Logger ( ) . debug ( " Panel state changed: \( newValue ?? . hidden) " )
8186 }
8287 }
88+
89+ func onEvent( _ event: MyPanelCoordinator . Event ) {
90+ lastEvent = event
91+ }
8392}
8493
8594// A custom coordinator object which handles panel context updates and setting up `FloatingPanelControllerDelegate` methods
8695class MyPanelCoordinator : FloatingPanelCoordinator {
87- enum Event { }
96+ enum Event : String {
97+ case willBeginDragging
98+ case didEndAttracting
99+ }
88100
89101 let action : ( Event ) -> Void
90102 let proxy : FloatingPanelProxy
@@ -115,6 +127,14 @@ class MyPanelCoordinator: FloatingPanelCoordinator {
115127}
116128
117129extension MyPanelCoordinator : FloatingPanelControllerDelegate {
130+ func floatingPanelWillBeginDragging( _ fpc: FloatingPanelController ) {
131+ action ( . willBeginDragging)
132+ }
133+
134+ func floatingPanelDidEndAttracting( _ fpc: FloatingPanelController ) {
135+ action ( . didEndAttracting)
136+ }
137+
118138 func floatingPanelDidChangeState( _ fpc: FloatingPanelController ) {
119139 // NOTE: This timing is difference from one of the change of the binding value
120140 // to `floatingPanelState(_:)` modifier
0 commit comments