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/Profiles/ProfilePickerView.swift

main
daybyday/DayByDay/Profiles/ProfilePickerView.swift history · blame · raw

88 lines · 3144 bytes

2 symbols in this file
 1//
 2//  ProfilePickerView.swift
 3//  DayByDay
 4//
 5
 6import SwiftUI
 7
 8/// "Who's playing?" Big avatar tiles; no reading needed.
 9struct ProfilePickerView: View {
10    @Environment(ProfileSession.self) private var session
11    @State private var showingParentArea = false
12
13    private let columns = [GridItem(.adaptive(minimum: 140, maximum: 260), spacing: 28)]
14
15    var body: some View {
16        ScrollView {
17            MascotView(mood: .waving)
18                .frame(width: 120, height: 120)
19                .padding(.top, 16)
20            LazyVGrid(columns: columns, spacing: 28) {
21                ForEach(session.profiles) { profile in
22                    Button {
23                        SpeechSynthesizer.shared.speak(Lines.greeting(for: profile.name))
24                        session.select(profile)
25                    } label: {
26                        VStack(spacing: 12) {
27                            AvatarBadge(avatar: profile.avatar, color: profile.color)
28                            Text(profile.name)
29                                .font(.heading(26))
30                                .foregroundStyle(.primary)
31                        }
32                    }
33                    .buttonStyle(.plain)
34                    .accessibilityLabel(profile.name)
35                }
36            }
37            .padding(32)
38        }
39        .safeAreaInset(edge: .bottom) {
40            Button { showingParentArea = true } label: {
41                Text("Grown-Ups")
42                    .padding(.horizontal, 20)
43                    .frame(minHeight: 44)
44                    .contentShape(Rectangle())
45            }
46            .font(.system(.callout, design: .rounded, weight: .medium))
47            .foregroundStyle(.primary)
48            .padding(.bottom, 4)
49        }
50        .onAppear { SpeechSynthesizer.shared.speak(Lines.whoIsPlaying) }
51        .sheet(isPresented: $showingParentArea) {
52            GatedView(onCancel: { showingParentArea = false }) {
53                ParentAreaView(onDone: { showingParentArea = false })
54            }
55        }
56    }
57}
58
59/// First launch: a grown-up creates the first profile.
60struct ProfileSetupView: View {
61    @State private var started = false
62
63    var body: some View {
64        if started {
65            GatedView(onCancel: { started = false }) {
66                NavigationStack {
67                    ProfileEditorView(profile: nil)
68                }
69            }
70        } else {
71            CenteredScrollView {
72                VStack(spacing: 24) {
73                    MascotView(mood: .waving)
74                        .frame(width: 160, height: 160)
75                    Text("Welcome to Day By Day")
76                        .font(.heading(32))
77                    Text("Set up a profile for your child.")
78                        .font(.system(.title3, design: .rounded))
79                    Button("Get Started") { started = true }
80                        .buttonStyle(.borderedProminent)
81                        .font(.system(.title2, design: .rounded, weight: .semibold))
82                }
83                .padding(40)
84                .multilineTextAlignment(.center)
85            }
86        }
87    }
88}