How can add an ActivityIndicator (spinning wheel) to this WebView when it's loading a website?
Here's the code for the WebView:
import Foundation
import SwiftUI
import WebKit
struct WebView : UIViewRepresentable {
var url: String
func makeUIView(context: Context) -> WKWebView {
guard let url = URL(string: self.url) else {
return WKWebView()
}
let request = URLRequest(url: url)
let wkWebView = WKWebView()
wkWebView.load(request)
return wkWebView
}
func updateUIView(_ uiView: WKWebView, context: UIViewRepresentableContext <WebView>) {
}
}
And here's the code to show the WebView in another view and tell it what URL to load:
WebView(url: "https://www.google.com")
Thanks!
EDIT: I have to be able to pass the URL as a string like shown above when calling the WebView in another view. That way I can easily tell the WebView what URL to load, and place two instances of WebView() together in a view showing different websites like so:
VStack {
WebView(url: "https://www.google.com")
WebView(url: "https://www.bing.com")
}
You can use the following code it contains "UIActivityIndicatorView" and is handled with "WKNavigationDelegate"