Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onRendered callback height is before when before height is larger than new actual height. #112

Open
cellgit opened this issue Apr 2, 2023 · 3 comments

Comments

@cellgit
Copy link

cellgit commented Apr 2, 2023

When embed in tableViewCell, need update everytimes after load markdown, but onRendered callback height is before when before height is larger than new actual height, so I add the below method to get the actual height

public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        // 获取内容实际高度
        webView.evaluateJavaScript("document.body.scrollHeight") { [unowned self] (result, error) in
            DispatchQueue.main.async { [unowned self] in
                if let tempHeight: Double = result as? Double {
                    let height = CGFloat(tempHeight) + 10
                    debugPrint("height ==== \(height)")
                    self.onRendered?(height)
                }
            }
        }
    }
@kasimok
Copy link

kasimok commented May 30, 2023

@cellgit
Bro, there is a wiser fix change the postDocumentHeight func to

const postDocumentHeight = () => {
    var _body = document.body;
    var _html = document.documentElement;
//    var height = Math.max(
//                          _body.scrollHeight,
//                          _body.offsetHeight,
//                          _html.clientHeight,
//                          _html.scrollHeight,
//                          _html.offsetHeight
//                          );
    var height = _html.offsetHeight;
    console.log(height)
    window?.webkit?.messageHandlers?.updateHeight?.postMessage(height);
};

@FirstStepzz
Copy link

@kasimok Why is my main.js compressed? Where can I see the source code?

@kasimok
Copy link

kasimok commented Jan 9, 2024

@kasimok Why is my main.js compressed? Where can I see the source code?

it is for performance concern, you can use tools like vscode to decompress it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants