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/PromptBar.swift

main
daybyday/DayByDay/Quiz/PromptBar.swift history · blame · raw

40 lines · 1441 bytes

1 symbol in this file
 1//
 2//  PromptBar.swift
 3//  DayByDay
 4//
 5
 6import SwiftUI
 7
 8/// A game's mascot and "Hear it again", which repeats the spoken prompt.
 9/// VoiceOver also reads the prompt as the button's value.
10struct PromptBar: View {
11    @Binding var mascot: MascotState
12    var prompt: String?
13    let action: () -> Void
14
15    @Environment(\.dynamicTypeSize) private var typeSize
16
17    var body: some View {
18        // The mascot goes above the button at the accessibility text sizes.
19        let layout = typeSize.isAccessibilitySize ? AnyLayout(VStackLayout(spacing: 12)) : AnyLayout(HStackLayout(spacing: 12))
20        layout {
21            GameMascot(state: $mascot)
22            Button(action: action) {
23                Label {
24                    // Room for Baloo's tall glyphs inside the text's own frame.
25                    Text("Hear it again").padding(.vertical, 4)
26                } icon: {
27                    Image(systemName: "speaker.wave.2.fill")
28                }
29                .font(.heading(24))
30                .fixedSize(horizontal: false, vertical: true)
31                .padding(.horizontal, 28)
32                .padding(.vertical, 12)
33                .frame(maxWidth: typeSize.isAccessibilitySize ? .infinity : nil)
34                .background(RoundedRectangle(cornerRadius: 30, style: .continuous).fill(Color(.systemGray6)))
35            }
36            .buttonStyle(.plain)
37            .accessibilityValue(prompt ?? "")
38        }
39    }
40}