2020-06-30 15:22:23 +02:00
|
|
|
//
|
|
|
|
// SafariView.swift
|
|
|
|
// Multiplatform iOS
|
|
|
|
//
|
|
|
|
// Created by Stuart Breckenridge on 30/6/20.
|
|
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import SafariServices
|
|
|
|
|
|
|
|
|
|
|
|
private final class Safari: UIViewControllerRepresentable {
|
|
|
|
|
|
|
|
var urlToLoad: URL
|
|
|
|
|
|
|
|
init(url: URL) {
|
|
|
|
self.urlToLoad = url
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeUIViewController(context: Context) -> SFSafariViewController {
|
|
|
|
let viewController = SFSafariViewController(url: urlToLoad)
|
|
|
|
viewController.delegate = context.coordinator
|
|
|
|
return viewController
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateUIViewController(_ uiViewController: SFSafariViewController, context: Context) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeCoordinator() -> Coordinator {
|
|
|
|
Coordinator(self)
|
|
|
|
}
|
|
|
|
|
|
|
|
class Coordinator: NSObject, SFSafariViewControllerDelegate {
|
|
|
|
var parent: Safari
|
|
|
|
|
|
|
|
init(_ parent: Safari) {
|
|
|
|
self.parent = parent
|
|
|
|
}
|
|
|
|
|
|
|
|
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SafariView: View {
|
|
|
|
|
|
|
|
var url: URL
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
Safari(url: url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SafariView_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2021-02-22 03:00:40 +01:00
|
|
|
SafariView(url: URL(string: "https://netnewswire.com/")!)
|
2020-06-30 15:22:23 +02:00
|
|
|
}
|
|
|
|
}
|