import SwiftUI struct WelcomeView: View { let account: AtlasAccount @Environment(\.colorScheme) private var colorScheme @ScaledMetric(relativeTo: .largeTitle) private var headlineSize = 38.0 @State private var showingGuide = false @AccessibilityFocusState private var errorFocused: Bool private var canvas: Color { colorScheme == .dark ? Color(uiColor: .systemBackground) : Color(red: 0.976, green: 0.969, blue: 0.951) } var body: some View { ScrollView { VStack(alignment: .leading, spacing: 22) { HStack(spacing: 9) { Image("BrandMark") .resizable() .frame(width: 32, height: 32) .clipShape(.rect(cornerRadius: 8)) .accessibilityHidden(true) Text("见物") .font(.headline) } VStack(alignment: .leading, spacing: 9) { Text("放在哪里,\n一找就知道。") .font(.system(size: headlineSize, weight: .bold)) .accessibilityAddTraits(.isHeader) Text("记下家里的东西和位置,下次需要时,搜一下就能找到。") .font(.subheadline) .foregroundStyle(.primary.opacity(0.72)) } Color.atlasBlue.opacity(0.08) .aspectRatio(1.9, contentMode: .fit) .overlay { GeometryReader { geometry in Image("WelcomeDrawer") .resizable() .scaledToFill() .frame(width: geometry.size.width, height: geometry.size.height) } } .clipShape(.rect(cornerRadius: 21)) .accessibilityHidden(true) VStack(alignment: .leading, spacing: 13) { WelcomeFeature(symbol: "magnifyingglass", title: "搜名字就能找", detail: "从房间到抽屉,顺着位置就能拿到。") Divider().padding(.leading, 50) WelcomeFeature(symbol: "square.and.pencil", title: "一次记几件", detail: "把整理时记下的话变成草稿,核对后再保存。") Divider().padding(.leading, 50) WelcomeFeature(symbol: "person.2", title: "和家人一起找", detail: "用邀请码加入同一个空间。") } } .fixedSize(horizontal: false, vertical: true) .frame(maxWidth: 472, alignment: .leading) .padding(.horizontal, 24) .padding(.top, 12) .padding(.bottom, 20) .frame(maxWidth: .infinity) } .safeAreaInset(edge: .bottom, spacing: 0) { actions } .background(canvas.ignoresSafeArea()) .sheet(isPresented: $showingGuide) { WelcomeGuide() } .onChange(of: account.error) { _, error in if error != nil { errorFocused = true } } } private var actions: some View { VStack(spacing: 5) { if let error = account.error { Label(error, systemImage: "exclamationmark.circle") .font(.footnote) .foregroundStyle(.primary) .frame(maxWidth: .infinity, alignment: .leading) .padding(12) .background(.thinMaterial, in: .rect(cornerRadius: 12)) .accessibilityFocused($errorFocused) .padding(.bottom, 4) } Button { Task { await account.signIn() } } label: { HStack(spacing: 9) { if let progress = account.signInProgress { ProgressView().tint(.white).accessibilityHidden(true) Text(progress.title) } else { Text(account.error == nil ? "登录我的空间" : "重试登录") Image(systemName: "arrow.right") .font(.subheadline.weight(.semibold)) .accessibilityHidden(true) } } .font(.body.weight(.semibold)) .frame(maxWidth: .infinity, minHeight: 29) } .buttonStyle(.borderedProminent) .buttonBorderShape(.roundedRectangle(radius: 15)) .controlSize(.large) .disabled(account.signInProgress != nil) Button("看看怎么用") { showingGuide = true } .font(.subheadline.weight(.semibold)) .frame(minHeight: 44) .disabled(account.signInProgress != nil) } .frame(maxWidth: 472) .padding(.horizontal, 24) .padding(.top, 10) .frame(maxWidth: .infinity) .background(canvas) .overlay(alignment: .top) { Divider() } } } private struct WelcomeFeature: View { let symbol: String let title: String let detail: String @Environment(\.colorScheme) private var colorScheme private var iconColor: Color { colorScheme == .dark ? Color(red: 0.58, green: 0.67, blue: 1) : .atlasBlue } var body: some View { HStack(alignment: .top, spacing: 12) { Image(systemName: symbol) .font(.system(size: 17, weight: .medium)) .foregroundStyle(iconColor) .frame(width: 38, height: 38) .background(iconColor.opacity(0.12), in: .rect(cornerRadius: 12)) .accessibilityHidden(true) VStack(alignment: .leading, spacing: 3) { Text(title).font(.subheadline.weight(.semibold)) Text(detail).font(.footnote).foregroundStyle(.primary.opacity(0.72)) } } .accessibilityElement(children: .combine) } } private struct WelcomeGuide: View { @Environment(\.dismiss) private var dismiss var body: some View { NavigationStack { ScrollView { VStack(alignment: .leading, spacing: 24) { WelcomeFeature(symbol: "tray", title: "整理时记下位置", detail: "给常用物品写下名称和位置。一次整理了好几件,也可以先生成草稿,再逐件核对。") WelcomeFeature(symbol: "magnifyingglass", title: "需要时搜一下", detail: "可以搜物品的名字,也可以搜平时的叫法。结果会显示它放在哪个房间、哪层柜子。") WelcomeFeature(symbol: "person.2", title: "跟家人用同一个空间", detail: "登录后可以新建自己的空间,也可以用邀请码加入家人的空间。") } .frame(maxWidth: .infinity, alignment: .leading) .padding(24) } .navigationTitle("怎么用见物") .navigationBarTitleDisplayMode(.inline) .toolbar { ToolbarItem(placement: .confirmationAction) { Button("完成") { dismiss() } } } } } }