ios – SwiftUI Kind: Sheet is not dismissed mechanically when the view it is hooked up to is gone


See the code under (BTW, Record has the identical subject):

enum Worth: String, Equatable {
    case a = "a"
    case b = "b"
}

struct ContentView: View {
    @State var worth: Worth = .a
    @State var showSheet = false

    var physique: some View {
        Kind {
            Part {
                change worth {
                case .a:
                    Textual content("a")
                        .onTapGesture {
                            showSheet = true
                        }
                        .sheet(isPresented: $showSheet) {
                            Button("Set Worth to .b") {
                                worth = .b
                            }
                        }
                case .b:
                    Textual content("b")
                }
            }
        }
    }
}

To breed the difficulty, first click on on textual content ‘a’ to deliver up a sheet, then click on on button within the sheet to vary worth. I would anticipate the sheet ought to be dismissed mechanically, as a result of the view it is hooked up to is gone. But it surely is not.

If I take away the Kind, or exchange it with, say, ScrollView, the habits is as I anticipated. On different different hand, nevertheless, changing it with Record has the identical subject (sheet is not dismissed).

I am pondering to file a FB, however wish to ask right here first. Does anybody know if it is a bug or a function? If it is a function, what is the rationale behind it?

I am at present utilizing this workaround. Another ideas aside from calling dismiss() in button handler are appreciated.

    .onChange(of: worth) { _ in
            showSheet = false
        }

Leave a Reply