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();
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.jsAs per the sample provided that might return:
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.
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
to *I doubled the amount of text*
The size of the label should be 200. It is still 100. After further investigation if i change line 46 from
to
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.
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 whentoImage
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); })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.
How long does it take to have bugs in the sdk looked at?
I can't reproduce this. Both samples gives the consistent output for both labels as 28. Tried with 3.2 in Nexus S.
Closing ticket as the issue cannot be reproduced.