Skip to content

Instantly share code, notes, and snippets.

@amosgyamfi
Created November 11, 2023 01:58
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/cc85a4a40d171eb93f88c5b1a16b5035 to your computer and use it in GitHub Desktop.
Save amosgyamfi/cc85a4a40d171eb93f88c5b1a16b5035 to your computer and use it in GitHub Desktop.
//
// BouncyAlternative.swift
// ChatReactionAnimations
//
import SwiftUI
struct BouncyAlternative: View {
@State private var scaleRotate = false
@State private var thumbsCount = 0
var body: some View {
HStack(spacing: 32) {
Button {
withAnimation(.interpolatingSpring(stiffness: 170, damping: 10)) {
scaleRotate.toggle()
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.45) {
withAnimation(.interpolatingSpring(stiffness: 170, damping: 10)) {
scaleRotate = false
}
}
} label: {
Image(.thumbup)
.rotationEffect(.degrees(scaleRotate ? -45 : 0), anchor: .bottomLeading)
.scaleEffect(scaleRotate ? 1.5 : 1)
}
Button {
thumbsCount += 1
} label: {
Image(.thumbup)
}
.phaseAnimator([false, true], trigger: thumbsCount) { icon, scaleRotate in
icon
.rotationEffect(.degrees(scaleRotate ? -45 : 0), anchor: .bottomLeading)
.scaleEffect(scaleRotate ? 1.5 : 1)
} animation: { scaleRotate in
//.bouncy
.bouncy(duration: 0.5, extraBounce: 0.4)
}
}
}
}
#Preview {
BouncyAlternative()
.preferredColorScheme(.dark)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment