I am making an attempt to implement SwiftUI’s new .contentTransition(.numericText()) as described in this submit. However I am unable to work out why it really works on a button faucet, however I am unable to get it to work the place I would like, in an .onChange
modifier? 🤔
struct ContentView: View {
@State personal var newNumberForAnimation = 98.0
@State personal var quantity: Double = 99.0
var physique: some View {
VStack {
Textual content("(Int(quantity))")
.font(.system(dimension: 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()
}