Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-9121] Android: label.toImage().height not working correctly

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionCannot Reproduce
Resolution Date2013-06-19T18:36:02.000+0000
Affected Version/sRelease 2.0.1
Fix Version/sn/a
ComponentsAndroid
Labelsapi, exalture, parity
Reporterchris smashe
AssigneeSunila
Created2012-05-06T11:38:42.000+0000
Updated2017-03-21T21:31:18.000+0000

Description

Issue

Whenever label.toImage().height is used in Android it always returns 100 no matter how large the label field is. Tried converting an auto sized label to and image to get the height of it to figure out what size table I need to hold all of them.

Expected outputs

Each label has its own height (as seen in iOS simulator)

Actual outputs

Both height = 100

Tested on

LG ally 2.2 & Droid razr 2.3.5

Repro sequence

- app.js
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');


//
// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({  
    title:'Tab 1',
    backgroundColor:'#fff',
    layout:'vertical'
});

var label1 = Titanium.UI.createLabel({
	color:'#999',
	text:'Short Label',
	font:{fontSize:20,fontFamily:'Helvetica Neue'},
	width:'auto',
	top:0
});

var label1Size = label1.toImage().height;

win1.add(label1);

var label1Sizeinfo = Ti.UI.createLabel({
	text:'The size of label 1 is ' + label1Size,
	top:0
});

win1.add(label1Sizeinfo);


var label2 = Titanium.UI.createLabel({
	color:'#999',
	text:'Earlier today, Fearless Leader announced Appcelerator's plans to support native application development for the BlackBerry 10.  Work is already underway to implement the Titanium JavaScript API on BlackBerry 10 devices using BlackBerry's NDK. Unlike previous versions of the BlackBerry...',
	font:{fontSize:20,fontFamily:'Helvetica Neue'},
	width:'auto',
	top:0
});

var label2Size = label2.toImage().height;

win1.add(label2);

var label2Sizeinfo = Ti.UI.createLabel({
	text:'The size of label 2 is ' + label2Size,
	top:0
});

win1.add(label2Sizeinfo);

win1.open();

Attachments

FileDateSize
iOS_Labels.jpg2012-05-11T20:49:47.000+000039847

