Glimmer / app · glimmertoday.ai / native / Glimmer / EarnedCoins.swift
| 1 | import SwiftUI |
| 2 | |
| 3 | struct EarnedCoins: Identifiable, Equatable { |
| 4 | let id = UUID() |
| 5 | let amount: Int |
| 6 | } |
| 7 | |
| 8 | struct EarnedCoinsToast: View { |
| 9 | let award: EarnedCoins |
| 10 | @Environment(\.accessibilityReduceMotion) private var reduceMotion |
| 11 | |
| 12 | @State private var settled = false |
| 13 | |
| 14 | var body: some View { |
| 15 | HStack(spacing: 9) { |
| 16 | CoinMark(size: 24) |
| 17 | .scaleEffect(settled || reduceMotion ? 1 : 1.14) |
| 18 | .offset(y: settled || reduceMotion ? 0 : -7) |
| 19 | .opacity(settled || reduceMotion ? 1 : 0) |
| 20 | .task { |
| 21 | guard !reduceMotion else { return } |
| 22 | try? await Task.sleep(for: .milliseconds(24)) |
| 23 | guard !Task.isCancelled else { return } |
| 24 | withAnimation(.spring(duration: 0.42, bounce: 0.18)) { settled = true } |
| 25 | } |
| 26 | Text("+\(award.amount)").font(.callout.monospacedDigit().weight(.semibold)) |
| 27 | Text("coins earned").font(.callout).foregroundStyle(.secondary) |
| 28 | } |
| 29 | .padding(.horizontal, 16).padding(.vertical, 11) |
| 30 | .glimmerGlass(.capsule, tint: GlimmerColor.honey.opacity(0.40)) |
| 31 | .shadow(color: .black.opacity(0.09), radius: 8, y: 3) |
| 32 | .allowsHitTesting(false) |
| 33 | .accessibilityElement(children: .ignore) |
| 34 | .accessibilityLabel("\(award.amount) coins earned") |
| 35 | .accessibilityIdentifier("earnedCoins") |
| 36 | } |
| 37 | } |