arcgis-maps-sdk-swift-toolkit icon indicating copy to clipboard operation
arcgis-maps-sdk-swift-toolkit copied to clipboard

Can FloatingPanel work with DismissAction?

Open rolson opened this issue 5 months ago • 0 comments
trafficstars

Using the PopupView I have to write code like this when I show the PopupView in a sheet because the only way to integrate with the close button in the popup view is through the isPresented binding. It would be good if the PopupView could take the binding and update it, but also call the dismiss action on the environment. That would simplify the code and pattern for working with the PopupView in system views. The reason we can't do that right now is because the floating panel doesn't work with the environment's dismiss action.

struct EpicPopupView: View {
    let popup: Popup
    let isEditing: Binding<Bool>?
    @State var isPresented = true
    @Environment(\.dismiss) private var dismiss
    
    var body: some View {
        PopupView(popup: popup, isPresented: $isPresented)
            .toolbar {
                if isEditable, let isEditing {
                    ToolbarItem(placement: .topBarTrailing) {
                        Button {
                            isEditing.wrappedValue = true
                        } label: {
                            Text("Edit")
                        }
                    }
                }
                ToolbarItem(placement: .topBarLeading) {
                    DismissButton(kind: .text)
                }
            }
            .onChange(of: isPresented) {
                if !isPresented {
                    dismiss()
                }
            }
    }
    
    var isEditable: Bool {
        popup.geoElement.isAttributesEditable
    }
}

rolson avatar Jun 13 '25 20:06 rolson