Skip to content

Instantly share code, notes, and snippets.

@amosgyamfi
Created December 20, 2024 08:05
Show Gist options
  • Save amosgyamfi/d16e4e4c2a0836cb10d6d88c405cdfc8 to your computer and use it in GitHub Desktop.
Save amosgyamfi/d16e4e4c2a0836cb10d6d88c405cdfc8 to your computer and use it in GitHub Desktop.
import SwiftUI
struct PulsingHearts: View {
let hearts: [(image: String, animation: Animation)] = [
("heartSpring", .bouncy(duration: 1, extraBounce: 0.6)),
("heartSky", .bouncy(duration: 1, extraBounce: 0.4).delay(0.1)),
("heartStrawberry", .bouncy(duration: 1, extraBounce: 0.2).delay(0.2))
]
var body: some View {
ZStack {
ForEach(hearts, id: \.image) { heart in
PulsingHeart(image: heart.image, animation: heart.animation)
}
}
}
}
struct PulsingHeart: View {
let image: String
let animation: Animation
var body: some View {
PhaseAnimator([false, true]) { pulsate in
Image(image)
.scaleEffect(pulsate ? 2 : 0, anchor: .bottom)
.opacity(pulsate ? 2 : 0)
} animation: { _ in
animation
}
}
}
#Preview {
PulsingHearts()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment