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/Home/HomeView.swift

062549ad26607ce9e973ed2a9a7ef6f853885f83
daybyday/DayByDay/Home/HomeView.swift history · blame · raw

84 lines · 3157 bytes

2 symbols in this file
 1//
 2//  HomeView.swift
 3//  DayByDay
 4//
 5
 6import SwiftUI
 7
 8/// Today banner on top, then the topic grid.
 9struct HomeView: View {
10    @Environment(ProfileSession.self) private var session
11    @Environment(\.dynamicTypeSize) private var typeSize
12    @State private var showingParentArea = false
13
14    /// Two square tiles a row; one wide tile at the accessibility text sizes.
15    private var columns: [GridItem] {
16        Array(repeating: GridItem(.flexible(), spacing: 24), count: typeSize.isAccessibilitySize ? 1 : 2)
17    }
18
19    var body: some View {
20        NavigationStack {
21            ScrollView {
22                VStack(spacing: 24) {
23                    NavigationLink {
24                        TodayRoutineView().navigationTitle(Category.today.label)
25                    } label: {
26                        TodayBanner()
27                    }
28                    .buttonStyle(.plain)
29
30                    LazyVGrid(columns: columns, spacing: 24) {
31                        ForEach(Category.gridCases) { category in
32                            NavigationLink(value: category) {
33                                CategoryTile(category: category)
34                                    .aspectRatio(typeSize.isAccessibilitySize ? 2 : 1, contentMode: .fit)
35                            }
36                            .buttonStyle(.plain)
37                        }
38                    }
39
40                    footerButton("Grown-Ups", systemImage: "lock.fill") {
41                        showingParentArea = true
42                    }
43                }
44                .padding(24)
45            }
46            .navigationTitle("DayByDay")
47            .navigationDestination(for: Category.self) { category in
48                CategoryHubView(category: category)
49                    .navigationTitle(category.label)
50            }
51            .toolbar {
52                if session.profiles.count > 1, let current = session.current {
53                    ToolbarItem(placement: .topBarTrailing) {
54                        Button {
55                            session.current = nil
56                        } label: {
57                            AvatarBadge(avatar: current.avatar, color: current.color)
58                                .frame(width: 40, height: 40)
59                        }
60                        .accessibilityLabel("Switch child")
61                    }
62                }
63            }
64            .sheet(isPresented: $showingParentArea) {
65                GatedView(onCancel: { showingParentArea = false }) {
66                    ParentAreaView(onDone: { showingParentArea = false })
67                }
68            }
69        }
70    }
71
72    private func footerButton(_ title: String, systemImage: String, action: @escaping () -> Void) -> some View {
73        Button(action: action) {
74            Label(title, systemImage: systemImage)
75                .font(.system(.callout, design: .rounded, weight: .medium))
76                .foregroundStyle(.primary)
77                .frame(maxWidth: .infinity)
78                .padding(.vertical, 14)
79                .background(Color(.systemGray6))
80                .cornerRadius(16)
81        }
82        .buttonStyle(.plain)
83    }
84}