I was working on a more complicated screen with a lots of data and I noticed weird behavior when edit mode is embedded in navigation view.
Following example work as intended - which means text changes between editing and not editing. However when embedded in navigation view, the behavior changes (text remains the same) both in previews and on simulator. Whether the if-else is hooked to editMode itself or to .isEditing does not matter.
Can anyone refer me to resources that would explain why? What am I missing
import SwiftUI
struct ContentView: View {
@Environment(\.editMode) var editMode
var body: some View {
VStack {
HStack {
Spacer()
EditButton()
}
Spacer()
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
if editMode?.wrappedValue == .inactive {
Text("Not editing")
} else {
Text("Editing")
}
Spacer()
}
.padding()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
NavigationView { // if removed, the text will change
ContentView()
}
} // NavigationView end
}