keitaoouchi / MarkdownView

Markdown View for iOS.
MIT License
1.98k stars 213 forks source link

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

Open cellgit opened 1 year ago

cellgit commented 1 year ago

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 commented 1 year ago

@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 commented 9 months ago

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

kasimok commented 9 months ago

@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.