// // Cardify.swift // Memorize // // Created by ching on 2023/2/15. // import SwiftUI struct Cardify: AnimatableModifier { init(isFaceUp: Bool) { self.rotation = isFaceUp ? 0 : 180 } var animatableData: Double { get { rotation } set { rotation = newValue } } var rotation: Double func body(content: Content) -> some View { ZStack { let shape = RoundedRectangle(cornerRadius: const.DrawingConstants.cornerRadius) if rotation < 90 { shape.fill().foregroundColor(.white) shape.strokeBorder(lineWidth: const.DrawingConstants.lineWidth) } else { shape.fill() } content .opacity(rotation < 90 ? 1 : 0) } .rotation3DEffect(Angle.degrees(rotation), axis: (x: 0, y: 1, z: 0)) } } extension View { func cadify(isFaceUp: Bool) -> some View { modifier(Cardify(isFaceUp: isFaceUp)) } }