@@ -31,8 +31,6 @@ private final class IssueCommentHtmlCellWebView: UIWebView {
3131
3232final class IssueCommentHtmlCell : IssueCommentBaseCell , ListBindable , UIWebViewDelegate {
3333
34- private static let WebviewKeyPath = #keyPath( UIWebView . scrollView. contentSize)
35-
3634 private static let ImgScheme = " freetime-img "
3735 private static let htmlHead = """
3836 <!DOCTYPE html><html><head><style>
@@ -97,7 +95,6 @@ final class IssueCommentHtmlCell: IssueCommentBaseCell, ListBindable, UIWebViewD
9795
9896 webView. backgroundColor = . clear
9997 webView. delegate = self
100- webView. addObserver ( self , forKeyPath: IssueCommentHtmlCell . WebviewKeyPath, options: [ . new] , context: nil )
10198
10299 let scrollView = webView. scrollView
103100 scrollView. scrollsToTop = false
@@ -110,10 +107,6 @@ final class IssueCommentHtmlCell: IssueCommentBaseCell, ListBindable, UIWebViewD
110107 fatalError ( " init(coder:) has not been implemented " )
111108 }
112109
113- deinit {
114- webView. removeObserver ( self , forKeyPath: IssueCommentHtmlCell . WebviewKeyPath)
115- }
116-
117110 override func prepareForReuse( ) {
118111 super. prepareForReuse ( )
119112 webView. isHidden = true
@@ -122,6 +115,7 @@ final class IssueCommentHtmlCell: IssueCommentBaseCell, ListBindable, UIWebViewD
122115 override func layoutSubviews( ) {
123116 super. layoutSubviews ( )
124117 if webView. frame != contentView. bounds {
118+ print ( " previous frame: \( webView. frame) " )
125119 webView. frame = contentView. bounds
126120 }
127121 }
@@ -161,20 +155,13 @@ final class IssueCommentHtmlCell: IssueCommentBaseCell, ListBindable, UIWebViewD
161155 }
162156
163157 func webViewDidFinishLoad( _ webView: UIWebView ) {
164- webView . isHidden = false
165- }
166-
167- // MARK: KVO
158+ // if the cell is hidden, its been put back in the reuse pool
159+ guard self . isHidden == false ,
160+ let contentHeight = webView . stringByEvaluatingJavaScript ( from : " document.body.offsetHeight " ) as NSString ?
161+ else { return }
168162
169- override func observeValue( forKeyPath keyPath: String ? , of object: Any ? , change: [ NSKeyValueChangeKey : Any ] ? , context: UnsafeMutableRawPointer ? ) {
170- if keyPath == IssueCommentHtmlCell . WebviewKeyPath {
171- delegate? . webViewDidResize (
172- cell: self ,
173- html: body,
174- cellWidth: contentView. bounds. width,
175- size: webView. scrollView. contentSize
176- )
177- }
163+ let size = CGSize ( width: contentView. bounds. width, height: CGFloat ( contentHeight. floatValue) )
164+ delegate? . webViewDidResize ( cell: self , html: body, cellWidth: size. width, size: size)
178165 }
179166
180167}
0 commit comments