[TIMOB-14993] iOS: Ti.UI.SIZE height of a WebView is incorrectly calculated
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | High |
| Status | Closed |
| Resolution | Invalid |
| Resolution Date | 2013-10-09T21:16:07.000+0000 |
| Affected Version/s | Release 3.1.1 |
| Fix Version/s | 2013 Sprint 21, 2013 Sprint 21 API |
| Components | iOS |
| Labels | ios, ipass1, regression |
| Reporter | Matthew Delmarter |
| Assignee | Vishal Duggal |
| Created | 2013-07-31T05:15:40.000+0000 |
| Updated | 2017-04-10T08:15:46.000+0000 |
Description
I have typed up a detailed description here:
https://developer.appcelerator.com/question/155469/tiuisize-is-not-working-for-a-webviews-height-any-more-sample-code-included
Basically when trying to use Ti.UI.SIZE to automatically size the Height of a WebView to fit the contents, it does not work when spaces are included in the HTML string. No spaces - it works fine. Spaces included - the height of the WebView is far too large.
You can see a screenshot example here:
http://www.imattsolutions.com/images/TiWebView_Height.png
Here is some example code you can run in a new Project's app.js using 3.1.1 SDK:
var win = Ti.UI.createWindow({
backgroundColor:'#ffffff'
});
var html = 'This is not ok.';
var view = Ti.UI.createWebView({
html: html,
height: Ti.UI.SIZE,
width: Ti.UI.FILL,
top: 0,
backgroundColor:'red'
});
win.add(view);
win.open();
Note: This used to work fine in SDK 2.1.4.
Attachments
| File | Date | Size |
|---|---|---|
| TiWebView_Height.png | 2013-07-31T05:15:40.000+0000 | 10661 |
I have fixed the issue in 3.1.1.GA by doing the following: In the SDK locate the file "iphone/Classes/TiUIWebView.m". Replace:
With:-(CGFloat)contentHeightForWidth:(CGFloat)value { CGRect oldBounds = [[self webview] bounds]; BOOL oldVal = webview.scalesPageToFit; [webview setScalesPageToFit:NO]; [webview setBounds:CGRectMake(0, 0, 10, 1)]; CGFloat ret = [webview sizeThatFits:CGSizeMake(10, 1)].height; [webview setBounds:oldBounds]; [webview setScalesPageToFit:oldVal]; return ret; }-(CGFloat)contentHeightForWidth:(CGFloat)value { CGRect oldBounds = [[self webview] bounds]; [webview setBounds:CGRectMake(0, 0, MAX(value,10), 1)]; CGFloat result = [[webview stringByEvaluatingJavaScriptFromString:@"document.height"] floatValue]; [webview setBounds:oldBounds]; return result; }[~srahim], thoughts?
Setting plain text without a proper mime type will return incorrect results.
var win = Ti.UI.createWindow({ backgroundColor:'#ffffff' }); var html = 'This is not ok.'; var view = Ti.UI.createWebView({ height: Ti.UI.SIZE, width: Ti.UI.FILL, top: 40, backgroundColor:'red' }); view.setHtml(html,{mimeType:'text/plain'}); win.add(view); win.open();This bug also exsits on Android.
[~tomboman] Test case?
I don't think a test case is coming. Closing. Please reopen if still an issue.
This is related to TIMOB-20482, thx!