diff --git a/ElementX/Sources/Screens/Settings/LegalInformationScreen/View/LegalInformationScreen.swift b/ElementX/Sources/Screens/Settings/LegalInformationScreen/View/LegalInformationScreen.swift index b16b75319..242e90b03 100644 --- a/ElementX/Sources/Screens/Settings/LegalInformationScreen/View/LegalInformationScreen.swift +++ b/ElementX/Sources/Screens/Settings/LegalInformationScreen/View/LegalInformationScreen.swift @@ -8,28 +8,85 @@ import Compound import SwiftUI +import WebKit struct LegalInformationScreen: View { let context: LegalInformationScreenViewModel.Context @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 { Form { Section { 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), - kind: .button { openURL(context.viewState.acceptableUseURL) }) + kind: .button { browserURL = BrowserURL(context.viewState.acceptableUseURL) }) ListRow(label: .plain(title: L10n.commonPrivacyPolicy), - kind: .button { openURL(context.viewState.privacyURL) }) + kind: .button { browserURL = BrowserURL(context.viewState.privacyURL) }) } } .compoundList() .navigationTitle(L10n.commonAbout) .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 struct LegalInformationScreen_Previews: PreviewProvider, TestablePreview {