🐥

'animation' was deprecated in iOS 15.0: Use withAnimation or animation

2023/01/27に公開

カスタムな ButtonStylefunc makeBody(configuration: Configuration) するときに出ていたので。

before

Configuration.label
  .scaleEffect(isPressed ? 0.95 : 1)
  .animation(.easeOut(duration: 0.2))
⚠️ 'animation' was deprecated in iOS 15.0: Use withAnimation or animation

after

Configuration.label
  .scaleEffect(isPressed ? 0.95 : 1)
  .animation(.easeOut(duration: 0.2), value: configuration.isPressed)

全文

struct RoundedButtonStyle: ButtonStyle {
    func makeBody(configuration: Configuration) -> some View {
        configuration.label
            .padding()
            .background(Color.accentColor)
            .foregroundColor(.white)
            .font(.body.bold())
            .clipShape(RoundedRectangle(cornerRadius: 16, style: .continuous))
            .scaleEffect(isPressed ? 0.95 : 1)
            .animation(.easeOut(duration: 0.2), value: configuration.isPressed)
    }
}

struct ButtonStyle_Previews: PreviewProvider {
    static var previews: some View {
        VStack {
            Button("RoundedRect", action: {})
                .buttonStyle(RoundedButtonStyle())
        }
    }
}

Discussion