DayByDay/Home/CategoryHubView.swift
77 lines · 2836 bytes
2 symbols in this file
1//
2// CategoryHubView.swift
3// DayByDay
4//
5
6import SwiftUI
7
8/// What a child can do with one topic. Same layout for every topic.
9struct CategoryHubView: View {
10 let category: Category
11
12 @Environment(\.dynamicTypeSize) private var typeSize
13
14 var body: some View {
15 ScrollView {
16 VStack(spacing: 24) {
17 activity(Lines.lookAndListen, systemImage: "eye.fill", color: category.color) {
18 category.lookAndListenView
19 .navigationTitle(category.label)
20 }
21 ForEach(category.games, id: \.self) { game in
22 activity(game.title, systemImage: game.symbol, color: category.color) {
23 GameDestination(category: category, game: game)
24 }
25 }
26 }
27 .padding(typeSize.isAccessibilitySize ? 16 : 32)
28 .frame(maxWidth: 640)
29 .frame(maxWidth: .infinity)
30 }
31 }
32
33 private func activity(_ title: String, systemImage: String, color: Color,
34 @ViewBuilder destination: @escaping () -> some View) -> some View {
35 NavigationLink(destination: destination) {
36 // The symbol goes above the title at the accessibility text sizes.
37 let layout = typeSize.isAccessibilitySize
38 ? AnyLayout(VStackLayout(alignment: .leading, spacing: 8)) : AnyLayout(HStackLayout(spacing: 20))
39 layout {
40 Image(systemName: systemImage)
41 .font(.system(size: 44))
42 Text(title)
43 .font(.heading(32))
44 Spacer(minLength: 0)
45 }
46 .foregroundStyle(.white)
47 .padding(.horizontal, typeSize.isAccessibilitySize ? 20 : 32)
48 .padding(.vertical, 16)
49 .frame(maxWidth: .infinity, minHeight: 120, alignment: .leading)
50 .background(RoundedRectangle(cornerRadius: 32, style: .continuous).fill(color))
51 }
52 .buttonStyle(.plain)
53 .accessibilityIdentifier("activity:\(title)")
54 .simultaneousGesture(TapGesture().onEnded { SpeechSynthesizer.shared.speak(title) })
55 }
56}
57
58extension Category {
59 /// The existing card grid for this topic.
60 @ViewBuilder
61 var lookAndListenView: some View {
62 switch self {
63 case .today: TodayRoutineView()
64 case .days: DaysOfWeekView()
65 case .months: MonthsOfYearView()
66 case .seasons: SeasonsView()
67 case .numbers: NumbersView()
68 case .colors: ColorsView()
69 case .shapes: ShapesView()
70 case .animals: AnimalsView()
71 case .alphabet: AlphabetView()
72 case .weather: WeatherView()
73 case .bodyParts: BodyPartsView()
74 case .food: FoodView()
75 }
76 }
77}