import SwiftUI import Translation struct RootView: View { @Environment(BrowserStore.self) private var store @Environment(\.colorScheme) private var scheme var body: some View { withSheets } private var core: some View { ZStack { // Behind the page while search is open, so the page reads as a card stepping back. if store.showSearch { ArcBackdrop().transition(.opacity) } PageLayer() .clipShape(RoundedRectangle(cornerRadius: store.showSearch ? 44 : 0, style: .continuous)) .scaleEffect(store.showSearch ? 0.93 : 1, anchor: .top) .offset(y: store.showSearch ? 54 : 0) .overlay { Color.black.opacity(store.showSearch ? 0.3 : 0).clipShape(RoundedRectangle(cornerRadius: 44, style: .continuous)).allowsHitTesting(false) } .ignoresSafeArea() .animation(.spring(response: 0.5, dampingFraction: 0.88), value: store.showSearch) if store.browse.isPresented { BrowseView() } // The tab switcher sits under the bar, whose buttons glide to the corners. if store.showTabs { TabSwitcher().transition(.opacity.combined(with: .scale(scale: 1.04))) } if !store.tools.hideActive && !store.tools.inspectActive { BottomChrome() .opacity(store.showSearch ? 0 : 1) .allowsHitTesting(!store.showSearch) } if store.showPageMenu { PageMenu().transition(.move(edge: .bottom).combined(with: .opacity)) } if store.tools.hideActive { HideElementsOverlay() } if store.tools.inspectActive { InspectorOverlay() } if store.showSearch { SearchSheet().transition(store.menuToSearch ? .opacity : .move(edge: .bottom).combined(with: .opacity)) } if store.showVoice { VoiceSearchView().transition(.opacity) } if store.showReader, let tab = store.current { ReaderView(tab: tab).transition(.opacity) } // It animates itself in from the page; leaving, it fades. if store.ai.isPresented { SummaryView().transition(.asymmetric(insertion: .identity, removal: .opacity)) } FindBar() BannerHost() if store.privateLocked { PrivateLockView() } if !store.settings.hasOnboarded { OnboardingView().transition(.opacity) } } .animation(.spring(response: 0.45, dampingFraction: 0.86), value: store.showSearch) .animation(.spring(response: 0.48, dampingFraction: 0.86), value: store.showTabs) .animation(.spring(response: 0.42, dampingFraction: 0.88), value: store.showPageMenu) .animation(.easeInOut(duration: 0.3), value: store.showVoice) .animation(.easeInOut(duration: 0.3), value: store.browse.isPresented) .animation(.easeInOut(duration: 0.25), value: store.showReader) .animation(.easeOut(duration: 0.3), value: store.ai.isPresented) .animation(.easeInOut(duration: 0.3), value: store.settings.hasOnboarded) } private var withSheets: some View { @Bindable var store = store return core .sheet(isPresented: $store.showSettings) { SettingsView() } .sheet(isPresented: $store.showSiteSettings) { SiteSettingsSheet() } .sheet(isPresented: $store.showArchive) { ArchiveView().presentationDetents([.medium, .large]) } .sheet(isPresented: $store.showDownloads) { DownloadsView().presentationDetents([.medium, .large]) } .sheet(item: Binding(get: { store.tools.fontInfo.map(FontInfoBox.init) }, set: { if $0 == nil { store.tools.fontInfo = nil } })) { box in FontInfoSheet(info: box.info).presentationDetents([.medium, .large]) } .sheet(isPresented: Binding(get: { store.tools.showPageColors }, set: { store.tools.showPageColors = $0 })) { PageColorsSheet().presentationDetents([.medium, .large]) } .sheet(isPresented: Binding(get: { store.tools.showHiddenList }, set: { store.tools.showHiddenList = $0 })) { HiddenListSheet().presentationDetents([.medium]) } .translationTask(store.translationConfig) { session in await store.performTranslation(session) } .tint(Color(hex: 0x4C5BFF)) } } struct FontInfoBox: Identifiable { let id = UUID() let info: FontInfo } // MARK: - Page layer private struct PageLayer: View { @Environment(BrowserStore.self) private var store var body: some View { ZStack { if let tab = store.current { if tab.isBlank { HomeView(tab: tab) } else { WebContainer(tab: tab) } } } .background(Color(.systemBackground)) } } /// Hosts the current tab's WKWebView and tells it which parts of the screen Halcyon's bar covers. struct WebContainer: UIViewRepresentable { let tab: WebTab @Environment(BrowserStore.self) private var store func makeUIView(context: Context) -> WebHost { WebHost() } func updateUIView(_ host: WebHost, context: Context) { let wv = tab.ensureWebView() host.show(wv) host.bar = store.tools.hideActive || store.tools.inspectActive ? .none : (tab.barHidden ? .compact : .full) host.setNeedsLayout() tab.applySettingsToWebView(wv) } } final class WebHost: UIView { /// How much of the bottom the bar takes: the full bar, the compact domain pill while scrolling, or nothing. enum BarSpace { case full, compact, none } private weak var current: HWebView? var bar: BarSpace = .full func show(_ wv: HWebView) { guard current !== wv else { return } current?.removeFromSuperview() wv.removeFromSuperview() addSubview(wv) current = wv setNeedsLayout() } override func layoutSubviews() { super.layoutSubviews() guard let wv = current else { return } wv.frame = bounds // The bar's own height (see BottomChrome): the full bar reaches up from the screen's bottom edge, the // collapsed one is a thin sliver over the home indicator, and with no bar only the safe area is left. let safe = safeAreaInsets.bottom let bottomInset: CGFloat = switch bar { case .full: BottomChrome.inset(safe: safe) case .compact: BottomChrome.compactInset(safe: safe) case .none: safe } // Obscured insets shrink the page's viewport, so fixed and sticky elements (a site's own bottom // bar, say) stay clear of the status bar and of Halcyon's bar instead of sitting under them. let insets = UIEdgeInsets(top: safeAreaInsets.top, left: 0, bottom: bottomInset, right: 0) // The scroll view needs the same insets, or it can only scroll back to 0 and the top of the page // stays under the status bar. A page at the top stays at the top when the bar changes. if wv.obscuredContentInsets != insets { let sv = wv.scrollView let wasAtTop = sv.contentOffset.y <= -sv.adjustedContentInset.top + 1 wv.obscuredContentInsets = insets sv.contentInset = insets sv.verticalScrollIndicatorInsets = insets if wasAtTop { sv.contentOffset = CGPoint(x: sv.contentOffset.x, y: -insets.top) } } } } // MARK: - Home struct HomeView: View { let tab: WebTab @Environment(BrowserStore.self) private var store @State private var ripples = Ripples() var body: some View { ZStack { SkyBackground(ripples: ripples) VStack(spacing: 14) { Spacer() HalcyonMark(private: tab.isPrivate).frame(width: 112, height: 112) Spacer().frame(height: 22) Text(tab.isPrivate ? "Private tab" : "Want links to open in Halcyon?") .font(.system(size: 17, weight: .medium)) if !tab.isPrivate { Text("Make Halcyon your default browser and get an ad-free experience for every link.") .font(.system(size: 14)).foregroundStyle(.secondary).multilineTextAlignment(.center) .padding(.horizontal, 44) Button { if let u = URL(string: UIApplication.openSettingsURLString) { UIApplication.shared.open(u) } } label: { Text("Set Halcyon as Default Browser").font(.system(size: 15, weight: .medium)) .padding(.horizontal, 18).frame(height: 40) .background(Color.primary.opacity(0.14), in: RoundedRectangle(cornerRadius: 12, style: .continuous)) } .buttonStyle(.plain) .padding(.top, 4) } Spacer() Spacer().frame(height: BottomChrome.barHeight + 20) } } .contentShape(Rectangle()) .onTapGesture(coordinateSpace: .local) { point in ripples.add(at: point) store.openSearch() } } } /// Halcyon's mark: a kingfisher on a soft gradient tile. struct HalcyonMark: View { var `private` = false var body: some View { ZStack { RoundedRectangle(cornerRadius: 28, style: .continuous) .fill(LinearGradient(colors: `private` ? [Color(hex: 0x3A3A44), Color(hex: 0x1C1C22)] : [Arc.blue, Arc.violet, Arc.red], startPoint: .topLeading, endPoint: .bottomTrailing)) .overlay(RoundedRectangle(cornerRadius: 28, style: .continuous).strokeBorder(.white.opacity(0.25), lineWidth: 1)) .shadow(color: (`private` ? Color.black : Arc.violet).opacity(0.35), radius: 18, y: 8) Image(systemName: `private` ? "eyes" : "bird.fill").font(.system(size: 52, weight: .semibold)).foregroundStyle(.white) } } } /// Taps that ripple out through the dot grid. @MainActor @Observable final class Ripples { struct Ripple: Identifiable { let id = UUID() let center: CGPoint let start: Date } static let duration: TimeInterval = 1.1 private(set) var items: [Ripple] = [] func add(at point: CGPoint) { let now = Date() items.removeAll { now.timeIntervalSince($0.start) > Self.duration } items.append(Ripple(center: point, start: now)) Task { try? await Task.sleep(for: .seconds(Self.duration + 0.1)) items.removeAll { Date().timeIntervalSince($0.start) > Self.duration } } } } /// A quiet dot grid on gray: dark gray in dark mode, light gray in light mode. Taps send a wave of /// brighter dots out from where they land. struct SkyBackground: View { var ripples: Ripples? @Environment(\.colorScheme) private var scheme var body: some View { let dark = scheme == .dark TimelineView(.animation(paused: ripples?.items.isEmpty ?? true)) { timeline in Canvas { ctx, size in let now = timeline.date let waves = (ripples?.items ?? []).map { ($0.center, now.timeIntervalSince($0.start)) } let ink: Color = dark ? .white : .black let step: CGFloat = 22 var y: CGFloat = 11 while y < size.height { var x: CGFloat = 11 while x < size.width { var glow = 0.0 for (c, t) in waves where t < Ripples.duration { let d = hypot(x - c.x, y - c.y) let front = t * 700 let band = (Double(d) - front) / 46 glow += exp(-band * band) * (1 - t / Ripples.duration) } glow = min(1, glow) let r = 1 + glow * 1.6 let alpha = (dark ? 0.10 : 0.12) + glow * (dark ? 0.75 : 0.55) ctx.fill(Path(ellipseIn: CGRect(x: x - r, y: y - r, width: r * 2, height: r * 2)), with: .color(ink.opacity(alpha))) x += step } y += step } } } .background { ArcBackdrop() } .ignoresSafeArea() } } // MARK: - Banners and lock struct BannerHost: View { @Environment(BrowserStore.self) private var store var body: some View { VStack(spacing: 10) { if let item = store.downloads.banner { DownloadBanner(item: item).transition(.move(edge: .top).combined(with: .opacity)) } if let b = store.banner { HStack(spacing: 10) { Image(systemName: b.symbol).font(.system(size: 15, weight: .semibold)) Text(b.text).font(.system(size: 15, weight: .medium)) if let t = b.actionTitle { Button(t) { b.action?(); store.banner = nil } .font(.system(size: 15, weight: .semibold)) .foregroundStyle(Color(hex: 0x4C5BFF)) } } .padding(.horizontal, 18).padding(.vertical, 12) .glassEffect(.regular, in: Capsule()) .transition(.move(edge: .top).combined(with: .opacity)) } Spacer() } .padding(.top, 8) .animation(.spring(response: 0.45, dampingFraction: 0.82), value: store.banner?.id) .animation(.spring(response: 0.45, dampingFraction: 0.82), value: store.downloads.banner?.id) .allowsHitTesting(store.banner?.action != nil || store.downloads.banner != nil) } } struct PrivateLockView: View { @Environment(BrowserStore.self) private var store var body: some View { ZStack { Rectangle().fill(.ultraThickMaterial).ignoresSafeArea() VStack(spacing: 18) { Image(systemName: "eyes").font(.system(size: 44)) Text("Private tabs are locked").font(.system(size: 22, weight: .semibold)) Button("Unlock") { store.unlockPrivate() } .buttonStyle(.glassProminent) Button("Close private tabs") { store.closeAll(private: true); store.privateLocked = false } .font(.system(size: 15)).foregroundStyle(.secondary) } } .onAppear { store.unlockPrivate() } } }