I have a situation that I have to update a child view within a view that is under an onging transition.
Here is a simple code to reproduce/demonstrate the issue I just mentioned.
struct ContentView: View {
@State var text = "\(Date().timeIntervalSince1970)"
@State var isOn = true
var body: some View {
ZStack {
VStack {
if isOn {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text(text)
.transition(.move(edge: .bottom))
}
}
.zIndex(1)
.animation(.default, value: isOn)
Color.clear
.ignoresSafeArea()
.overlay(alignment: .bottom) {
Button("Click") {
isOn.toggle()
text = isOn ? "\(Date().timeIntervalSince1970)" : "Hello, Swift!"
}
}
}
}
}
In the above code, I have a Text
which will be hidden/shown by clicking the bottom button. And update the text to a different value when it shows up next time.
If I click the button quickly, which means the text is updated before the transition finished. Then the text loses the transition and shows up directly at the "final" position.

How to updating a child view during transition? Or there is a limitation on SwiftUI for now?