SPB Git

Repository Public License

Onboarding.swift 6.4 KB 133 lines swift

1import LunarDesign2import NavigatorCore3import SwiftUI45/// First-launch welcome: four short screens, skippable at any time. It never asks for an account or a key.6struct OnboardingView: View {7    @Environment(\.lunarTheme) private var theme8    @Environment(\.accessibilityReduceMotion) private var reduceMotion9    let environment: AppEnvironment10    let settings: AppSettings11    @State private var step = 012    private let stepCount = 41314    var body: some View {15        ZStack {16            BackdropView(density: 1.2, isAnimated: !reduceMotion)17            VStack(spacing: 0) {18                HStack {19                    Spacer()20                    Button(L("Skip")) { environment.completeOnboarding() }21                        .buttonStyle(.lunar(.secondary, size: .compact))22                        .accessibilityIdentifier("onboarding.skip")23                }24                .padding(LunarSpacing.md)25                ScrollView {26                    page27                        .frame(maxWidth: 560)28                        .padding(.horizontal, LunarSpacing.lg)29                        .padding(.vertical, LunarSpacing.md)30                        .frame(maxWidth: .infinity)31                        .id(step)32                        .lunarTransition(anchor: .center)33                }34                .scrollIndicators(.never)35                VStack(spacing: LunarSpacing.md) {36                    HStack(spacing: 6) {37                        ForEach(0..<stepCount, id: \.self) { index in38                            Capsule().fill(index == step ? theme.accent : theme.textPrimary.withAlpha(0.18))39                                .frame(width: index == step ? 22 : 7, height: 7)40                        }41                    }42                    .accessibilityHidden(true)43                    HStack(spacing: LunarSpacing.sm) {44                        if step > 0 {45                            Button(L("Back")) { step -= 1 }.buttonStyle(.lunar(.secondary, size: .large))46                                .accessibilityIdentifier("onboarding.back")47                        }48                        Button(step == stepCount - 1 ? L("Start Browsing") : L("Continue")) {49                            if step == stepCount - 1 { environment.completeOnboarding() } else { step += 1 }50                        }51                        .buttonStyle(.lunar(.primary, size: .large))52                        .keyboardShortcut(.defaultAction)53                        .accessibilityIdentifier("onboarding.continue")54                    }55                }56                .padding(.bottom, LunarSpacing.xl)57                .padding(.top, LunarSpacing.sm)58            }59        }60        .lunarAnimation(.smooth, value: step)61        .accessibilityElement(children: .contain)62        .accessibilityIdentifier("onboarding")63    }6465    @ViewBuilder private var page: some View {66        switch step {67        case 0:68            VStack(spacing: LunarSpacing.md) {69                ZStack {70                    LunarOrbitRings(count: 2).frame(width: 230, height: 230).opacity(0.7)71                    LunarMarkView(size: 128)72                }73                .accessibilityHidden(true)74                heading(L("Welcome to ORIX Navigator"),75                        L("A calm browser built around the page. Your tabs, your history and your settings stay on this device."))76            }77        case 1:78            VStack(spacing: LunarSpacing.md) {79                heading(L("Choose your look"), L("Twelve themes, each designed for light and dark. You can change it at any time in Settings."))80                LunarCard(padding: LunarSpacing.md, shape: .md) {81                    VStack(spacing: LunarSpacing.md) {82                        AppearancePicker(settings: settings)83                        ThemeGrid(settings: settings, minimumWidth: 84)84                    }85                }86            }87        case 2:88            VStack(spacing: LunarSpacing.md) {89                heading(L("Choose your search engine"), L("Used when what you type is not an address. Suggestions come from your own history and bookmarks only."))90                LunarCard(padding: LunarSpacing.xs, shape: .md) {91                    SearchEngineList(settings: settings, engines: SearchEngine.builtIn)92                }93            }94        default:95            VStack(spacing: LunarSpacing.md) {96                heading(L("Private by design"), L("What ORIX Navigator does, plainly."))97                LunarCard(padding: LunarSpacing.md, shape: .md) {98                    VStack(alignment: .leading, spacing: LunarSpacing.md) {99                        fact("person.crop.circle.badge.xmark", L("No account"), L("There is nothing to sign in to. The browser works as soon as you open it."))100                        fact("antenna.radiowaves.left.and.right.slash", L("No telemetry"), L("The app sends no usage data, no crash reports and no identifiers to anyone."))101                        fact("internaldrive", L("Your data stays on this device"), L("History, bookmarks, tabs and settings are stored locally. You can delete them at any time in Settings."))102                    }103                }104            }105        }106    }107108    private func heading(_ title: String, _ subtitle: String) -> some View {109        VStack(spacing: LunarSpacing.xs) {110            Text(title).lunarFont(.title).foregroundStyle(theme.textPrimary).multilineTextAlignment(.center)111                .fixedSize(horizontal: false, vertical: true)112                .accessibilityAddTraits(.isHeader)113                .accessibilityValue(L("Step %d of %d", step + 1, stepCount))114                .accessibilityIdentifier("onboarding.title")115            Text(subtitle).lunarFont(.body).foregroundStyle(theme.textSecondary).multilineTextAlignment(.center)116                .fixedSize(horizontal: false, vertical: true)117        }118    }119120    private func fact(_ symbol: String, _ title: String, _ text: String) -> some View {121        HStack(alignment: .top, spacing: LunarSpacing.sm) {122            LunarIconView(.symbol(symbol), size: 22).foregroundStyle(theme.accent)123                .frame(width: 40, height: 40)124                .background { Circle().fill(theme.selection) }125            VStack(alignment: .leading, spacing: 2) {126                Text(title).lunarFont(.headline).foregroundStyle(theme.textPrimary)127                Text(text).lunarFont(.callout).foregroundStyle(theme.textSecondary).fixedSize(horizontal: false, vertical: true)128            }129        }130        .accessibilityElement(children: .combine)131    }132}133
Files main
Menu

Theme