Merge branch 'bugfix/webView_scrollView_contentsize_2' into 'release/8_0_0'

fix

See merge request BPHV_MIPS/mvm_core_ui!572
This commit is contained in:
Hedden, Kyle Matthew 2020-08-25 19:41:36 -04:00
commit aed3f6b4cf

View File

@ -129,31 +129,30 @@ extension WebView : WKUIDelegate {
return return
} }
/* /*
//TODO: Check and remove the comment
was using "document.readyState" to check the state, 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". 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
*/ */
webView.evaluateJavaScript("document.readyState", completionHandler: { (complete, error) in if !webView.isLoading {
if complete == nil {
return
}
webView.evaluateJavaScript("document.body.scrollHeight", completionHandler: { [weak self] (result, error) in webView.evaluateJavaScript("document.body.scrollHeight", completionHandler: { [weak self] (result, error) in
guard let self = self else { guard let self = self else {
return return
} }
let scrollHeight = self.webView?.scrollView.contentSize.height ?? 44.0 MVMCoreDispatchUtility.performBlock(onMainThread: { [weak self] in
if let height = result as? CGFloat, guard let self = self else {
height < scrollHeight { return
}
if let height = result as? CGFloat {
self.webViewHeight?.constant = height self.webViewHeight?.constant = height
} else { } else {
//if failed to get height from javascript, using scrollview.contensize's height //if failed to get height from javascript, using scrollview.contensize's height
self.webViewHeight?.constant = scrollHeight self.webViewHeight?.constant = webView.scrollView.contentSize.height
} }
self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self) self.delegateObject?.moleculeDelegate?.moleculeLayoutUpdated(self)
}) })
}) })
} }
}
public func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) { public func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {