I have a view
struct CellView: View { @Binding var color: Int @State var padding : Length = 10 let colors = [Color.yellow, Color.red, Color.blue, Color.green] var body: some View { colors[color] .cornerRadius(20) .padding(padding) .animation(.spring()) } } And I want it to have padding animation when property color changes. I want to animate padding from 10 to 0.
I've tried to use onAppear
...onAppear { self.padding = 0 } But it work only once when view appears(as intended), and I want to do this each time when property color changes. Basically, each time color property changes, I want to animate padding from 10 to 0. Could you please tell if there is a way to do this?