The Slider value doesn't connect to the animation

The State variable that is used for the stiffness.


@State private var stiffnessAmount: CGFloat = 1


The Slider here sets the value, range, and step size.


Slider(value: $stiffnessAmount, in: 1...10, step: 1)

Text with modifier for the animation doesn't change its stiffnessAmount even though the Slider above:


           Text("Look here!")   
         .animation(
                Animation.interpolatingSpring(stiffness: Double(stiffnessAmount), damping: 0)
                    .repeatCount(Int(animationCount), autoreverses: false)
            )


I changed the value using the Slider during runtime and then animation stiffness doesn't change.


Why is it not working?

Could you show the complete code ?

Basically, it is SwiftUI code. Those were the most necessary parts of the code.


As requested, here is the entire ContentView.swift file:


import SwiftUI

struct ContentView: View {
    
    @State private var animationAmount: CGFloat = 1
    @State private var stiffnessAmount: CGFloat = 1
    @State private var animationCount: CGFloat = 1
    
    var body: some View {
        VStack{
            HStack{
                Slider(value: $stiffnessAmount, in: 1...10, step: 1)
                Text("Stiffness: \(stiffnessAmount)")
            }
            HStack{
                Slider(value: $animationCount, in: 1...5, step: 1)
                Text("Animation Count: \(animationCount)")
            }
            Text("Look here!")
            .font(.title)
            .frame(width: 1000, height: 1000, alignment: .center)
            .background(Color.red)
            .foregroundColor(.black)
            .clipShape(Circle())
        .scaleEffect(animationAmount)
            .animation(
                Animation.interpolatingSpring(stiffness: Double(stiffnessAmount), damping: 0)
                    //.repeatForever(autoreverses: false)
                    .repeatCount(Int(animationCount), autoreverses: false)
            )
            .onAppear{
                self.animationAmount = 0.5
            }

        }
    }
}


struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

I played with it. Surprisingly, animation does not stop on count…


I had to reduce size from 1000 downto 100 to see the sliders.

So, do you have any pointers to a solution? Or is there no answer to the question?

Unfortunately, I could not find a solution.


Does animation stop for you or does it go endlessly ?


If so, you could file a bug.

The Slider value doesn't connect to the animation
 
 
Q