damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 150bbb1eb2d051756420e8242c51e56e8e4d4dc1
parent 0aff41d3842924dd67753e1cf469ad6442a3ae0c
Author: Swift <scoder1747@gmail.com>
Date:   Tue, 28 Feb 2023 11:18:48 -0500

Add shaka animation

Changelog-Added: Add shaka animation
Closes: #705

Diffstat:
Mdamus/Views/ActionBar/EventActionBar.swift | 30+++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/damus/Views/ActionBar/EventActionBar.swift b/damus/Views/ActionBar/EventActionBar.swift @@ -167,13 +167,41 @@ struct LikeButton: View { let action: () -> () @Environment(\.colorScheme) var colorScheme + + // Following four are Shaka animation properties + let timer = Timer.publish(every: 0.1, on: .main, in: .common).autoconnect() + @State private var shouldAnimate = false + @State private var rotationAngle = 0.0 + @State private var amountOfAngleIncrease: Double = 0.0 var body: some View { - Button(action: action) { + + Button(action: { + withAnimation(Animation.easeOut(duration: 0.15)) { + self.action() + shouldAnimate = true + amountOfAngleIncrease = 20.0 + } + }) { Image(liked ? "shaka-full" : "shaka-line") .foregroundColor(liked ? .accentColor : .gray) } .accessibilityLabel(NSLocalizedString("Like", comment: "Accessibility Label for Like button")) + .rotationEffect(Angle(degrees: shouldAnimate ? rotationAngle : 0)) + .onReceive(self.timer) { _ in + // Shaka animation logic + rotationAngle = amountOfAngleIncrease + if amountOfAngleIncrease == 0 { + timer.upstream.connect().cancel() + return + } + amountOfAngleIncrease = -amountOfAngleIncrease + if amountOfAngleIncrease < 0 { + amountOfAngleIncrease += 5 + } else { + amountOfAngleIncrease -= 5 + } + } } }