I am attempting to implement SwiftUI’s new .contentTransition(.numericText()) as described in this publish. However I can not determine why it really works on a button faucet, however I can not get it to work the place I want, in an .onChange
modifier? 🤔
struct ContentView: View {
@State non-public var newNumberForAnimation = 98.0
@State non-public var quantity: Double = 99.0
var physique: some View {
VStack {
Textual content("(Int(quantity))")
.font(.system(measurement: 36))
.contentTransition(.numericText())
Button {
//This works when uncommented
//withAnimation {
quantity = .random(in: 90 ..< 100)
//}
} label: {
Textual content("Random")
}
}
//Why does this not work?
.onChange(of: quantity, preliminary: true) { oldNumber, newNumber in
withAnimation {
newNumberForAnimation = newNumber
}
}
}
}
#Preview {
ContentView()
}