This commit is contained in:
Suresh, Kamlesh 2020-08-24 22:09:03 -04:00
parent 61c3231965
commit db851b00a9

View File

@ -128,23 +128,31 @@ extension WebView : WKUIDelegate {
if !dynamicHeight { if !dynamicHeight {
return return
} }
/* was using "document.readyState" to check the state, while evaluateJavaScript "document.readyState",only works when webview contains userscrpt.otherwise, it would return WKErrorDomain Code=4 "A JavaScript exception occurred". /*
//TODO: Check and remove the comment
was using "document.readyState" to check the state,
while evaluateJavaScript "document.readyState",only works when webview contains userscrpt.otherwise, it would return WKErrorDomain Code=4 "A JavaScript exception occurred".
so webView.isLoading to check load finished state so webView.isLoading to check load finished state
*/ */
if !webView.isLoading { if !webView.isLoading {
webView.evaluateJavaScript("document.body.scrollHeight", completionHandler: { [weak self] (result, error) in webView.evaluateJavaScript("document.readyState", completionHandler: { (complete, error) in
guard let self = self else { if complete == nil {
return return
} }
let scrollHeight = self.webView?.scrollView.contentSize.height ?? 44.0 webView.evaluateJavaScript("document.body.scrollHeight", completionHandler: { [weak self] (result, error) in
if let height = result as? CGFloat, guard let self = self else {
height < scrollHeight { return
self.webViewHeight?.constant = height }
} else { let scrollHeight = self.webView?.scrollView.contentSize.height ?? 44.0
//if failed to get height from javascript, using scrollview.contensize's height if let height = result as? CGFloat,
self.webViewHeight?.constant = scrollHeight height < scrollHeight {
} self.webViewHeight?.constant = height
self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self) } else {
//if failed to get height from javascript, using scrollview.contensize's height
self.webViewHeight?.constant = scrollHeight
}
self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
})
}) })
} }
} }