Created
September 10, 2021 13:42
-
-
Save amosgyamfi/b2e65d173480cd379de825a83e925bc5 to your computer and use it in GitHub Desktop.
This file contains 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
// | |
// SparklingHeart.swift | |
// SparklingHeart | |
// | |
// Created by Amos Gyamfi on 5.9.2021. | |
// | |
import SwiftUI | |
struct SparklingHeart: View { | |
@State private var beating = false | |
var body: some View { | |
VStack(spacing: 50) { | |
Text("Sparkling Heart") | |
.font(.title) | |
Text("A pink love heart with stars around it, making it look like it is sparkling or shimmering.") | |
.multilineTextAlignment(.center) | |
ZStack { | |
if #available(iOS 15.0, *) { | |
Image("front") | |
.scaleEffect(beating ? 1.2 : 1.7, anchor: .bottom) | |
.offset(y: 16) | |
.animation(.timingCurve(0.68, -0.6, 0.32, 1.6).delay(0.5).repeatForever(autoreverses: false).speed(0.5), value: beating) | |
.task{ | |
beating.toggle() | |
} | |
HStack { | |
Image("sparkle_left") | |
.scaleEffect(beating ? 0 : 1) | |
.animation(.timingCurve(0.6, 0.68, 0.32, 2).repeatForever(autoreverses: false).speed(0.8), value: beating) | |
.task{ | |
beating.toggle() | |
} | |
Image("sparkle_right") | |
.scaleEffect(beating ? 0 : 1) | |
.animation(.timingCurve(0.68, 0.6, 0.32, 1).repeatForever(autoreverses: false).speed(0.7), value: beating) | |
.task{ | |
beating.toggle() | |
} | |
} | |
.rotationEffect(.degrees(45)) | |
} else { | |
// Fallback on earlier versions | |
} | |
} | |
} | |
} | |
} | |
struct SparklingHeart_Previews: PreviewProvider { | |
static var previews: some View { | |
SparklingHeart() | |
.preferredColorScheme(.dark) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment