I already saw this and this and this but I couldn't apply the answers to my problem.
I am new to swiftui so I'm not sure how to get this done. In my app, I need to display some HTML content so I created a UIViewRepresentable like below:
import SwiftUI
import WebKit
struct HTMLStringView: UIViewRepresentable {
let htmlContent: String
func makeUIView(context: Context) -> WKWebView {
return WKWebView()
}
func updateUIView(_ uiView: WKWebView, context: Context) {
uiView.loadHTMLString(htmlContent, baseURL: nil)
}
}
and I display it in my view like so:
HTMLStringView(htmlContent: "HTML String")
The problem is that some of the HTML content have links and they open within the view. How can I open the links in Safari Browser or at least a sheet instead if the link is reachable or valid?