Refresh tabItem view

Hello,

I'm trying to show a pdf inside my app, using webkit, with the code below. When I open the app, everything is fine, but after I'm switching to another tab (another page), the content of the pdf doesn't show up (just the pages don't show up, but page counter is still there).

view(request: URLRequest(url: URL(string: "[the url to the pdf file]")!)).previewLayout(.fixed(width: .infinity, height: .infinity))
.tabItem {
     Image("Lyzeum")
     Text("Lyzeum")
}

Also the URLRequest function:

struct view : UIViewRepresentable {
    let request: URLRequest

    func makeUIView(context: Context) -> WKWebView  {
        return WKWebView()
    }
    func updateUIView(_ uiView: WKWebView, context: Context) {
        uiView.load(request)
    }
}

Where do you use view(request ? Could you show the complete code ? I suppose you would need a stat var to keep track of tab, but need to see complete code.

Here is the full code:

import SwiftUI

import WebKit



struct view : UIViewRepresentable {

    

    let request: URLRequest

    

    func makeUIView(context: Context) -> WKWebView  {

        return WKWebView()

    }

    

    func updateUIView(_ uiView: WKWebView, context: Context) {

        uiView.load(request)

    }

    

}



struct ContentView: View {

    var body: some View {

            TabView {

                view(request: URLRequest(url: URL(string: "[url for the pdf file]")!)).previewLayout(.fixed(width: .infinity, height: .infinity))

                    .tabItem {

                        Image("1")

                            .resizable()

                            .frame(width: .infinity, height: .infinity)

                        Text("Gymnasium")

                    }

                view(request: URLRequest(url: URL(string: "[url]")!)).previewLayout(.fixed(width: .infinity, height: .infinity))

                    .tabItem {

                        Image("2")

                        Text("Lyzeum")

                    }

                view(request: URLRequest(url: URL(string: "[url]")!)).previewLayout(.fixed(width: .infinity, height: .infinity))

                    .tabItem {

                        Image("3")

                        Text("Neuigkeiten")

                    }

            }

    }

}



#if DEBUG

struct ContentView_Previews : PreviewProvider {

    static var previews: some View {

        ContentView()

    }

}

#endif
Refresh tabItem view
 
 
Q