Cotton code
105 lines · 4.5 KB · SwiftRaw
// The boot's gate inside Cotton Vault (SHAPES "Decided" 8 and 12; Android's// CardLook.Waiting and VaultCardLook): while the gate only waits, the app's// name centred in `large_title` on the flat ground, as the first frame is; a// gate with ways out stands on Vault's ground in its type and buttons, its// words and ways the core's (`GateSlip`), never on paper.#if os(iOS)import CottonKitimport SwiftUI/// The app's name on the flat ground: the first frame, and every wait.struct VaultLaunchName: View {    @Environment(\.vault) private var look    @Environment(\.colorScheme) private var scheme    var body: some View {        ZStack {            look.colour("background", scheme).ignoresSafeArea()            // Notes, Story and Days wait on their bare ground, as they launched (flavour.json `flat`, no word mark).            if VaultLook.saysItsName { Text(ShellLines.line(VaultLook.nameSet, VaultLook.namePath)).vault(look, "large_title") }        }        .accessibilityIdentifier("vault-launch")    }}struct VaultGateScreen: View {    let gate: HomeAnswer.Gate    let look: VaultLook    let onWayOut: (String) -> Void    @State private var copied = false    @State private var confirmingErase = false    @Environment(\.colorScheme) private var scheme    var body: some View {        Group {            if gate.ways_out.isEmpty {                VaultLaunchName()            } else {                slip(GateSlip.of(gate, copied: copied))            }        }        .environment(\.vault, look)        .overlay {            if confirmingErase {                VaultConfirmView(asking: VaultAsking(                    confirm: VaultConfirm(title: CottonStrings.eraseConfirmTitle, body: CottonStrings.eraseConfirmBody, yes: CottonStrings.eraseConfirmVerb, no: ""),                    tone: .danger) { yes in                        confirmingErase = false                        if yes { onWayOut("erase") }                    })                .environment(\.vault, look)            }        }        .accessibilityIdentifier(GateScreen.identifier(gate.stage))    }    private func slip(_ slip: GateSlip) -> some View {        ZStack {            look.colour("background", scheme).ignoresSafeArea()            ScrollView {                VStack(alignment: .leading, spacing: look.gap("m")) {                    Text(slip.title).vault(look, "title").fixedSize(horizontal: false, vertical: true)                        .accessibilityIdentifier(slip.titleIdentifier ?? "gate-title")                    Text(slip.sentence).vault(look, "body").fixedSize(horizontal: false, vertical: true)                        .accessibilityIdentifier(slip.sentenceIdentifier ?? "gate-sentence")                    if let figure = slip.figure {                        Text(figure).vault(look, "code").accessibilityIdentifier(slip.figureIdentifier ?? "gate-figure")                    }                    if let detail = slip.detail {                        Text(detail).vault(look, "row_detail", "secondary").fixedSize(horizontal: false, vertical: true)                            .textSelection(.enabled)                    }                    if let usually = slip.usually { Text(usually).vault(look, "label", "secondary") }                    if let note = slip.note { Text(note).vault(look, "row_detail", "secondary").fixedSize(horizontal: false, vertical: true) }                    VStack(spacing: look.gap("s")) {                        ForEach(slip.buttons, id: \.identifier) { button in                            VaultButton(label: button.label, tone: button.weight == .red ? .danger : button.weight == .ink ? .accent : .neutral,                                        fill: button.weight == .ink ? .main : .quiet, wide: true) {                                act(button.action)                            }                            .accessibilityIdentifier(button.identifier)                        }                    }                    .padding(.top, look.gap("l"))                }                .padding(.horizontal, look.gap("gutter"))                .padding(.vertical, look.gap("xxl"))                .frame(maxWidth: .infinity, alignment: .leading)            }        }    }    private func act(_ action: GateAction) {        switch action {        case .retry: onWayOut("retry")        case .resetKey: onWayOut("reset_key")        case .signOut: onWayOut("sign_out")        case .erase: confirmingErase = true        case .copyDetails:            UIPasteboard.general.string = gate.words.detail            copied = true        }    }}#endif