ColorPicker on sheet taps outside

250 Views Asked by At

I have a problem with SwiftUI and the ColorPicker, only for iPad. On iPhone and Mac it works fine.

When I use a ColorPicker inside a sheet, I open the picker to choose the color and I click (without closing the picker) the button to close the sheet, the button is clicked, but the dismiss() is done on the picker and not on the sheet.

The problem is that once the picker is closed, the dismiss stops working on the sheet and I can't close it with the button, but by clicking outside of it.

I attach the code of the example, simplified to the maximum. The behavior in my app is exactly the same.

@available(iOS 16.0, *)
struct Pruebas: View {
    
    @State private var showSheet: Bool = false
    
    var body: some View {
        
        Button("Show") {
            showSheet.toggle()
        }
        .sheet(isPresented: $showSheet) {
            Detail()
        }
    }
}

@available(iOS 16.0, *)
struct Detail: View {
    
    @Environment(\.dismiss) var dismiss
    
    @State private var color: Color = .orange
    
    var body: some View {
        
        NavigationStack {
            VStack {
                ColorPicker("Color", selection: $color)
                    .padding()
            }
            .navigationTitle("Color")
            
            .toolbar {
                Button("Cancel") {
                    dismiss()
                }
            }
        }
    }
}

Thanks in advance!

0

There are 0 best solutions below