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/

Commit 753b20e234

753b20e2347ec94c9abbdef192d219a76993b3b1

parent: d032beeaa4

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-22 22:10 UTC

Add Qlty config; share card shell and grid across categories

- TapCard holds the rounded card, highlight, tap bounce, and
  accessibility every category card repeated; SymbolLabel the
  symbol-over-name content five of them shared.
- CardGrid replaces eleven copies of the ScrollView/LazyVGrid screen.
  Renders of every card and screen are pixel-identical before and after.
- render-voice-elevenlabs.py: plan and remove_stale split out of main.
- Qlty: switch statements excluded from Swift duplication (enum lookup
  tables), return_statements and file_complexity disabled.

Layout: unified · split

.qlty/.gitignore added +7
@@ -0,0 +1,7 @@
1*
2!configs
3!configs/**
4!hooks
5!hooks/**
6!qlty.toml
7!.gitignore
.qlty/qlty.toml added +49
@@ -0,0 +1,49 @@
1config_version = "0"
2
3exclude_patterns = [
4 "**/vendor/**",
5 "**/node_modules/**",
6 "**/testdata/**",
7 "**/dist/**",
8 "**/.build/**",
9 "**/build/**",
10 "**/*.min.*",
11 "**/generated/**",
12 ".claude/**",
13 "**/Pods/**",
14]
15
16test_patterns = [
17 "**/test/**",
18 "**/tests/**",
19 "**/Tests/**",
20 "**/*_test.*",
21 "**/test_*.*",
22 "**/*.test.*",
23 "**/*Tests.swift",
24 "e2e/**",
25]
26
27[[source]]
28name = "default"
29default = true
30
31[[plugin]]
32name = "osv-scanner"
33
34[[plugin]]
35name = "trufflehog"
36
37# Early returns are guard clauses, which keep the happy path unindented.
38[smells.return_statements]
39enabled = false
40
41# Total file complexity is the sum of its functions, which function_complexity
42# already checks.
43[smells.file_complexity]
44enabled = false
45
46# Exhaustive switch-over-enum lookup tables (name, symbol, color per case)
47# share shape but not content.
48[language.swift.smells.duplication]
49filter_patterns = ["(import_declaration _)", "(switch_statement _)"]
AlphabetView.swift +2 −12
@@ -8,19 +8,9 @@ import SwiftUI
88/// Displays all 26 letters A–Z as large, tappable cards in a scrollable grid.
99/// Uses a smaller minimum size to fit more letters across the screen.
1010struct AlphabetView: View {
11 private let columns = [
12 GridItem(.adaptive(minimum: 140, maximum: 300), spacing: 20)
13 ]
14
1511 var body: some View {
16 ScrollView {
17 LazyVGrid(columns: columns, spacing: 20) {
18 ForEach(LearnLetter.allCases) { letter in
19 LetterCard(letter: letter)
20 .frame(minHeight: 160)
21 }
22 }
23 .padding(32)
12 CardGrid(items: LearnLetter.allCases, column: GridItem(.adaptive(minimum: 140, maximum: 300), spacing: 20), spacing: 20, minHeight: 160) { letter in
13 LetterCard(letter: letter)
2414 }
2515 .onDisappear { CardVoice.shared.cancel() }
2616 }
AnimalCard.swift +3 −20
@@ -9,14 +9,11 @@ import SwiftUI
99/// Tapping the card plays a bounce animation and speaks the animal name aloud.
1010struct AnimalCard: View {
1111 let animal: LearnAnimal
12 @State private var isTapped = false
1312
1413 var body: some View {
15 ZStack {
16 RoundedRectangle(cornerRadius: 32, style: .continuous)
17 .fill(animal.color)
18 .shadow(color: animal.color.opacity(0.4), radius: 8, y: 4)
19
14 TapCard(color: animal.color, label: animal.name) {
15 CardVoice.shared.say(animal.cardLine, after: animal.sound)
16 } content: {
2017 VStack(spacing: 16) {
2118 AnimalIcon(animal: animal)
2219 .font(.system(size: 64))
@@ -29,20 +26,6 @@ struct AnimalCard: View {
2926 }
3027 .padding(16)
3128 }
32 .scaleEffect(isTapped ? 1.12 : 1.0)
33 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
34 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
35 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
36 .onTapGesture {
37 isTapped = true
38 CardVoice.shared.say(animal.cardLine, after: animal.sound)
39 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
40 isTapped = false
41 }
42 }
43 .accessibilityElement(children: .ignore)
44 .accessibilityLabel(animal.name)
45 .accessibilityAddTraits(.isButton)
4629 }
4730}
4831
AnimalsView.swift +2 −12
@@ -8,19 +8,9 @@ import SwiftUI
88/// Displays 12 animals as large, tappable cards in a scrollable grid.
99/// Adapts between 1 and 2 columns depending on available width.
1010struct AnimalsView: View {
11 private let columns = [
12 GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24)
13 ]
14
1511 var body: some View {
16 ScrollView {
17 LazyVGrid(columns: columns, spacing: 24) {
18 ForEach(LearnAnimal.allCases) { animal in
19 AnimalCard(animal: animal)
20 .frame(minHeight: 200)
21 }
22 }
23 .padding(32)
12 CardGrid(items: LearnAnimal.allCases) { animal in
13 AnimalCard(animal: animal)
2414 }
2515 .onDisappear { CardVoice.shared.cancel() }
2616 }
BodyPartCard.swift +3 −30
@@ -9,40 +9,13 @@ import SwiftUI
99/// Tapping the card plays a bounce animation and speaks the body part name aloud.
1010struct BodyPartCard: View {
1111 let bodyPart: LearnBodyPart
12 @State private var isTapped = false
1312
1413 var body: some View {
15 ZStack {
16 RoundedRectangle(cornerRadius: 32, style: .continuous)
17 .fill(bodyPart.color)
18 .shadow(color: bodyPart.color.opacity(0.4), radius: 8, y: 4)
19
20 VStack(spacing: 16) {
21 Image(systemName: bodyPart.symbol)
22 .font(.system(size: 64))
23 .foregroundStyle(.white)
24 .symbolRenderingMode(.hierarchical)
25
26 Text(bodyPart.name)
27 .font(.heading(32))
28 .foregroundStyle(.white)
29 }
30 .padding(16)
31 }
32 .scaleEffect(isTapped ? 1.12 : 1.0)
33 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
34 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
35 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
36 .onTapGesture {
37 isTapped = true
14 TapCard(color: bodyPart.color, label: bodyPart.name) {
3815 SpeechSynthesizer.shared.speak(bodyPart.name)
39 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
40 isTapped = false
41 }
16 } content: {
17 SymbolLabel(symbol: bodyPart.symbol, name: bodyPart.name)
4218 }
43 .accessibilityElement(children: .ignore)
44 .accessibilityLabel(bodyPart.name)
45 .accessibilityAddTraits(.isButton)
4619 }
4720}
4821
BodyPartsView.swift +2 −12
@@ -7,19 +7,9 @@ import SwiftUI
77
88/// Displays all 12 body parts as large, tappable cards in a scrollable grid.
99struct BodyPartsView: View {
10 private let columns = [
11 GridItem(.adaptive(minimum: 280), spacing: 24)
12 ]
13
1410 var body: some View {
15 ScrollView {
16 LazyVGrid(columns: columns, spacing: 24) {
17 ForEach(LearnBodyPart.allCases) { part in
18 BodyPartCard(bodyPart: part)
19 .frame(minHeight: 200)
20 }
21 }
22 .padding(32)
11 CardGrid(items: LearnBodyPart.allCases, column: .narrowCards) { part in
12 BodyPartCard(bodyPart: part)
2313 }
2414 }
2515}
ColorCard.swift +3 −20
@@ -8,32 +8,15 @@ import SwiftUI
88/// A single large card filled with a color. Tapping speaks the color name aloud.
99struct ColorCard: View {
1010 let learnColor: LearnColor
11 @State private var isTapped = false
1211
1312 var body: some View {
14 ZStack {
15 RoundedRectangle(cornerRadius: 32, style: .continuous)
16 .fill(learnColor.color)
17 .shadow(color: learnColor.color.opacity(0.4), radius: 8, y: 4)
18
13 TapCard(color: learnColor.color, label: learnColor.name) {
14 SpeechSynthesizer.shared.speak(learnColor.name)
15 } content: {
1916 Text(learnColor.name)
2017 .font(.heading(36))
2118 .foregroundStyle(learnColor.labelColor)
2219 }
23 .scaleEffect(isTapped ? 1.12 : 1.0)
24 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
25 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
26 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
27 .onTapGesture {
28 isTapped = true
29 SpeechSynthesizer.shared.speak(learnColor.name)
30 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
31 isTapped = false
32 }
33 }
34 .accessibilityElement(children: .ignore)
35 .accessibilityLabel(learnColor.name)
36 .accessibilityAddTraits(.isButton)
3720 }
3821}
3922
ColorsView.swift +2 −12
@@ -8,19 +8,9 @@ import SwiftUI
88/// Displays 10 colors as large, tappable cards in a scrollable grid.
99/// Adapts between 1 and 2 columns depending on available width.
1010struct ColorsView: View {
11 private let columns = [
12 GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24)
13 ]
14
1511 var body: some View {
16 ScrollView {
17 LazyVGrid(columns: columns, spacing: 24) {
18 ForEach(LearnColor.allCases) { color in
19 ColorCard(learnColor: color)
20 .frame(minHeight: 200)
21 }
22 }
23 .padding(32)
12 CardGrid(items: LearnColor.allCases) { color in
13 ColorCard(learnColor: color)
2414 }
2515 }
2616}
DayByDay/CardGrid.swift added +46
@@ -0,0 +1,46 @@
1//
2// CardGrid.swift
3// DayByDay
4//
5
6import SwiftUI
7
8/// Large, tappable cards in a scrollable adaptive grid.
9struct CardGrid<Item: Identifiable, Card: View, Header: View>: View {
10 let items: [Item]
11 var column = GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24)
12 var spacing: CGFloat = 24
13 var minHeight: CGFloat = 200
14 @ViewBuilder var header: () -> Header
15 @ViewBuilder let card: (Item) -> Card
16
17 var body: some View {
18 ScrollView {
19 header()
20 LazyVGrid(columns: [column], spacing: spacing) {
21 ForEach(items) { item in
22 card(item)
23 .frame(minHeight: minHeight)
24 }
25 }
26 .padding(32)
27 }
28 }
29}
30
31extension CardGrid where Header == EmptyView {
32 init(
33 items: [Item],
34 column: GridItem = GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24),
35 spacing: CGFloat = 24,
36 minHeight: CGFloat = 200,
37 @ViewBuilder card: @escaping (Item) -> Card
38 ) {
39 self.init(items: items, column: column, spacing: spacing, minHeight: minHeight, header: { EmptyView() }, card: card)
40 }
41}
42
43extension GridItem {
44 /// Columns for cards with longer names, which need a narrower minimum to fit two across.
45 static let narrowCards = GridItem(.adaptive(minimum: 280), spacing: 24)
46}
DayByDay/DayCard.swift +9 −47
@@ -12,35 +12,17 @@ struct DayCard: View {
1212 let day: DayOfWeek
1313 var isHighlighted = false
1414 var picture: DayPictureKind? = nil
15 @State private var isTapped = false
16
17 private var cardScale: CGFloat {
18 if isTapped { return 1.12 }
19 if isHighlighted { return 1.04 }
20 return 1.0
21 }
2215
2316 var body: some View {
24 ZStack {
25 RoundedRectangle(cornerRadius: 32, style: .continuous)
26 .fill(day.color)
27 .shadow(color: day.color.opacity(0.4), radius: 8, y: 4)
28 // Glow on the card only: on the label it would lower the contrast.
29 .shadow(color: isHighlighted ? .white.opacity(0.8) : .clear, radius: 12)
30
31 VStack(spacing: 16) {
32 Image(systemName: day.symbol)
33 .font(.system(size: 64))
34 .foregroundStyle(.white)
35 .symbolRenderingMode(.hierarchical)
36
37 Text(day.name)
38 .font(.heading(32))
39 .foregroundStyle(.white)
40 }
41 .padding(16)
42 }
43 .overlay(alignment: .topTrailing) {
17 TapCard(
18 color: day.color,
19 label: picture.map { "\(day.name), \($0.name)" } ?? day.name,
20 isHighlighted: isHighlighted
21 ) {
22 CardVoice.shared.say(Lines.dayCard(day, picture: picture), after: nil)
23 } content: {
24 SymbolLabel(symbol: day.symbol, name: day.name)
25 } badge: {
4426 if let picture {
4527 Image(systemName: picture.symbol)
4628 .font(.system(size: 30, weight: .bold))
@@ -51,26 +33,6 @@ struct DayCard: View {
5133 .accessibilityHidden(true)
5234 }
5335 }
54 .overlay {
55 if isHighlighted {
56 RoundedRectangle(cornerRadius: 32, style: .continuous)
57 .strokeBorder(.white, lineWidth: 5)
58 }
59 }
60 .scaleEffect(cardScale)
61 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
62 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
63 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
64 .onTapGesture {
65 isTapped = true
66 CardVoice.shared.say(Lines.dayCard(day, picture: picture), after: nil)
67 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
68 isTapped = false
69 }
70 }
71 .accessibilityElement(children: .ignore)
72 .accessibilityLabel(picture.map { "\(day.name), \($0.name)" } ?? day.name)
73 .accessibilityAddTraits(.isButton)
7436 }
7537}
7638
DayByDay/DaysOfWeekView.swift +2 −12
@@ -11,19 +11,9 @@ import SwiftUI
1111struct DaysOfWeekView: View {
1212 @Environment(ProfileSession.self) private var session
1313
14 private let columns = [
15 GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24)
16 ]
17
1814 var body: some View {
19 ScrollView {
20 LazyVGrid(columns: columns, spacing: 24) {
21 ForEach(DayOfWeek.allCases) { day in
22 DayCard(day: day, isHighlighted: day == .current, picture: picture(on: day))
23 .frame(minHeight: 200)
24 }
25 }
26 .padding(32)
15 CardGrid(items: DayOfWeek.allCases) { day in
16 DayCard(day: day, isHighlighted: day == .current, picture: picture(on: day))
2717 }
2818 .onDisappear { CardVoice.shared.cancel() }
2919 }
DayByDay/MonthCard.swift +3 −44
@@ -10,54 +10,13 @@ import SwiftUI
1010struct MonthCard: View {
1111 let month: MonthOfYear
1212 var isHighlighted = false
13 @State private var isTapped = false
14
15 private var cardScale: CGFloat {
16 if isTapped { return 1.12 }
17 if isHighlighted { return 1.04 }
18 return 1.0
19 }
2013
2114 var body: some View {
22 ZStack {
23 RoundedRectangle(cornerRadius: 32, style: .continuous)
24 .fill(month.color)
25 .shadow(color: month.color.opacity(0.4), radius: 8, y: 4)
26 // Glow on the card only: on the label it would lower the contrast.
27 .shadow(color: isHighlighted ? .white.opacity(0.8) : .clear, radius: 12)
28
29 VStack(spacing: 16) {
30 Image(systemName: month.symbol)
31 .font(.system(size: 64))
32 .foregroundStyle(.white)
33 .symbolRenderingMode(.hierarchical)
34
35 Text(month.name)
36 .font(.heading(32))
37 .foregroundStyle(.white)
38 }
39 .padding(16)
40 }
41 .overlay {
42 if isHighlighted {
43 RoundedRectangle(cornerRadius: 32, style: .continuous)
44 .strokeBorder(.white, lineWidth: 5)
45 }
46 }
47 .scaleEffect(cardScale)
48 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
49 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
50 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
51 .onTapGesture {
52 isTapped = true
15 TapCard(color: month.color, label: month.name, isHighlighted: isHighlighted) {
5316 SpeechSynthesizer.shared.speak(month.name)
54 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
55 isTapped = false
56 }
17 } content: {
18 SymbolLabel(symbol: month.symbol, name: month.name)
5719 }
58 .accessibilityElement(children: .ignore)
59 .accessibilityLabel(month.name)
60 .accessibilityAddTraits(.isButton)
6120 }
6221}
6322
DayByDay/MonthsOfYearView.swift +2 −12
@@ -8,19 +8,9 @@ import SwiftUI
88/// Displays all twelve months as large, tappable cards in a scrollable grid.
99/// Adapts between 1 and 2 columns depending on available width.
1010struct MonthsOfYearView: View {
11 private let columns = [
12 GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24)
13 ]
14
1511 var body: some View {
16 ScrollView {
17 LazyVGrid(columns: columns, spacing: 24) {
18 ForEach(MonthOfYear.allCases) { month in
19 MonthCard(month: month, isHighlighted: month == .current)
20 .frame(minHeight: 200)
21 }
22 }
23 .padding(32)
12 CardGrid(items: MonthOfYear.allCases) { month in
13 MonthCard(month: month, isHighlighted: month == .current)
2414 }
2515 }
2616}
DayByDay/SeasonCard.swift +3 −44
@@ -10,54 +10,13 @@ import SwiftUI
1010struct SeasonCard: View {
1111 let season: Season
1212 var isHighlighted = false
13 @State private var isTapped = false
14
15 private var cardScale: CGFloat {
16 if isTapped { return 1.12 }
17 if isHighlighted { return 1.04 }
18 return 1.0
19 }
2013
2114 var body: some View {
22 ZStack {
23 RoundedRectangle(cornerRadius: 32, style: .continuous)
24 .fill(season.color)
25 .shadow(color: season.color.opacity(0.4), radius: 8, y: 4)
26 // Glow on the card only: on the label it would lower the contrast.
27 .shadow(color: isHighlighted ? .white.opacity(0.8) : .clear, radius: 12)
28
29 VStack(spacing: 16) {
30 Image(systemName: season.symbol)
31 .font(.system(size: 64))
32 .foregroundStyle(.white)
33 .symbolRenderingMode(.hierarchical)
34
35 Text(season.name)
36 .font(.heading(32))
37 .foregroundStyle(.white)
38 }
39 .padding(16)
40 }
41 .overlay {
42 if isHighlighted {
43 RoundedRectangle(cornerRadius: 32, style: .continuous)
44 .strokeBorder(.white, lineWidth: 5)
45 }
46 }
47 .scaleEffect(cardScale)
48 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
49 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
50 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
51 .onTapGesture {
52 isTapped = true
15 TapCard(color: season.color, label: season.name, isHighlighted: isHighlighted) {
5316 SpeechSynthesizer.shared.speak(season.name)
54 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
55 isTapped = false
56 }
17 } content: {
18 SymbolLabel(symbol: season.symbol, name: season.name)
5719 }
58 .accessibilityElement(children: .ignore)
59 .accessibilityLabel(season.name)
60 .accessibilityAddTraits(.isButton)
6120 }
6221}
6322
DayByDay/SeasonsView.swift +2 −12
@@ -8,19 +8,9 @@ import SwiftUI
88/// Displays all four seasons as large, tappable cards in a scrollable grid.
99/// Adapts between 1 and 2 columns depending on available width.
1010struct SeasonsView: View {
11 private let columns = [
12 GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24)
13 ]
14
1511 var body: some View {
16 ScrollView {
17 LazyVGrid(columns: columns, spacing: 24) {
18 ForEach(Season.allCases) { season in
19 SeasonCard(season: season, isHighlighted: season == .current)
20 .frame(minHeight: 200)
21 }
22 }
23 .padding(32)
12 CardGrid(items: Season.allCases) { season in
13 SeasonCard(season: season, isHighlighted: season == .current)
2414 }
2515 }
2616}
DayByDay/TapCard.swift added +90
@@ -0,0 +1,90 @@
1//
2// TapCard.swift
3// DayByDay
4//
5
6import SwiftUI
7
8/// The rounded, colored card shared by every learning category.
9/// Tapping it plays a bounce animation and runs `onTap`, which speaks the card.
10/// A highlighted card (today's day, month, or season) is enlarged, glows, and has a white border.
11struct TapCard<Content: View, Badge: View>: View {
12 let color: Color
13 let label: String
14 var isHighlighted = false
15 let onTap: () -> Void
16 @ViewBuilder let content: () -> Content
17 @ViewBuilder var badge: () -> Badge
18 @State private var isTapped = false
19
20 private var cardScale: CGFloat {
21 if isTapped { return 1.12 }
22 if isHighlighted { return 1.04 }
23 return 1.0
24 }
25
26 var body: some View {
27 ZStack {
28 RoundedRectangle(cornerRadius: 32, style: .continuous)
29 .fill(color)
30 .shadow(color: color.opacity(0.4), radius: 8, y: 4)
31 // Glow on the card only: on the label it would lower the contrast.
32 .shadow(color: isHighlighted ? .white.opacity(0.8) : .clear, radius: 12)
33
34 content()
35 }
36 .overlay(alignment: .topTrailing) { badge() }
37 .overlay {
38 if isHighlighted {
39 RoundedRectangle(cornerRadius: 32, style: .continuous)
40 .strokeBorder(.white, lineWidth: 5)
41 }
42 }
43 .scaleEffect(cardScale)
44 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
45 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
46 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
47 .onTapGesture {
48 isTapped = true
49 onTap()
50 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
51 isTapped = false
52 }
53 }
54 .accessibilityElement(children: .ignore)
55 .accessibilityLabel(label)
56 .accessibilityAddTraits(.isButton)
57 }
58}
59
60extension TapCard where Badge == EmptyView {
61 init(
62 color: Color,
63 label: String,
64 isHighlighted: Bool = false,
65 onTap: @escaping () -> Void,
66 @ViewBuilder content: @escaping () -> Content
67 ) {
68 self.init(color: color, label: label, isHighlighted: isHighlighted, onTap: onTap, content: content, badge: { EmptyView() })
69 }
70}
71
72/// An SF Symbol above a name, the content of most category cards.
73struct SymbolLabel: View {
74 let symbol: String
75 let name: String
76
77 var body: some View {
78 VStack(spacing: 16) {
79 Image(systemName: symbol)
80 .font(.system(size: 64))
81 .foregroundStyle(.white)
82 .symbolRenderingMode(.hierarchical)
83
84 Text(name)
85 .font(.heading(32))
86 .foregroundStyle(.white)
87 }
88 .padding(16)
89 }
90}
FoodCard.swift +3 −21
@@ -10,14 +10,11 @@ import SwiftUI
1010/// Each food displays its emoji at large size for instant recognition.
1111struct FoodCard: View {
1212 let food: LearnFood
13 @State private var isTapped = false
1413
1514 var body: some View {
16 ZStack {
17 RoundedRectangle(cornerRadius: 32, style: .continuous)
18 .fill(food.color)
19 .shadow(color: food.color.opacity(0.4), radius: 8, y: 4)
20
15 TapCard(color: food.color, label: food.name) {
16 SpeechSynthesizer.shared.speak(food.name)
17 } content: {
2118 VStack(spacing: 16) {
2219 Text(food.emoji)
2320 .font(.system(size: 72))
@@ -28,22 +25,7 @@ struct FoodCard: View {
2825 }
2926 .padding(16)
3027 }
31 .scaleEffect(isTapped ? 1.12 : 1.0)
32 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
33 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
34 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
35 .onTapGesture {
36 isTapped = true
37 SpeechSynthesizer.shared.speak(food.name)
38 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
39 isTapped = false
40 }
41 }
42 .accessibilityElement(children: .ignore)
43 .accessibilityLabel(food.name)
44 .accessibilityAddTraits(.isButton)
4528 }
46
4729}
4830
4931// MARK: - Food model
FoodView.swift +2 −12
@@ -7,19 +7,9 @@ import SwiftUI
77
88/// Displays all 12 fruits and vegetables as large, tappable cards in a scrollable grid.
99struct FoodView: View {
10 private let columns = [
11 GridItem(.adaptive(minimum: 280), spacing: 24)
12 ]
13
1410 var body: some View {
15 ScrollView {
16 LazyVGrid(columns: columns, spacing: 24) {
17 ForEach(LearnFood.allCases) { food in
18 FoodCard(food: food)
19 .frame(minHeight: 200)
20 }
21 }
22 .padding(32)
11 CardGrid(items: LearnFood.allCases, column: .narrowCards) { food in
12 FoodCard(food: food)
2313 }
2414 }
2515}
LetterCard.swift +3 −20
@@ -9,32 +9,15 @@ import SwiftUI
99/// Tapping the card plays a bounce animation and speaks the letter aloud.
1010struct LetterCard: View {
1111 let letter: LearnLetter
12 @State private var isTapped = false
1312
1413 var body: some View {
15 ZStack {
16 RoundedRectangle(cornerRadius: 32, style: .continuous)
17 .fill(letter.color)
18 .shadow(color: letter.color.opacity(0.4), radius: 8, y: 4)
19
14 TapCard(color: letter.color, label: letter.spokenName) {
15 CardVoice.shared.say(letter.cardLine, after: nil)
16 } content: {
2017 Text(letter.character)
2118 .font(.heading(64, weight: .heavy))
2219 .foregroundStyle(.white)
2320 }
24 .scaleEffect(isTapped ? 1.12 : 1.0)
25 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
26 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
27 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
28 .onTapGesture {
29 isTapped = true
30 CardVoice.shared.say(letter.cardLine, after: nil)
31 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
32 isTapped = false
33 }
34 }
35 .accessibilityElement(children: .ignore)
36 .accessibilityLabel(letter.spokenName)
37 .accessibilityAddTraits(.isButton)
3821 }
3922}
4023
NumberCard.swift +3 −34
@@ -10,22 +10,11 @@ import SwiftUI
1010struct NumberCard: View {
1111 let number: LearnNumber
1212 var isHighlighted = false
13 @State private var isTapped = false
14
15 private var cardScale: CGFloat {
16 if isTapped { return 1.12 }
17 if isHighlighted { return 1.04 }
18 return 1.0
19 }
2013
2114 var body: some View {
22 ZStack {
23 RoundedRectangle(cornerRadius: 32, style: .continuous)
24 .fill(number.color)
25 .shadow(color: number.color.opacity(0.4), radius: 8, y: 4)
26 // Glow on the card only: on the label it would lower the contrast.
27 .shadow(color: isHighlighted ? .white.opacity(0.8) : .clear, radius: 12)
28
15 TapCard(color: number.color, label: number.name, isHighlighted: isHighlighted) {
16 SpeechSynthesizer.shared.speak(number.name)
17 } content: {
2918 VStack(spacing: 10) {
3019 Text("\(number.numeral)")
3120 .font(.heading(60, weight: .heavy))
@@ -41,26 +30,6 @@ struct NumberCard: View {
4130 }
4231 .padding(16)
4332 }
44 .overlay {
45 if isHighlighted {
46 RoundedRectangle(cornerRadius: 32, style: .continuous)
47 .strokeBorder(.white, lineWidth: 5)
48 }
49 }
50 .scaleEffect(cardScale)
51 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
52 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
53 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
54 .onTapGesture {
55 isTapped = true
56 SpeechSynthesizer.shared.speak(number.name)
57 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
58 isTapped = false
59 }
60 }
61 .accessibilityElement(children: .ignore)
62 .accessibilityLabel(number.name)
63 .accessibilityAddTraits(.isButton)
6433 }
6534}
6635
NumbersView.swift +2 −15
@@ -8,22 +8,9 @@ import SwiftUI
88/// Displays numbers 1–10 as large, tappable cards in a scrollable grid.
99/// Adapts between 1 and 2 columns depending on available width.
1010struct NumbersView: View {
11 private let columns = [
12 GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24)
13 ]
14
1511 var body: some View {
16 ScrollView {
17 LazyVGrid(columns: columns, spacing: 24) {
18 ForEach(LearnNumber.allCases) { number in
19 NumberCard(
20 number: number,
21 isHighlighted: number == .current
22 )
23 .frame(minHeight: 200)
24 }
25 }
26 .padding(32)
12 CardGrid(items: LearnNumber.allCases) { number in
13 NumberCard(number: number, isHighlighted: number == .current)
2714 }
2815 }
2916}
ShapeCard.swift +3 −20
@@ -9,14 +9,11 @@ import SwiftUI
99/// Tapping the card plays a bounce animation and speaks the shape name aloud.
1010struct ShapeCard: View {
1111 let shape: LearnShape
12 @State private var isTapped = false
1312
1413 var body: some View {
15 ZStack {
16 RoundedRectangle(cornerRadius: 32, style: .continuous)
17 .fill(shape.color)
18 .shadow(color: shape.color.opacity(0.4), radius: 8, y: 4)
19
14 TapCard(color: shape.color, label: shape.name) {
15 SpeechSynthesizer.shared.speak(shape.name)
16 } content: {
2017 VStack(spacing: 16) {
2118 shape.shapeView
2219 .frame(width: 80, height: 80)
@@ -28,20 +25,6 @@ struct ShapeCard: View {
2825 }
2926 .padding(16)
3027 }
31 .scaleEffect(isTapped ? 1.12 : 1.0)
32 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
33 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
34 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
35 .onTapGesture {
36 isTapped = true
37 SpeechSynthesizer.shared.speak(shape.name)
38 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
39 isTapped = false
40 }
41 }
42 .accessibilityElement(children: .ignore)
43 .accessibilityLabel(shape.name)
44 .accessibilityAddTraits(.isButton)
4528 }
4629}
4730
ShapesView.swift +2 −12
@@ -8,19 +8,9 @@ import SwiftUI
88/// Displays 8 shapes as large, tappable cards in a scrollable grid.
99/// Adapts between 1 and 2 columns depending on available width.
1010struct ShapesView: View {
11 private let columns = [
12 GridItem(.adaptive(minimum: 300, maximum: 500), spacing: 24)
13 ]
14
1511 var body: some View {
16 ScrollView {
17 LazyVGrid(columns: columns, spacing: 24) {
18 ForEach(LearnShape.allCases) { shape in
19 ShapeCard(shape: shape)
20 .frame(minHeight: 200)
21 }
22 }
23 .padding(32)
12 CardGrid(items: LearnShape.allCases) { shape in
13 ShapeCard(shape: shape)
2414 }
2515 }
2616}
WeatherCard.swift +3 −30
@@ -9,40 +9,13 @@ import SwiftUI
99/// Tapping the card plays a bounce animation and speaks the weather name aloud.
1010struct WeatherCard: View {
1111 let weather: LearnWeather
12 @State private var isTapped = false
1312
1413 var body: some View {
15 ZStack {
16 RoundedRectangle(cornerRadius: 32, style: .continuous)
17 .fill(weather.color)
18 .shadow(color: weather.color.opacity(0.4), radius: 8, y: 4)
19
20 VStack(spacing: 16) {
21 Image(systemName: weather.symbol)
22 .font(.system(size: 64))
23 .foregroundStyle(.white)
24 .symbolRenderingMode(.hierarchical)
25
26 Text(weather.name)
27 .font(.heading(32))
28 .foregroundStyle(.white)
29 }
30 .padding(16)
31 }
32 .scaleEffect(isTapped ? 1.12 : 1.0)
33 .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
34 .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
35 .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
36 .onTapGesture {
37 isTapped = true
14 TapCard(color: weather.color, label: weather.name) {
3815 SpeechSynthesizer.shared.speak(weather.name)
39 DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
40 isTapped = false
41 }
16 } content: {
17 SymbolLabel(symbol: weather.symbol, name: weather.name)
4218 }
43 .accessibilityElement(children: .ignore)
44 .accessibilityLabel(weather.name)
45 .accessibilityAddTraits(.isButton)
4619 }
4720}
4821
WeatherView.swift +3 −13
@@ -8,16 +8,12 @@ import SwiftUI
88/// Displays all 8 weather types as large, tappable cards in a scrollable grid.
99/// Shaking the device, or tapping the rain button, makes it rain.
1010struct WeatherView: View {
11 private let columns = [
12 GridItem(.adaptive(minimum: 280), spacing: 24)
13 ]
14
1511 @State private var raining = false
1612 /// Bumped when the screen goes away, so a pending stop does nothing.
1713 @State private var generation = 0
1814
1915 var body: some View {
20 ScrollView {
16 CardGrid(items: LearnWeather.allCases, column: .narrowCards) {
2117 Button(action: rain) {
2218 Label("Shake for rain!", systemImage: "cloud.rain.fill")
2319 .font(.heading(22))
@@ -27,14 +23,8 @@ struct WeatherView: View {
2723 }
2824 .buttonStyle(.plain)
2925 .padding(.top, 16)
30
31 LazyVGrid(columns: columns, spacing: 24) {
32 ForEach(LearnWeather.allCases) { weather in
33 WeatherCard(weather: weather)
34 .frame(minHeight: 200)
35 }
36 }
37 .padding(32)
26 } card: { weather in
27 WeatherCard(weather: weather)
3828 }
3929 .overlay { RainOverlay(isActive: raining) }
4030 .onShake(rain)
scripts/render-voice-elevenlabs.py +21 −12
@@ -120,6 +120,25 @@ def encode(audio: array.array, out: Path) -> None:
120120 str(wav), str(out)], check=True)
121121
122122
123def plan(lines: list, old: dict, out: Path, redo: list) -> tuple[list, list]:
124 """Splits lines into manifest entries to keep and (text, seed) pairs to render."""
125 kept, todo = [], []
126 for text in lines:
127 entry = old.get(text)
128 if entry and text not in redo and entry.get("engine") == MODEL and (out / entry["file"]).exists():
129 kept.append(entry)
130 else:
131 seed = entry["seed"] + 1 if entry and text in redo else 0
132 todo.append((text, seed))
133 return kept, todo
134
135
136def remove_stale(out: Path, keep: set) -> None:
137 for stale in [*out.glob("*.aac"), *out.glob("*.m4a")]:
138 if stale.name not in keep:
139 stale.unlink()
140
141
123142def main() -> None:
124143 parser = argparse.ArgumentParser()
125144 parser.add_argument("lines", type=Path)
@@ -142,14 +161,7 @@ def main() -> None:
142161 manifest_path = args.out / "voice-manifest.json"
143162 old = {e["text"]: e for e in json.loads(manifest_path.read_text())} if manifest_path.exists() else {}
144163
145 kept, todo = [], []
146 for text in lines:
147 entry = old.get(text)
148 if entry and text not in args.redo and entry.get("engine") == MODEL and (args.out / entry["file"]).exists():
149 kept.append(entry)
150 else:
151 seed = entry["seed"] + 1 if entry and text in args.redo else 0
152 todo.append((text, seed))
164 kept, todo = plan(lines, old, args.out, args.redo)
153165
154166 def job(item):
155167 text, seed = item
@@ -167,10 +179,7 @@ def main() -> None:
167179 write_manifest(manifest_path, kept + done + [e for t, e in old.items() if t not in fresh and e not in kept])
168180
169181 entries = kept + done
170 keep = {e["file"] for e in entries}
171 for stale in [*args.out.glob("*.aac"), *args.out.glob("*.m4a")]:
172 if stale.name not in keep:
173 stale.unlink()
182 remove_stale(args.out, {e["file"] for e in entries})
174183 write_manifest(manifest_path, entries)
175184 print(f"{len(done)} rendered, {len(kept)} kept")
176185