Am I trippin' or is this animation absolutely not behaving like intended ?

I was trying to fix some animation problem and somehow got down to this weird behavior :
import SwiftUI

struct ContentView: View {
@State private var yPos: Double = 0 // Start with no offset

var body: some View {

HoldCue()
.position(x: 100, y: yPos )
.animation(Animation.linear(duration: 1), value: yPos)
.onAppear {
yPos = 200
}

}
}

struct HoldCue: View {
@State private var size: Double = 20

var body: some View {
ZStack {
Circle()
.frame(width: size, height: size)
.animation(Animation.linear(duration: 1).repeatForever(autoreverses: true), value: size)
.onAppear {
// Start the pulsing animation independently
size = 50
}
}
}
}



#Preview {
ContentView()
}
import SwiftUI

struct ContentView: View {
@State private var yPos: Double = 0 // Start with no offset

var body: some View {

HoldCue()
.position(x: 100, y: yPos )
.animation(Animation.linear(duration: 1), value: yPos)
.onAppear {
yPos = 200
}

}
}

struct HoldCue: View {
@State private var size: Double = 20

var body: some View {
ZStack {
Circle()
.frame(width: size, height: size)
.animation(Animation.linear(duration: 1).repeatForever(autoreverses: true), value: size)
.onAppear {
// Start the pulsing animation independently
size = 50
}
}
}
}



#Preview {
ContentView()
}
I'm probably too tired and missed something obvious but I can't figure why the position animation keeps repeating even though it's not set as repeatForever. I've used the animation(Animation, Value) modifier that is supposed to limit context merge. Try it out and tell me if you get the same result!
Solution:
Ok for those interested I found a workaround : using scaleEffect instead of frame seems to fix the problem Not sure why this works but I guess it has to do with the fact that the view's frame is used to determine its position in the parent view...
Jump to solution
1 Reply
Solution
Zer0
Zer09mo ago
Ok for those interested I found a workaround : using scaleEffect instead of frame seems to fix the problem Not sure why this works but I guess it has to do with the fact that the view's frame is used to determine its position in the parent view
Want results from more Discord servers?
Add your server