The code below renders a view with a navigation bar. A plus button is placed on the navigation bar which opens a sheet. After closing this sheet view programmatically the plus button of the first view won't react anymore. Is this an iOS bug or is the code incorrect?
import SwiftUI
struct ContentView: View {
@State var isAddPresented = false
var body: some View {
NavigationView {
Text("Tap plus to add item")
.navigationBarTitle("Main Screen Title")
.navigationBarItems(trailing:
Button(action: {
self.isAddPresented = true
}) {
Image(systemName: "plus")
}
)
.sheet(isPresented: $isAddPresented,
onDismiss: {
self.isAddPresented = false
}) {
NavigationView {
Text("Tap on save")
.navigationBarTitle("Add something")
.navigationBarItems(leading: Button(action: {self.isAddPresented = false}, label: {Text("Save")}))
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}