Created
November 11, 2023 01:58
-
-
Save amosgyamfi/cc85a4a40d171eb93f88c5b1a16b5035 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
// | |
// 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