← All repositories

reportage

A life-logging app for iPhone

git clone https://code.inqk.net/reportage.git


Reportage/Views/WelcomeView.swift (4232B)

1import SwiftUI
2
3/// Shown the first time the app is opened: what Reportage does, and why it's
4/// about to ask for location, notifications and Health. Continue asks for
5/// each in turn and closes once all are answered.
6struct WelcomeView: View {
7    @State private var isAsking = false
8    let onFinish: () -> Void
9
10    var body: some View {
11        VStack(spacing: 0) {
12            ScrollView {
13                WelcomeContent()
14                    .padding(.horizontal, Theme.margin)
15                    .padding(.top, Theme.pageTop)
16                    .padding(.bottom, Theme.blockGap)
17            }
18            .scrollBounceBehavior(.basedOnSize)
19            Button {
20                Task { await askAndFinish() }
21            } label: {
22                Text("Continue")
23                    .font(.body.weight(.semibold))
24                    .foregroundStyle(Theme.onAccent)
25                    .frame(maxWidth: .infinity, minHeight: 52)
26                    .background(Theme.accent, in: .capsule)
27            }
28            .buttonStyle(.plain)
29            .disabled(isAsking)
30            .padding(.horizontal, Theme.margin)
31            .padding(.vertical, 12)
32        }
33        .background(Theme.paper)
34        .foregroundStyle(Theme.ink)
35    }
36
37    private func askAndFinish() async {
38        isAsking = true
39        await FirstLaunch.ask()
40        onFinish()
41    }
42}
43
44/// The welcome's text, apart from its button so it can be rendered on its
45/// own.
46struct WelcomeContent: View {
47    var body: some View {
48        VStack(alignment: .leading, spacing: Theme.promptGap) {
49            Text("Reportage\(Text(".").foregroundStyle(Theme.mark))", comment: "The app's name on the welcome screen, with a coloured full stop")
50                .screenTitle()
51                .accessibilityLabel(Text("Reportage"))
52            Text(
53                "Throughout the day, Reportage will send notifications asking you to file a report."
54            )
55            .font(Theme.serif(.title3))
56            .fixedSize(horizontal: false, vertical: true)
57            VStack(alignment: .leading, spacing: Theme.blockGap) {
58                Text("Reportage will ask to use")
59                    .eyebrow()
60                WelcomePermission(
61                    title: "Location",
62                    systemImage: "location",
63                    detail:
64                        "Each report records your location and the weather. This includes Instant Reports."
65                )
66                WelcomePermission(
67                    title: "Notifications",
68                    systemImage: "bell",
69                    detail:
70                        "Prompts are delivered as system notifications. You can choose the frequency and the hours during which you want to be prompted in the Settings tab."
71                )
72                WelcomePermission(
73                    title: "Health",
74                    systemImage: "heart",
75                    detail:
76                        "Each report records your steps and other activity so far that day, and wake reports record how you slept. Health data stays on this iPhone."
77                )
78            }
79            Text("You can change these permissions at any time in the Settings app.")
80                .font(.footnote)
81                .foregroundStyle(Theme.muted)
82        }
83        .frame(maxWidth: .infinity, alignment: .leading)
84    }
85}
86
87/// One permission: what it is and what Reportage uses it for.
88private struct WelcomePermission: View {
89    let title: LocalizedStringKey
90    let systemImage: String
91    let detail: LocalizedStringKey
92
93    var body: some View {
94        HStack(alignment: .firstTextBaseline, spacing: Theme.iconGap) {
95            Image(systemName: systemImage)
96                .foregroundStyle(Theme.accent)
97                .frame(width: 24)
98                .accessibilityHidden(true)
99            VStack(alignment: .leading, spacing: Theme.lineGap) {
100                Text(title)
101                    .font(.headline)
102                Text(detail)
103                    .font(.subheadline)
104                    .foregroundStyle(Theme.muted)
105                    .fixedSize(horizontal: false, vertical: true)
106            }
107        }
108    }
109}
110
111#Preview {
112    WelcomeView {}
113}