@@ -33,6 +33,8 @@ final class IssueCommentHtmlCell: IssueCommentBaseCell, ListBindable, UIWebViewD
33
33
34
34
private static let ImgScheme = " freetime-img "
35
35
private static let HeightScheme = " freetime-hgt "
36
+ private static let JavaScriptHeight = " offsetHeight "
37
+
36
38
private static let htmlHead = """
37
39
<!DOCTYPE html><html><head><style>
38
40
* {margin: 0;padding: 0;}
@@ -80,9 +82,9 @@ final class IssueCommentHtmlCell: IssueCommentBaseCell, ListBindable, UIWebViewD
80
82
imgs[i].addEventListener('click', tapAction);
81
83
}
82
84
function onElementHeightChange(elm, callback) {
83
- var lastHeight = elm.offsetHeight , newHeight;
85
+ var lastHeight = elm. \( IssueCommentHtmlCell . JavaScriptHeight ) , newHeight;
84
86
(function run() {
85
- newHeight = elm.offsetHeight ;
87
+ newHeight = elm. \( IssueCommentHtmlCell . JavaScriptHeight ) ;
86
88
if(lastHeight != newHeight) {
87
89
callback(newHeight);
88
90
}
@@ -139,6 +141,15 @@ final class IssueCommentHtmlCell: IssueCommentBaseCell, ListBindable, UIWebViewD
139
141
}
140
142
}
141
143
144
+ // MARK: Private API
145
+
146
+ func changed( height: CGFloat ) {
147
+ guard isHidden == false , height != bounds. height else { return }
148
+
149
+ let size = CGSize ( width: contentView. bounds. width, height: CGFloat ( height) )
150
+ delegate? . webViewDidResize ( cell: self , html: body, cellWidth: size. width, size: size)
151
+ }
152
+
142
153
// MARK: ListBindable
143
154
144
155
func bindViewModel( _ viewModel: Any ) {
@@ -163,9 +174,7 @@ final class IssueCommentHtmlCell: IssueCommentBaseCell, ListBindable, UIWebViewD
163
174
return false
164
175
} else if url. scheme == IssueCommentHtmlCell . HeightScheme,
165
176
let heightString = url. host as NSString ? {
166
- webView. alpha = 1
167
- let size = CGSize ( width: contentView. bounds. width, height: CGFloat ( heightString. floatValue) )
168
- delegate? . webViewDidResize ( cell: self , html: body, cellWidth: size. width, size: size)
177
+ changed ( height: CGFloat ( heightString. floatValue) )
169
178
return false
170
179
}
171
180
@@ -182,6 +191,11 @@ final class IssueCommentHtmlCell: IssueCommentBaseCell, ListBindable, UIWebViewD
182
191
183
192
func webViewDidFinishLoad( _ webView: UIWebView ) {
184
193
webView. alpha = 1
194
+
195
+ if let heightString = webView
196
+ . stringByEvaluatingJavaScript ( from: " document.body. \( IssueCommentHtmlCell . JavaScriptHeight) " ) as NSString ? {
197
+ changed ( height: CGFloat ( heightString. floatValue) )
198
+ }
185
199
}
186
200
187
201
}
0 commit comments