Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.animation is deprecated in iOS15 #32

Open
transat opened this issue Oct 31, 2021 · 1 comment
Open

.animation is deprecated in iOS15 #32

transat opened this issue Oct 31, 2021 · 1 comment

Comments

@transat
Copy link
Contributor

transat commented Oct 31, 2021

I believe .animation now needs to be more specific, by adding a value parameter or by changing it to .withAnimation.

I'm not sure if this is the right way, and I haven't tested it but the following suppresses the warning in FFTView.swift, for example:

struct AmplitudeBar: View {
    var amplitude: Double
    var linearGradient: LinearGradient
    var paddingFraction: CGFloat = 0.2
    var includeCaps: Bool = true
    @State private var offset: CGFloat = 0
    @State private var geoSize: CGFloat = 0

    var body: some View {
        GeometryReader { geometry in
            ZStack(alignment: .bottom) {
                // Colored rectangle in back of ZStack
                Rectangle()
                    .fill(self.linearGradient)

                // Dynamic black mask padded from bottom in relation to the amplitude
                Rectangle()
                    .fill(Color.black)
                    .mask(Rectangle().padding(.bottom, geoSize))
                    .onAppear {
                        withAnimation(.easeOut(duration: 0.15)) { self.geoSize = geometry.size.height * CGFloat(amplitude) }
                    }
//                    .animation(.easeOut(duration: 0.15))

                // White bar with slower animation for floating effect
                if includeCaps {
                    addCap(width: geometry.size.width, height: geometry.size.height)
                }
            }
            .padding(geometry.size.width * paddingFraction / 2)
            .border(Color.black, width: geometry.size.width * paddingFraction / 2)
        }
    }

    // Creates the Cap View - seperate method allows variable definitions inside a GeometryReader
    func addCap(width: CGFloat, height: CGFloat) -> some View {
        let padding = width * paddingFraction / 2
        let capHeight = height * 0.005
        let capDisplacement = height * 0.02
        let capOffset = -height * CGFloat(amplitude) - capDisplacement - padding * 2
        let capMaxOffset = -height + capHeight + padding * 2

        return Rectangle()
            .fill(Color.white)
            .frame(height: capHeight)
            .offset(x: 0.0, y: offset) // prevents offset from pushing cap outside of it's frame
            .onAppear {
                withAnimation(.easeOut(duration: 0.6)) { self.offset = -height > capOffset - capHeight ? capMaxOffset : capOffset }
            }
//            .animation(.easeOut(duration: 0.6))
    }
}
@ShowtimeSoft
Copy link

As you say, you could also just add a value parameter to .animation.

So I presume that:

.animation(.easeOut(duration: 0.6), value: amplitude)

would also work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants