Skip to content

Instantly share code, notes, and snippets.

@amosgyamfi
Created September 10, 2021 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amosgyamfi/ea3c4346c73546495642f24be465265f to your computer and use it in GitHub Desktop.
Save amosgyamfi/ea3c4346c73546495642f24be465265f to your computer and use it in GitHub Desktop.
//
// 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