Could you not use two separate state variables?
This code works:
struct ContentView: View {
@State private var value: Int = 0
@State private var trigger = 0
var body: some View {
VStack {
GeometryReader { geometry in
Text("\(value)")
.phaseAnimator([0, 1], trigger: trigger) { view, phase in
view
.offset(x: phase == 1 ? 100 : 0)
} animation: { phase in
switch phase {
case 1:
.linear(duration: 1)
default:
nil
}
}
}
Button("Start Animation") {
withAnimation {
trigger += 1
} completion: {
value += 1
}
}
}
}
}
The trigger property is for triggering the animation.
The value property only gets updated when the animation is complete, i.e. on the "snap back".
This way the trigger and what is shown in the view cannot interfere with each other. It also ensures the text value can be updated after the animation, not before, like you said you wanted.
If this solution is something you're not looking for, or there is more surrounding this problem, then I am still here to help. Just let me know.
Topic:
UI Frameworks
SubTopic:
SwiftUI