I want to implement a text animation in SwiftUI and made a view that boils down to something like this:
public struct AnimatedTextView: View, Animatable {
public var number: CGFloat
public init(number: CGFloat) {
self.number = number
}
public var animatableData: CGFloat {
get { number }
set { number = newValue }
}
public var body: some View {
Text("\(Int(number))")
}
}
This animation works fine in the main app target, but when I move it to a SPM package, the animation breaks:
Has anybody encountered this and knows a workaround?
(Full project to reproduce the issue: https://www.dropbox.com/s/e1yrzszxlgkk0p0/AnimationRepro.zip)
CodePudding user response:
So it seems that the issue is not related to being the code inside the package, but actually to the iOS version.
I have dropped your app's iOS Deployment Target to iOS 14, and the animation appears to be broken in the App module as well. Then, I bumped it again to iOS 15, and also updated the package's Package.swift
to have a minimum of iOS 15 and animation did work great on both. (Make sure to clean build the project after updating the minimum version)
So it seems that the increment/decrement animation is something new in iOS 15. You might need to bump up the minimum version for the whole app (package included), or implement a custom animation with the same behaviour if lower versions are required.