Created
September 10, 2021 13:27
-
-
Save amosgyamfi/ea3c4346c73546495642f24be465265f 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
// | |
// ContentView.swift | |
// AnimatedEmojis | |
// | |
// Created by Amos Gyamfi on 5.9.2021. | |
// | |
import SwiftUI | |
struct GrowingHeart: View { | |
@State private var growing = false | |
@State private var pulsing = false | |
@State private var beating = false | |
var body: some View { | |
VStack { | |
Text("Growing Heart") | |
.font(.title) | |
Text("A pink heart, inside a slightly larger pink heart, inside a larger-again pink heart. Intended to give the impression of a heart increasing in size.") | |
.multilineTextAlignment(.center) | |
Spacer() | |
ZStack { | |
if #available(iOS 15.0, *) { | |
Image("back") | |
.scaleEffect(growing ? 0.8 : 1.5, anchor: .bottom) | |
.animation(.easeOut(duration: 0.5).repeatForever(autoreverses: true), value: growing) | |
.task{ | |
growing.toggle() | |
} | |
Image("middle") | |
.scaleEffect(pulsing ? 0.9 : 1.5, anchor: .bottom) | |
.offset(y: 8) | |
.animation(.easeInOut(duration: 0.5).repeatForever(autoreverses: true), value: pulsing) | |
.task{ | |
pulsing.toggle() | |
} | |
Image("front") | |
.scaleEffect(beating ? 1 : 1.5, anchor: .bottom) | |
.offset(y: 16) | |
.animation(.easeIn(duration: 0.5).repeatForever(autoreverses: true), value: beating) | |
.task{ | |
beating.toggle() | |
} | |
} else { | |
// Fallback on earlier versions | |
} | |
} | |
Spacer() | |
Spacer() | |
} | |
.padding() | |
} | |
} | |
struct GrowingHeart_Previews: PreviewProvider { | |
static var previews: some View { | |
GrowingHeart() | |
.preferredColorScheme(.dark) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment