krz/daybyday

iOS app for children to learn days of the week, months, and seasons with audio assist.

clone: git clone https://gitbay.org/krz/daybyday.git

v1.3.2: TodayView.swift · raw

 1//
 2//  TodayView.swift
 3//  DayByDay
 4//
 5
 6import SwiftUI
 7
 8/// A single-screen summary of today: day of the week, date, month, and season.
 9/// The child taps the large card to hear "Today is [day], [month] [date]. It is [season]."
10struct TodayView: View {
11    @State private var isTapped = false
12
13    private var todayText: String {
14        let day = DayOfWeek.current.name
15        let month = MonthOfYear.current.name
16        let date = Calendar.current.component(.day, from: Date())
17        let season = Season.current.name
18        return "Today is \(day), \(month) \(date). It is \(season)."
19    }
20
21    var body: some View {
22        ScrollView {
23            VStack(spacing: 32) {
24                // Main today card
25                ZStack {
26                    RoundedRectangle(cornerRadius: 32, style: .continuous)
27                        .fill(Color.orange.gradient)
28                        .shadow(color: Color.orange.opacity(0.4), radius: 8, y: 4)
29
30                    VStack(spacing: 20) {
31                        Image(systemName: "sun.horizon.fill")
32                            .font(.system(size: 80))
33                            .foregroundStyle(.white)
34                            .symbolRenderingMode(.hierarchical)
35
36                        // Day of the week
37                        Text(DayOfWeek.current.name)
38                            .font(.system(size: 48, weight: .bold, design: .rounded))
39                            .foregroundStyle(.white)
40
41                        // Date number
42                        let dayNumber = Calendar.current.component(.day, from: Date())
43                        Text("\(dayNumber)")
44                            .font(.system(size: 72, weight: .heavy, design: .rounded))
45                            .foregroundStyle(.white.opacity(0.9))
46
47                        // Month and season
48                        HStack(spacing: 24) {
49                            Label(MonthOfYear.current.name, systemImage: MonthOfYear.current.symbol)
50                            Label(Season.current.name, systemImage: Season.current.symbol)
51                        }
52                        .font(.system(size: 24, weight: .semibold, design: .rounded))
53                        .foregroundStyle(.white.opacity(0.9))
54                    }
55                    .padding(.vertical, 32)
56                }
57                .frame(height: 420)
58                .scaleEffect(isTapped ? 1.08 : 1.0)
59                .rotation3DEffect(.degrees(isTapped ? 6 : 0), axis: (x: 1, y: 0, z: 0))
60                .animation(.spring(response: 0.35, dampingFraction: 0.5), value: isTapped)
61                .contentShape(RoundedRectangle(cornerRadius: 32, style: .continuous))
62                .onTapGesture {
63                    isTapped = true
64                    SpeechSynthesizer.shared.speak(todayText)
65                    DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
66                        isTapped = false
67                    }
68                }
69                .accessibilityLabel(todayText)
70                .accessibilityAddTraits(.isButton)
71
72                // Tap hint
73                Label("Tap to hear today", systemImage: "speaker.wave.2.fill")
74                    .font(.system(size: 22, weight: .medium, design: .rounded))
75                    .foregroundStyle(.secondary)
76            }
77            .padding(32)
78        }
79    }
80}
81
82#Preview {
83    TodayView()
84}