Pulling down the Drop Down Notification Sheet Resets/Reloads the Swift WKWebView Content back to the top

Viewed 40

Demo Here How do i stop this reset and let the screen stay as it is even if i pull down the notifications screen?

Below code is what i use to display the html data thats coming from an API.i just pass the URL to this struct and this struct will take care of displaying the data.

struct URLView : UIViewRepresentable
{
    
    let request: URLRequest
    
    func makeUIView(context: Context) -> WKWebView { return WKWebView()
        
    }
    func updateUIView(_ uiView: WKWebView, context: Context) { uiView.load(request)
    
}
    
}
1 Answers

You are loading request each time SwiftUI updates view. This is not a good solution, coz there are a lot of cases that causes updates (size, orientation changes, etc.) Move your request loading to makeUIView

func makeUIView(context: Context) -> WKWebView {
    let webView = WKWebView()
    webView.load(request)
    return webView
}
Related