Open legal links with in app sheets instead of external browser
This commit is contained in:
@@ -8,28 +8,85 @@
|
|||||||
|
|
||||||
import Compound
|
import Compound
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
import WebKit
|
||||||
|
|
||||||
struct LegalInformationScreen: View {
|
struct LegalInformationScreen: View {
|
||||||
let context: LegalInformationScreenViewModel.Context
|
let context: LegalInformationScreenViewModel.Context
|
||||||
@Environment(\.openURL) private var openURL
|
@Environment(\.openURL) private var openURL
|
||||||
|
|
||||||
|
/*
|
||||||
|
Letro: open legal info in a sheet instead of external browser
|
||||||
|
*/
|
||||||
|
@State private var browserURL: BrowserURL?
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Form {
|
Form {
|
||||||
Section {
|
Section {
|
||||||
ListRow(label: .plain(title: L10n.commonCopyright),
|
ListRow(label: .plain(title: L10n.commonCopyright),
|
||||||
kind: .button { openURL(context.viewState.copyrightURL) })
|
kind: .button { browserURL = BrowserURL(context.viewState.copyrightURL) })
|
||||||
ListRow(label: .plain(title: L10n.commonAcceptableUsePolicy),
|
ListRow(label: .plain(title: L10n.commonAcceptableUsePolicy),
|
||||||
kind: .button { openURL(context.viewState.acceptableUseURL) })
|
kind: .button { browserURL = BrowserURL(context.viewState.acceptableUseURL) })
|
||||||
ListRow(label: .plain(title: L10n.commonPrivacyPolicy),
|
ListRow(label: .plain(title: L10n.commonPrivacyPolicy),
|
||||||
kind: .button { openURL(context.viewState.privacyURL) })
|
kind: .button { browserURL = BrowserURL(context.viewState.privacyURL) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.compoundList()
|
.compoundList()
|
||||||
.navigationTitle(L10n.commonAbout)
|
.navigationTitle(L10n.commonAbout)
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
|
.sheet(item: $browserURL) { browserURL in
|
||||||
|
ElementNavigationStack {
|
||||||
|
LegalInformationWebView(url: browserURL.url)
|
||||||
|
.ignoresSafeArea(edges: .bottom)
|
||||||
|
.toolbar {
|
||||||
|
ToolbarItem(placement: .confirmationAction) {
|
||||||
|
Button(L10n.actionDone) {
|
||||||
|
self.browserURL = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Letro: open legal info in a sheet instead of external browser
|
||||||
|
*/
|
||||||
|
|
||||||
|
private struct BrowserURL: Identifiable {
|
||||||
|
let url: URL
|
||||||
|
var id: URL { url }
|
||||||
|
|
||||||
|
init(_ url: URL) {
|
||||||
|
self.url = url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct LegalInformationWebView: UIViewControllerRepresentable {
|
||||||
|
let url: URL
|
||||||
|
|
||||||
|
func makeUIViewController(context: Context) -> UIViewController {
|
||||||
|
let viewController = UIViewController()
|
||||||
|
let webView = WKWebView()
|
||||||
|
webView.allowsBackForwardNavigationGestures = true
|
||||||
|
webView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
|
||||||
|
viewController.view.addSubview(webView)
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
webView.topAnchor.constraint(equalTo: viewController.view.topAnchor),
|
||||||
|
webView.leadingAnchor.constraint(equalTo: viewController.view.leadingAnchor),
|
||||||
|
webView.trailingAnchor.constraint(equalTo: viewController.view.trailingAnchor),
|
||||||
|
webView.bottomAnchor.constraint(equalTo: viewController.view.bottomAnchor)
|
||||||
|
])
|
||||||
|
|
||||||
|
webView.load(URLRequest(url: url))
|
||||||
|
|
||||||
|
return viewController
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateUIViewController(_ uiViewController: UIViewController, context: Context) { }
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Previews
|
// MARK: - Previews
|
||||||
|
|
||||||
struct LegalInformationScreen_Previews: PreviewProvider, TestablePreview {
|
struct LegalInformationScreen_Previews: PreviewProvider, TestablePreview {
|
||||||
|
|||||||
Reference in New Issue
Block a user