For some reason, ToolbarItems are not visible in this code. This worked in Xcode 13. Not sure whether I'm doing something wrong or not? Note that if isFlowDetermined
is initialized to true
, then the "Cancel" button does appear. Any guidance appreciated.
import SwiftUI
struct ContentView: View {
@State private var isFlowDetermined = false
var body: some View {
NavigationView {
//NestedView()
if self.isFlowDetermined {
NestedView()
} else {
ProgressView()
.task {
await self.determineFlow()
}
}
}
}
private func determineFlow() async {
self.isFlowDetermined = true
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct NestedView: View {
var body: some View {
ScrollView {
Text("Is there a Cancel button?")
}
#if !os(macOS)
.navigationBarTitleDisplayMode(.inline)
#endif
.toolbar {
#if !os(macOS)
ToolbarItem(placement: .navigationBarLeading) {
Button("Cancel") {
print("got here")
}
}
#endif
}
}
}