- Xcode 12 beta 6 (12A8189n)
- iPhone 11, iOS 14.0 Simulator
In the given code example the presentation of CreateSomethingView works, however dismissing it does not work. I'm especially interested in making this one work using @StateObject and avoiding @State entirely.
import SwiftUI
@main
struct ModalPresentationApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
final class ContentModel: ObservableObject {
@Published
var isPresenting = false
}
struct ContentView: View {
@StateObject
var contentModel = ContentModel()
var body: some View {
NavigationView {
Text("ContentView")
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
contentModel.isPresenting.toggle()
}, label: {
Image(systemName: "plus.circle")
})
.sheet(isPresented: $contentModel.isPresenting) {
CreateSomethingView(isPresented: $contentModel.isPresenting)
}
}
}
}
}
}
struct CreateSomethingView: View {
@Binding
var isPresented: Bool
var body: some View {
NavigationView {
Text("CreateSomethingView")
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button(action: {
isPresented = false
}, label: {
Image(systemName: "xmark.circle.fill")
})
}
}
}
}
}