import RastrilloApple import SwiftUI /// The iPhone's first screen (A, mockup `phone-ask`): Ask. Round glass /// buttons for the apps (left, with a dot while a job waits on the person) /// and the person (right, the account's menu); "Ask Base" with the team /// under it; then the conversation and the composer, which rides above /// the keyboard. public struct PhoneAskScreen: View { let me: Me? let home: HomeData? let ask: AskModel? let transport: NativeTransport? let actions: BaseActions @State private var appsShown: Bool @State private var switching = false @State private var confirmingSignOut = false @Environment(\.colorScheme) private var scheme public init(me: Me?, home: HomeData?, ask: AskModel?, transport: NativeTransport?, actions: BaseActions, appsShown: Bool = false) { self.me = me; self.home = home; self.ask = ask; self.transport = transport; self.actions = actions _appsShown = State(initialValue: appsShown) } public var body: some View { let p = Palette(scheme) ZStack { Sky() VStack(spacing: 0) { bar(p) Group { if let ask { AskView(model: ask, layout: .phone, timeZone: me?.base.timeZone, actions: AskActions(setUp: actions.setUpAsk, setUpOnWeb: actions.setUpAskOnWeb)) } else { Color.clear } } .frame(maxWidth: .infinity, maxHeight: .infinity) // The sheet's lower corners run off the screen; Ask stays on it. .padding(.bottom, 26) .glassSheet(cornerRadius: 26) .padding(.horizontal, 8) .padding(.bottom, -26) } } .foregroundStyle(p[.frost]) .scrollDismissesKeyboard(.interactively) .sheet(isPresented: $appsShown) { AppsSheet(me: me, home: home, transport: transport, actions: actions) { appsShown = false } .presentationDetents([.medium, .large]) .presentationDragIndicator(.visible) .presentationBackground { Palette(scheme)[.menuBase] } } .accountChoices(actions: actions, switching: $switching, confirmingSignOut: $confirmingSignOut) } private func bar(_ p: Palette) -> some View { HStack(spacing: 10) { Button { appsShown = true } label: { RoundGlass { Image(systemName: "square.grid.2x2").font(.system(size: 18, weight: .medium)) } .overlay(alignment: .topTrailing) { if (ask?.waitingJobs ?? 0) > 0 { Circle().fill(p[.stAsk]).frame(width: 10, height: 10) .overlay { Circle().strokeBorder(p[.sky2], lineWidth: 2) } .offset(x: -6, y: 6) } } } .buttonStyle(.plain) .accessibilityLabel(Text(BaseText.text("native.phone.apps_a11y"))) .accessibilityValue(Text((ask?.waitingJobs ?? 0) > 0 ? BaseText.plural("native.sidebar.ask.badge_a11y", ask?.waitingJobs ?? 0) : "")) VStack(spacing: 1) { HStack(spacing: 7) { BaseMark(size: 14) Text(BaseText.text("native.sidebar.ask")).font(BaseFont.heading(17, .semibold, relativeTo: .headline)) } Text(verbatim: me?.base.name ?? "").font(BaseFont.body(12, relativeTo: .caption)).foregroundStyle(p[.haze]) } .frame(maxWidth: .infinity) .accessibilityElement(children: .combine) .accessibilityAddTraits(.isHeader) Menu { AccountMenuItems(actions: actions, switching: $switching, confirmingSignOut: $confirmingSignOut) } label: { RoundGlass { Avatar(me?.member.initials ?? "", size: 32) } } .accessibilityLabel(Text(BaseText.text("native.phone.account_a11y"))) } .padding(.horizontal, 14) .frame(minHeight: 56) } } /// A round glass button: 44 pt. struct RoundGlass: View { @ViewBuilder let content: Content var body: some View { content.frame(width: 44, height: 44).glass(cornerRadius: 22).contentShape(Circle()) } } /// The Apps sheet (mockup `phone-apps`): the team's name, Getting started /// while a step is open, and every app in four columns, Base's own pages /// (Store, People, Settings) on a row of their own; each opens through /// Opener (P12). public struct AppsSheet: View { let me: Me? let home: HomeData? let transport: NativeTransport? let actions: BaseActions let close: () -> Void @Environment(\.colorScheme) private var scheme @Environment(\.dynamicTypeSize) private var typeSize public init(me: Me?, home: HomeData?, transport: NativeTransport?, actions: BaseActions, close: @escaping () -> Void) { self.me = me; self.home = home; self.transport = transport; self.actions = actions; self.close = close } public var body: some View { let p = Palette(scheme) ScrollView { VStack(alignment: .leading, spacing: 14) { HStack(spacing: 10) { Text(verbatim: me?.base.name ?? "").font(BaseFont.heading(20, .semibold, relativeTo: .title3)) .accessibilityAddTraits(.isHeader) Spacer() Button(action: close) { Icon(.close).frame(width: 18, height: 18).frame(width: 36, height: 36) .background(p[.chip], in: Circle()).overlay { Circle().strokeBorder(p[.chipEdge], lineWidth: 1) } .frame(width: 44, height: 44).contentShape(Circle()) } .buttonStyle(.plain) .accessibilityLabel(Text(BaseText.text("native.phone.apps.close_a11y"))) } if let home, home.stepsOpen { FlowLayout(spacing: 6) { ForEach(home.steps, id: \.self) { step in HStack(spacing: 8) { StepDot(done: step.done, size: 18) Text(verbatim: step.label).font(BaseFont.body(13, relativeTo: .footnote)) } .padding(.vertical, 7).padding(.horizontal, 11) .glass(cornerRadius: 12) .accessibilityElement(children: .combine) .accessibilityAddTraits(step.done ? .isSelected : []) } } } if let home { grid(home.launchable) grid(home.own) } } .padding(.horizontal, 18).padding(.top, 20).padding(.bottom, 24) } .foregroundStyle(p[.frost]) .background(p[.menuBase]) } private func grid(_ apps: [HomeData.App]) -> some View { let columns = typeSize.isAccessibilitySize ? 2 : 4 return LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 0, alignment: .top), count: columns), spacing: 16) { ForEach(apps) { app in Button { actions.open(app) } label: { VStack(spacing: 6) { AppIcon(app, size: 60, transport: transport) Text(verbatim: app.name).font(BaseFont.body(12, .medium, relativeTo: .caption)) .lineLimit(2).multilineTextAlignment(.center) } .frame(maxWidth: .infinity) .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(Text(verbatim: app.name)) } } } }