@@ -31,8 +31,6 @@ private final class IssueCommentHtmlCellWebView: UIWebView {
31
31
32
32
final class IssueCommentHtmlCell : IssueCommentBaseCell , ListBindable , UIWebViewDelegate {
33
33
34
- private static let WebviewKeyPath = #keyPath( UIWebView . scrollView. contentSize)
35
-
36
34
private static let ImgScheme = " freetime-img "
37
35
private static let htmlHead = """
38
36
<!DOCTYPE html><html><head><style>
@@ -97,7 +95,6 @@ final class IssueCommentHtmlCell: IssueCommentBaseCell, ListBindable, UIWebViewD
97
95
98
96
webView. backgroundColor = . clear
99
97
webView. delegate = self
100
- webView. addObserver ( self , forKeyPath: IssueCommentHtmlCell . WebviewKeyPath, options: [ . new] , context: nil )
101
98
102
99
let scrollView = webView. scrollView
103
100
scrollView. scrollsToTop = false
@@ -110,10 +107,6 @@ final class IssueCommentHtmlCell: IssueCommentBaseCell, ListBindable, UIWebViewD
110
107
fatalError ( " init(coder:) has not been implemented " )
111
108
}
112
109
113
- deinit {
114
- webView. removeObserver ( self , forKeyPath: IssueCommentHtmlCell . WebviewKeyPath)
115
- }
116
-
117
110
override func prepareForReuse( ) {
118
111
super. prepareForReuse ( )
119
112
webView. isHidden = true
@@ -122,6 +115,7 @@ final class IssueCommentHtmlCell: IssueCommentBaseCell, ListBindable, UIWebViewD
122
115
override func layoutSubviews( ) {
123
116
super. layoutSubviews ( )
124
117
if webView. frame != contentView. bounds {
118
+ print ( " previous frame: \( webView. frame) " )
125
119
webView. frame = contentView. bounds
126
120
}
127
121
}
@@ -161,20 +155,13 @@ final class IssueCommentHtmlCell: IssueCommentBaseCell, ListBindable, UIWebViewD
161
155
}
162
156
163
157
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 }
168
162
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)
178
165
}
179
166
180
167
}
0 commit comments