import SwiftUI import WebKit /// Signing in, rating, claiming and replying happen on the website, inside the app. /// Sign-in is passkeys only. The webcredentials associated domain (Docley.entitlements) lets WebAuthn run in this web view. struct WebSheet: View { let url: URL @Environment(\.dismiss) private var dismiss var body: some View { NavigationStack { WebView(url: url) .ignoresSafeArea(edges: .bottom) .navigationTitle("Docley").navigationBarTitleDisplayMode(.inline) .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() } } } } } } struct WebView: UIViewRepresentable { let url: URL func makeUIView(context: Context) -> WKWebView { let config = WKWebViewConfiguration() config.websiteDataStore = .default() // keeps the Docley sign-in between visits let view = WKWebView(frame: .zero, configuration: config) view.isOpaque = false view.backgroundColor = .black view.navigationDelegate = context.coordinator view.load(URLRequest(url: url)) return view } func updateUIView(_ view: WKWebView, context: Context) {} func makeCoordinator() -> Coordinator { Coordinator() } final class Coordinator: NSObject, WKNavigationDelegate { // Stay on Docley; open everything else (sources, projectatom.ai) in Safari. func webView(_ webView: WKWebView, decidePolicyFor action: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { if let u = action.request.url, u.host != Site.base.host, action.navigationType == .linkActivated { UIApplication.shared.open(u); decisionHandler(.cancel); return } decisionHandler(.allow) } } }