Files
comaps/iphone/Maps/Bridging/EmbeddedSafariViewContent.swift
Yannik Bloscheck 48faa90b5e [ios] Switch About to SwiftUI
Signed-off-by: Yannik Bloscheck <git@yannikbloscheck.com>
2025-07-16 14:55:14 +02:00

60 lines
1.7 KiB
Swift

import SwiftUI
import WebKit
/// Content of the view for Safari via a WebKit view
struct EmbeddedSafariViewContent: UIViewRepresentable {
// MARK: Properties
/// If the content is loading
@Binding var isLoading: Bool
/// The view height
@Binding var height: CGFloat
/// If the view should resize itself to the height of the website content
var hasDynamicHeight: Bool = true
/// The url
let url: URL
// MARK: Methods
/// Create a coodindator for the WebKit view
func makeCoordinator() -> EmbeddedSafariViewCoordinator {
EmbeddedSafariViewCoordinator(self)
}
/// Create a WebKit view
/// - Parameter context: The context
/// - Returns: The WebKit view
func makeUIView(context: UIViewRepresentableContext<EmbeddedSafariViewContent>) -> WKWebView {
let uiView = WKWebView()
uiView.navigationDelegate = context.coordinator
uiView.scrollView.isScrollEnabled = !hasDynamicHeight
uiView.scrollView.showsHorizontalScrollIndicator = false
uiView.allowsBackForwardNavigationGestures = false
uiView.allowsLinkPreview = false
if #available(iOS 16.0, *) {
uiView.isFindInteractionEnabled = false
}
uiView.isOpaque = false
uiView.backgroundColor = .clear
uiView.underPageBackgroundColor = .clear
uiView.load(URLRequest(url: url))
return uiView
}
/// Update the WebKit view
/// - Parameter context: The context
func updateUIView(_ uiView: WKWebView, context: UIViewRepresentableContext<EmbeddedSafariViewContent>) {
uiView.load(URLRequest(url: url))
}
}