Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14993] iOS: Ti.UI.SIZE height of a WebView is incorrectly calculated

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2013-10-09T21:16:07.000+0000
Affected Version/sRelease 3.1.1
Fix Version/s2013 Sprint 21, 2013 Sprint 21 API
ComponentsiOS
Labelsios, ipass1, regression
ReporterMatthew Delmarter
AssigneeVishal Duggal
Created2013-07-31T05:15:40.000+0000
Updated2017-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

FileDateSize
TiWebView_Height.png2013-07-31T05:15:40.000+000010661

Comments

  1. Matthew Delmarter 2013-08-13

    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:
       -(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;
       }
       
    With:
       -(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;
       }
       
  2. Ingo Muschenetz 2013-08-29

    [~srahim], thoughts?
  3. Vishal Duggal 2013-10-09

    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();
       
  4. Tom aan 't Goor 2013-10-29

    This bug also exsits on Android.
  5. Ingo Muschenetz 2013-10-29

    [~tomboman] Test case?
  6. Eric Merriman 2017-03-28

    I don't think a test case is coming. Closing. Please reopen if still an issue.
  7. Hans Knöchel 2017-04-10

    This is related to TIMOB-20482, thx!

JSON Source