I found a solution
import PlaygroundSupport
import SwiftUI
struct SheetView: View {
@Binding var content: String?
init(_ content: Binding<String?>) {
_content = content
}
var body: some View {
Text(content!)
}
}
struct ContentView: View {
@State private var isPresented = false
@State private var content: String?
@State private var startTask = false
var body: some View {
Text("Tap me")
.onTapGesture {
startTask = true
}
.frame(width: 500.0, height: 500.0)
.task(id: startTask) {
guard startTask else {
// startTask = false // <===== Crashes if removed
content = "Some message"
isPresented = true
}
.sheet(isPresented: $isPresented) {
SheetView($content)
}
}
}
let view = ContentView()
PlaygroundPage.current.setLiveView(view)
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: