krz/daybyday

iOS learning games for young children: days, months, seasons, numbers, letters, animals and more. education ios kids swift https://krz.sh/apps/daybyday/

DayByDay/Quiz/FinishedView.swift

062549ad26607ce9e973ed2a9a7ef6f853885f83
daybyday/DayByDay/Quiz/FinishedView.swift history · blame · raw

43 lines · 1365 bytes

1 symbol in this file
 1//
 2//  FinishedView.swift
 3//  DayByDay
 4//
 5
 6import SwiftUI
 7
 8/// End of a game: cheering mascot, "You did it!", and Play again.
 9struct FinishedView: View {
10    let onPlayAgain: () -> Void
11
12    @State private var speechToken = 0
13
14    var body: some View {
15        CenteredScrollView {
16            VStack(spacing: 28) {
17                MascotView(mood: .cheering)
18                    .frame(width: 180, height: 180)
19                Text("You did it!")
20                    .font(.heading(48, weight: .heavy))
21                Button(action: onPlayAgain) {
22                    Label("Play again", systemImage: "arrow.clockwise")
23                        .font(.heading(28))
24                        .foregroundStyle(.white)
25                        .padding(.horizontal, 40)
26                        .padding(.vertical, 20)
27                        .background(Capsule().fill(RoundStyle.playAgainFill))
28                }
29                .buttonStyle(.plain)
30            }
31            .padding(32)
32        }
33        .onAppear {
34            SoundEngine.shared.play(.roundComplete)
35            speechToken += 1
36            let token = speechToken
37            DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
38                if token == speechToken { SpeechSynthesizer.shared.speak(Lines.youDidIt) }
39            }
40        }
41        .onDisappear { speechToken += 1 }
42    }
43}