SPB Git

Repository Public

AuraSurfaces.swift 8.3 KB 176 lines swift

1import SwiftUI2import UIKit34// MARK: - Command Orbit and palette56/// Hosts Command Orbit (a sheet rising from the bottom on iPhone, a ring in the middle of the window on iPad)7/// and the compact command palette. Both run commands through `BrowserModel.perform`.8struct AuraCommandLayer: View {9    @Bindable var model: BrowserModel10    let environment: MobileEnvironment11    @Environment(\.horizontalSizeClass) private var sizeClass12    @Environment(\.auraPolicy) private var policy13    @State private var pull: CGFloat = 01415    private var compact: Bool { sizeClass == .compact }1617    var body: some View {18        ZStack(alignment: compact ? .bottom : .center) {19            if model.showsOrbit {20                Color.black.opacity(compact ? 0.30 : 0.16).ignoresSafeArea()21                    .onTapGesture { dismiss() }22                    .transition(.opacity)23                    .accessibilityLabel(L("Close")).accessibilityAddTraits(.isButton)24                    .accessibilityIdentifier("orbit-backdrop")25                if compact {26                    orbit27                        .frame(maxWidth: .infinity)28                        .auraSurface(.overlay, radius: Aura.Radius.xxl, tint: model.isPrivate ? Aura.Palette.violet : nil)29                        .padding(.horizontal, 8).padding(.bottom, 6)30                        .offset(y: pull)31                        .gesture(pullDown)32                        .transition(AuraTransition.rise(.bottom, policy))33                } else {34                    orbit.transition(policy.allowsSpatial ? .opacity.combined(with: .scale(scale: 0.86)) : .opacity)35                }36            }37        }38        .frame(maxWidth: .infinity, maxHeight: .infinity)39        .auraModal(isPresented: $model.showsPalette, maxWidth: 560, alignment: .top) { MobilePalette(model: model, environment: environment) }40        .onChange(of: model.showsOrbit) { _, shown in if !shown { pull = 0 } }41    }4243    private var orbit: some View {44        OrbitView(commands: OrbitCatalog.ring(for: model.orbitContext), isEnabled: model.isEnabled,45                  shortcut: { compact ? "" : (BrowserCommands.shortcuts[$0]?.display ?? "") },46                  onRun: model.orbitRun, onType: model.orbitHandOver, onDismiss: dismiss)47    }4849    private func dismiss() { AuraMotion.perform(.quick) { model.showsOrbit = false } }5051    /// The sheet follows the finger downwards and resists upwards; letting go either dismisses it or springs it back.52    private var pullDown: some Gesture {53        DragGesture(minimumDistance: 8)54            .onChanged { value in55                pull = value.translation.height >= 0 ? value.translation.height : CGFloat(GestureResolution.rubberBand(Double(value.translation.height), limit: 40))56            }57            .onEnded { value in58                let progress = Double(max(value.translation.height, 0) / 220)59                if GestureResolution.shouldCommit(progress: progress, velocity: Double(value.velocity.height / 220), threshold: 0.4) {60                    dismiss()61                } else {62                    withAnimation(AuraMotion.animation(.spring, policy: policy)) { pull = 0 }63                }64            }65    }66}6768/// The compact palette: every command this app supports, ranked by the shared catalog, then the open tabs.69/// "@" lists tabs only.70struct MobilePalette: View {71    @Bindable var model: BrowserModel72    let environment: MobileEnvironment73    @State private var query = ""74    @State private var selection = 075    @Environment(\.horizontalSizeClass) private var sizeClass7677    private var items: [AuraCommandItem] {78        let tabsOnly = query.hasPrefix("@")79        let needle = (tabsOnly ? String(query.dropFirst()) : query).trimmingCharacters(in: .whitespaces)80        var out: [AuraCommandItem] = []81        if !tabsOnly {82            let runnable = model.supportedCommands.filter { $0 != .commandPalette && $0 != .commandOrbit && model.isEnabled($0) }83            out += OrbitCatalog.rank(runnable, query: needle, recent: model.recentCommands).map { command in84                AuraCommandItem(id: "c:" + command.rawValue, symbol: OrbitCatalog.symbol(command), title: command.title,85                                trailing: sizeClass == .regular ? (BrowserCommands.shortcuts[command]?.display ?? "") : "")86            }87        }88        if tabsOnly || !needle.isEmpty {89            let lower = needle.lowercased()90            out += model.visibleTabs.filter { tab in91                tab.id != model.selectedTabID && (lower.isEmpty || tab.displayTitle.lowercased().contains(lower) || (tab.url?.absoluteString.lowercased().contains(lower) ?? false))92            }.map { tab in93                AuraCommandItem(id: "t:" + tab.id.uuidString, symbol: tab.isPrivate ? "eyeglasses" : "square.on.square", title: tab.displayTitle, subtitle: tab.addressText)94            }95        }96        return out97    }9899    var body: some View {100        AuraCommandPalette(query: $query, placeholder: L("Search commands and tabs"), items: items, selection: $selection,101                           hint: L("Type @ to list open tabs"), maxListHeight: sizeClass == .compact ? 300 : 380,102                           onRun: run, onDismiss: dismiss)103            .onAppear { query = model.palettePrefill; model.palettePrefill = "" }104            .accessibilityIdentifier("palette")105    }106107    private func dismiss() { AuraMotion.perform(.quick) { model.showsPalette = false } }108109    private func run(_ item: AuraCommandItem) {110        dismiss()111        if item.id.hasPrefix("c:"), let command = CommandID(rawValue: String(item.id.dropFirst(2))) {112            model.perform(command)113        } else if let id = UUID(uuidString: String(item.id.dropFirst(2))), let tab = model.tabs.first(where: { $0.id == id }) {114            model.select(tab)115        }116    }117}118119// MARK: - Full-screen and sheet surfaces120121/// Tab Constellation over the tab set on screen (regular or private). iOS has no tab groups: grouping and moving122/// a tab between constellations do nothing here.123struct ConstellationScreen: View {124    @Bindable var model: BrowserModel125    /// Leaves the constellation and everything it was opened from, landing on the selected tab.126    var onFinish: () -> Void127    /// "Done": back to where the constellation was opened from. Defaults to `onFinish`.128    var onDismiss: (() -> Void)?129130    var body: some View {131        ConstellationView(items: model.constellationItems, selectedID: model.selectedTabID, isPrivate: model.showsPrivate,132                          thumbnail: model.constellationThumbnail,133                          onOpen: { id in134                              if let tab = model.tabs.first(where: { $0.id == id }) { model.select(tab) }135                              onFinish()136                          },137                          onClose: model.constellationClose,138                          onGroup: { _ in },139                          onMove: { _, _ in },140                          onNewTab: { model.newTab(isPrivate: model.showsPrivate); onFinish() },141                          onDismiss: onDismiss ?? onFinish)142    }143}144145struct FlowSheet: View {146    @Bindable var model: BrowserModel147    let environment: MobileEnvironment148149    var body: some View {150        FlowMapView(trail: model.flowTrail, currentNodeID: model.flowCursor, isPrivate: model.isPrivate, isRecording: environment.settings.flowEnabled,151                    onOpen: model.flowOpen, onDeleteJourney: model.flowForget, onDismiss: { model.auraSurface = nil })152    }153}154155struct PortalSheet: View {156    @Bindable var model: BrowserModel157    let environment: MobileEnvironment158159    var body: some View {160        // Reading the revision refreshes the sheet when a synchronization brings new tabs or hand-offs.161        let _ = environment.services.libraryRevision162        PortalView(devices: environment.services.portalDevices, handoffs: model.isPrivate ? [] : environment.services.pendingHandoffs, host: model.portalHost)163    }164}165166/// The Focus Mode pill on a touch screen. The shared pill fades until a pointer approaches; with no pointer it needs167/// a backing of its own to stay legible over the page.168struct FocusControl: View {169    @Bindable var model: BrowserModel170171    var body: some View {172        FocusPill(title: model.selectedTab?.displayTitle ?? "", progress: model.focusProgress, onExit: { model.toggleFocusMode() })173            .background(RoundedRectangle(cornerRadius: 16, style: .continuous).fill(Aura.Palette.surface))174    }175}176
Files main
Menu

Theme