I create an application, with several tabs, for each tab there is a webview.
My webview:
struct WebView : UIViewRepresentable {
let request: URLRequest
func makeUIView(context: Context) -> WKWebView {
return WKWebView()
}
func updateUIView(_ uiView: WKWebView, context: Context) {
uiView.load(request)
}
}
The problem when im changing tab, the web view recreate again. I want create the webviews only once, then every time I change tab, it keeped state And webview will not recharge each time
My code:
struct ContentView: View {
var body: some View {
TabView {
WebView(request: URLRequest(url: URL(string: "https://www.google.com/")!))
.tabItem {
Image(systemName: "1.circle")
Text("Messenger")
}.tag(0)
WebView(request: URLRequest(url: URL(string: "https://facebook.com/login")!))
.tabItem {
Image(systemName: "2.circle")
Text("Trello")
}.tag(1)
}
}
}