Remove sheet safari presentation for iOS, to be able to handle all types of links

This commit is contained in:
Balazs Perlaki-Horvath 2024-06-10 11:55:36 +02:00
parent 4c6fc186a7
commit edc71f660e
3 changed files with 5 additions and 39 deletions

View File

@ -1,29 +0,0 @@
// This file is part of Kiwix for iOS & macOS.
//
// Kiwix is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// any later version.
//
// Kiwix is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Kiwix; If not, see https://www.gnu.org/licenses/.
import SafariServices
import SwiftUI
#if os(iOS)
struct SafariView: UIViewControllerRepresentable {
let url: URL
func makeUIViewController(context: Context) -> SFSafariViewController {
SFSafariViewController(url: url)
}
func updateUIViewController(_ uiViewController: SFSafariViewController, context: Context) { }
}
#endif

View File

@ -81,7 +81,10 @@ struct About: View {
}
.navigationTitle("settings.about.title".localized)
.navigationBarTitleDisplayMode(.inline)
.sheet(item: $externalLinkURL) { SafariView(url: $0) }
.onChange(of: externalLinkURL) { url in
guard let url = url else { return }
UIApplication.shared.open(url)
}
.task { await getDependencies() }
#endif
}

View File

@ -20,7 +20,6 @@ import Defaults
struct ExternalLinkHandler: ViewModifier {
@State private var isAlertPresented = false
@State private var activeAlert: ActiveAlert?
@State private var activeSheet: ActiveSheet?
@Binding var externalURL: URL?
enum ActiveAlert {
@ -67,20 +66,13 @@ struct ExternalLinkHandler: ViewModifier {
Text("external_link_handler.alert.not_loading.description".localized)
}
}
#if os(iOS)
.sheet(item: $activeSheet) { sheet in
if case .safari(let url) = sheet {
SafariView(url: url)
}
}
#endif
}
private func load(url: URL) {
#if os(macOS)
NSWorkspace.shared.open(url)
#elseif os(iOS)
activeSheet = .safari(url: url)
UIApplication.shared.open(url)
#endif
}
}