Repository Public
1import SwiftUI23/// All tabs as a grid of cards, with the regular / private switch.4struct TabOverview: View {5 @Bindable var model: BrowserModel6 let environment: MobileEnvironment7 @Environment(\.dismiss) private var dismiss8 @Environment(\.horizontalSizeClass) private var sizeClass9 @Environment(\.auraPolicy) private var policy1011 var body: some View {12 NavigationStack {13 ScrollView {14 if model.visibleTabs.isEmpty {15 ContentUnavailableView(model.showsPrivate ? L("No private tabs") : L("No tabs"), systemImage: model.showsPrivate ? "eyeglasses" : "square.on.square",16 description: Text(model.showsPrivate ? L("Private tabs are not kept in history and are never synchronized.") : L("Open a new tab to start browsing.")))17 .padding(.top, 80)18 } else {19 LazyVGrid(columns: [GridItem(.adaptive(minimum: sizeClass == .regular ? 220 : 150), spacing: 14)], spacing: 16) {20 ForEach(model.visibleTabs) { tab in21 TabCard(tab: tab, isSelected: tab.id == model.selectedTabID) { model.select(tab); dismiss() } close: { AuraMotion.perform(.spring) { model.close(tab) } }22 .transition(AuraTransition.morph(from: .center, policy))23 }24 }25 .padding(14)26 .auraAnimation(.spring, value: model.visibleTabs.map(\.id))27 }28 }29 .background((model.showsPrivate ? Aura.Palette.violet.opacity(0.14) : Color.clear).ignoresSafeArea())30 .background(Aura.Palette.chrome.ignoresSafeArea())31 .toolbar {32 ToolbarItem(placement: .principal) {33 Picker(L("Tabs"), selection: Binding(get: { model.showsPrivate }, set: { model.showsPrivate = $0 })) {34 Text(L("%d Tabs", model.regularTabs.count)).tag(false)35 Text(L("Private")).tag(true)36 }37 .pickerStyle(.segmented).frame(maxWidth: 280)38 .accessibilityIdentifier("private-toggle")39 }40 ToolbarItem(placement: .topBarLeading) {41 Menu {42 Button(role: .destructive) { model.closeAll(private: model.showsPrivate); if model.showsPrivate { model.showsPrivate = false } } label: {43 Label(model.showsPrivate ? L("Close All Private Tabs") : L("Close All Tabs"), systemImage: "xmark.square")44 }45 if !model.recentlyClosed.isEmpty, !model.showsPrivate {46 Button { model.reopenClosedTab(); dismiss() } label: { Label(L("Reopen Closed Tab"), systemImage: "arrow.uturn.backward") }47 }48 } label: { Image(systemName: "ellipsis.circle") }49 .accessibilityLabel(L("More"))50 }51 ToolbarItem(placement: .topBarTrailing) {52 HStack(spacing: 14) {53 // The spatial view of the same tabs; the grid stays the default.54 Button { model.selectedTab?.captureThumbnail(); model.showsOverviewConstellation = true } label: {55 Image(systemName: OrbitCatalog.symbol(.showConstellation)).foregroundStyle(Aura.gradient)56 }57 .accessibilityLabel(CommandID.showConstellation.title)58 .accessibilityIdentifier("constellation-button")59 Button(L("Done")) { finish() }.accessibilityIdentifier("tabs-done")60 }61 }62 ToolbarItem(placement: .bottomBar) {63 Button { model.newTab(isPrivate: model.showsPrivate); dismiss() } label: { Label(model.showsPrivate ? L("New Private Tab") : L("New Tab"), systemImage: "plus") }64 .labelStyle(.titleAndIcon).accessibilityIdentifier("new-tab")65 }66 }67 .navigationBarTitleDisplayMode(.inline)68 }69 .fullScreenCover(isPresented: $model.showsOverviewConstellation) {70 ConstellationScreen(model: model, onFinish: { model.showsOverviewConstellation = false; finish() },71 onDismiss: { model.showsOverviewConstellation = false })72 .auraRoot(decorative: environment.settings.ambientMotionEnabled)73 }74 }7576 /// Leaving the overview always lands on a tab of the set being shown.77 private func finish() {78 if model.selectedTab?.isPrivate != model.showsPrivate {79 if let tab = model.visibleTabs.max(by: { $0.lastActive < $1.lastActive }) { model.select(tab) } else { model.newTab(isPrivate: model.showsPrivate) }80 }81 dismiss()82 }83}8485struct TabCard: View {86 let tab: MobileTab87 let isSelected: Bool88 let open: () -> Void89 let close: () -> Void9091 var body: some View {92 VStack(spacing: 0) {93 HStack(spacing: 6) {94 Image(systemName: tab.isSearchPage ? "magnifyingglass" : (tab.isPrivate ? "eyeglasses" : "globe")).font(.caption2).foregroundStyle(.secondary)95 Text(tab.displayTitle).font(.caption.weight(.medium)).lineLimit(1)96 Spacer(minLength: 0)97 Button(action: close) { Image(systemName: "xmark").font(.system(size: 10, weight: .bold)).frame(width: 24, height: 24).background(Circle().fill(Aura.Palette.hover)) }98 .buttonStyle(AuraPressStyle(scale: 0.85)).accessibilityLabel(L("Close Tab"))99 }100 .padding(.horizontal, 8).frame(height: 34)101 ZStack {102 Aura.Palette.surface103 if let image = tab.thumbnail {104 Image(uiImage: image).resizable().aspectRatio(contentMode: .fill).frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top).clipped()105 } else {106 VStack(spacing: 6) {107 Image(systemName: tab.isBlank ? "sparkle.magnifyingglass" : (tab.isSearchPage ? "magnifyingglass" : "globe")).font(.title2).foregroundStyle(.tertiary)108 Text(tab.isBlank ? "SP Browser" : tab.addressText).font(.caption2).foregroundStyle(.secondary).lineLimit(1).padding(.horizontal, 6)109 }110 }111 }112 .frame(height: 190)113 .clipped()114 }115 .clipShape(RoundedRectangle(cornerRadius: Aura.Radius.l, style: .continuous))116 .auraSurface(.panel, radius: Aura.Radius.l, tint: tab.isPrivate ? Aura.Palette.violet : nil, interactive: true, luminous: isSelected)117 .contentShape(Rectangle())118 .onTapGesture(perform: open)119 .contextMenu {120 if let url = tab.url, HistoryStore.isRecordable(url) { Button { PlatformActions.copy(url.absoluteString) } label: { Label(L("Copy Link"), systemImage: "doc.on.doc") } }121 Button(role: .destructive, action: close) { Label(L("Close Tab"), systemImage: "xmark") }122 }123 .accessibilityElement(children: .combine)124 .accessibilityLabel(tab.displayTitle)125 .accessibilityAddTraits(isSelected ? [.isSelected, .isButton] : .isButton)126 .accessibilityIdentifier("tab-card")127 }128}129