I am having a lot of trouble with getting a .sheet() to work and I am beginning to wonder why I want to use one. What are the advantages of .sheet() and .popover() over e.g. changing the zIndex?
I have a search window in my app which popped up and down happily one or two betas ago. Now it pops up and down once. The code I am using works happily when isolated but not in my app. I tried using both the isPresented and item forms but neither were successful. The attached code works though if I have made any errors I would like to know. It is more complex than it needs to be as I was grasping at straws trying to find the problem.
struct ContentView : View {
@State var count = 0
@State var dismisses = 0
var body: some View {
VStack {
Spacer()
ShowButton(count: $count, dismisses: $dismisses)
Spacer()
Text("Shows: \(count), Dismisses:\(dismisses)")
}
}
}
struct ShowButton: View {
@State var show = false
@Binding var count: Int
@Binding var dismisses: Int
var body: some View {
Button(
action: { self.count += 1; self.show = true },
label: { Text("Show sheet") }
)
.sheet(
isPresented: $show,
onDismiss: { self.dismisses += 1 },
content: { Show(text: "Test #\(self.count)") }
)
}
}
struct Show: View {
let text: String
@Environment(\.presentationMode) var mode: Binding<PresentationMode>
var body: some View {
VStack {
Text(text)
Button(
action: {
self.mode.value.dismiss()
},
label: { Text("Dismiss") }
)
}
}
}
This code works as expected, similar code in my app works once.
Are there any good alternatives to sheet()/popover()?