We are using WkWebView for our IOS APP. When user scrolls the webpage, goes to another page and revisits again the page UI breaks or sometimes goes blank. But when again started scrolling, UI restores. How to fix this? Following is the code
func createWebView(container: UIView, WKSMH: WKScriptMessageHandler, WKND: WKNavigationDelegate, NSO: NSObject, VC: ViewController) -> WKWebView{
let config = WKWebViewConfiguration()
let userContentController = WKUserContentController()
userContentController.add(WKSMH, name: "setUserAttribute")
userContentController.add(WKSMH, name: "print")
config.userContentController = userContentController
if #available(iOS 14, *) {
config.limitsNavigationsToAppBoundDomains = true;
}
config.preferences.javaScriptCanOpenWindowsAutomatically = true
config.allowsInlineMediaPlayback = true
config.preferences.setValue(true, forKey: "standalone")
let webView = WKWebView(frame: calcWebviewFrame(webviewView: container, toolbarView: nil), configuration: config)
setCustomCookie(webView: webView)
webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
webView.isHidden = true;
webView.navigationDelegate = WKND;
webView.scrollView.bounces = false;
webView.allowsBackForwardNavigationGestures = true
webView.configuration.applicationNameForUserAgent = "Safari/604.1" // See https://github.com/pwa-builder/pwabuilder-ios/issues/30
webView.customUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1";
if #available(iOS 11.0, *) {
webView.scrollView.contentInsetAdjustmentBehavior = .never
} else {
// Fallback on earlier versions
}
webView.addObserver(NSO, forKeyPath: #keyPath(WKWebView.estimatedProgress), options: NSKeyValueObservingOptions.new, context: nil)
return webView
}