Created
December 20, 2024 08:05
-
-
Save amosgyamfi/d16e4e4c2a0836cb10d6d88c405cdfc8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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