Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
I attempt to swap from one display screen to a different by urgent a button (see full code under). The swap from the primary view to the second view (and vice versa) works, however no animation is going down.
Why does this conduct occur?
Full code:
struct ContentView: View {
@AppStorage("firstViewActive") var isFirstViewActive: Bool = true
var physique: some View {
if isFirstViewActive {
FirstView()
} else {
SecondView()
}
}
}
struct FirstView: View {
@AppStorage("firstViewActive") var isFirstViewActive: Bool = true
var physique: some View {
ZStack {
Coloration(.crimson).ignoresSafeArea(.all, edges: .all)
VStack {
Spacer()
Textual content("That is the primary view")
Spacer()
Button {
withAnimation {
isFirstViewActive = false
}
} label: {
Textual content("Go to second view")
}
Spacer()
}
}
}
}
struct SecondView: View {
@AppStorage("firstViewActive") var isFirstViewActive: Bool = false
var physique: some View {
ZStack {
Coloration(.blue).ignoresSafeArea(.all, edges: .all)
VStack {
Spacer()
Textual content("That is the second view")
Spacer()
Button {
withAnimation {
isFirstViewActive = true
}
} label: {
Textual content("Go to first view")
}
Spacer()
}
}
}
}