Comments

  1. Eduardo Gomez 2012-05-08

    The test case is invalid due to doesn't set height value for any of label1 & label2 (that's why it renders same values in this case 100). See refined sample that calculates height per each label:

    Repro sequence

    - app.js
       // this sets the background color of the master UIView (when there are no windows/tab groups on it)
       Titanium.UI.setBackgroundColor('#000');
       
       //
       // create base UI tab and root window
       //
       var win1 = Titanium.UI.createWindow({
       	title : 'Tab 1',
       	backgroundColor : '#fff',
       	layout : 'vertical',
       	height: 'auto'
       });
       
       var label1 = Titanium.UI.createLabel({
       	color : '#999',
       	text : 'Short Label',
       	font : {
       		fontSize : 20,
       		fontFamily : 'Helvetica Neue'
       	},
       	width : 'auto',
       	height: 'auto',
       	top : 0
       });
       
       var label1Size = label1.toImage().height;
       Ti.API.info(' >>>>>>>>>>> label1Size: '+ label1Size);
       
       win1.add(label1);
       
       var label1Sizeinfo = Ti.UI.createLabel({
       	text : 'The size of label 1 is ' + label1Size,
       	top : 0
       });
       
       win1.add(label1Sizeinfo);
       
       var label2 = Titanium.UI.createLabel({
       	color : '#999',
       	text : 'Earlier today, Fearless Leader announced Appcelerators plans to support native application development for the BlackBerry 10. Work is already underway to implement the Titanium JavaScript API on BlackBerry 10 devices using BlackBerrys NDK. Unlike previous versions of the BlackBerry...',
       	font : {
       		fontSize : 20,
       		fontFamily : 'Helvetica Neue'
       	},
       	width : 'auto',
       	height: Ti.UI.SIZE,
       	top : 0
       });
       
       var label2Size = label2.toImage().height;
       Ti.API.info(' >>>>>>>>>>> label2Size: '+ label2Size);
       
       win1.add(label2);
       
       var label2Sizeinfo = Ti.UI.createLabel({
       	text : 'The size of label 2 is ' + label2Size,
       	top : 0
       });
       
       win1.add(label2Sizeinfo);
       
       win1.open();
       

    As per the sample provided that might return:

       The size of label 1 is 27
       The size of label 2 is 100
       
    Closing at this time Jira ticket. If there are further issues please provide *target environment* and what is the device or emulator this was tested on.
  2. chris smashe 2012-05-11

    You said ??The test case is invalid due to doesn't set height value for any of label1 & label2 (that's why it renders same values in this case 100).?? According to your documentation [http://docs.appcelerator.com/titanium/2.0/index.html#!/guide/Transitioning_to_the_New_UI_Layout_System] it says ??When width or height parameters are undefined, an attempt will be made to calculate these parameters implicitly. If they cannot be calculated implicitly, they will follow "auto" behavior. In previous versions of the Titanium SDK undefined width or height enforced FILL behavior.?? which should mean that it blank is the same as auto right? Using your example above if you change 40 from
        text : 'Earlier today, Fearless Leader announced Appcelerators plans to support native application development for the BlackBerry 10. Work is already underway to implement the Titanium JavaScript API on BlackBerry 10 devices using BlackBerrys NDK. Unlike previous versions of the BlackBerry...',
        
    to *I doubled the amount of text*
        text : 'Earlier today, Fearless Leader announced Appcelerators plans to support native application development for the BlackBerry 10. Work is already underway to implement the Titanium JavaScript API on BlackBerry 10 devices using BlackBerrys NDK. Unlike previous versions of the BlackBerry...Earlier today, Fearless Leader announced Appcelerators plans to support native application development for the BlackBerry 10. Work is already underway to implement the Titanium JavaScript API on BlackBerry 10 devices using BlackBerrys NDK. Unlike previous versions of the BlackBerry...',
        
    The size of the label should be 200. It is still 100. After further investigation if i change line 46 from
       height: Ti.UI.SIZE,
       
    to
       height: 'auto'
       
    to mimic label number 1 where you use auto instead of the new Ti.UI.SIZE the size of the label changes from 100 to 27 which is the same as label 1. According to your documentation referenced above ??specifying 'auto' for either height or width is the same as specifying Ti.UI.SIZE. ?? Since auto is returning 100 and Ti.UI.SIZE is returning 27 this seems to not be the case. To recap everything that has been found to be wrong. 1. label2.toImage().height is not giving the correct height in android. it is returning 27 if you use Ti.UI.SIZE for the height and 100 if you use auto no matter how much text is actually in the label. 2. Ti.UI.SIZE and auto are not returning the same height so specifying 'auto' for either height or width is *Not* the same as specifying Ti.UI.SIZE This has been tested in the following set ups all with the same result Android Emulator Motorola Droid HTC Droid Incredible.
  3. Eduardo Gomez 2012-05-11

  4. Arthur Evans 2012-05-18

    Seeing this as well. Note that on iOS (and in the docs) toImage returns a Blob. On Android, it appears to return a dictionary containing height, width, cropRect, and the actual blob (media). The size appears to be incorrect on the blob, as well, however. media.height and media.width are both returning 0, and the image is a black square. So it doesn't appear that toImage is working at all, at least on emulator. I believe this is all because the view (label in this case) isn't fully laid out when toImage is called. However, for this use case, toImage is overkill, anyway. The appropriate way to handle this would be to listen for the postlayout event and checking label.size.height: label.addEventListener('postlayout', function(e) { Ti.API.info("label height = "+ button.size.height); })
  5. chris smashe 2012-05-19

    The test case was just to show it not working. The height is being used to add set the height of the rows and table that the label is in when you are using dynamic data since you can not just set everything to auto and have it grow and shrink based on the amount of text.
  6. chris smashe 2012-06-10

    How long does it take to have bugs in the sdk looked at?
  7. Sunila 2013-06-19

    I can't reproduce this. Both samples gives the consistent output for both labels as 28. Tried with 3.2 in Nexus S.
  8. Lee Morris 2017-03-21

    Closing ticket as the issue cannot be reproduced.

JSON Source