Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-709] size.height and size.width properties are 0 when height or width auto is used

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T01:53:59.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.3.0
ComponentsiOS
Labelsn/a
ReporterNolan Wright
AssigneeBlain Hamon
Created2011-04-15T02:34:56.000+0000
Updated2011-04-17T01:53:59.000+0000

Description

from premium support:

http://helpdesk.appcelerator.net/tickets/1762">http://helpdesk.appcelerator.net/tickets/1762

Comments

  1. Stephen Tramer 2011-04-15

    Partial fix for this that solves the user's problem:

    You can't get these values before the window is drawn, because the autosize values are not computed until that time. So what you can do is:

       var realWidth = null;
       var realHeight = null;
       win.addEventListener('open', function(e) {
          realWidth = view.size.width;
          realHeight = view.size.height;
       });
       

    Blain says this might not work for tableRowViews, however, since they are lazyload. This should solve the customer's problem however.

    Leaving the bug open until we can come up with a tableRowView solution.

  2. Stephen Tramer 2011-04-15

    Closing this, it's just not possible to get useful size information without drawing all superviews (which, in the case of an element like a label, means drawing everything). The user can get the desired behavior by using code like the following:

       var label1 = Ti.UI.createLabel({
           text: 'Some Name',
           color: 'blue',
           font: { fontSize: 16}, 
           width: 'auto',
           height: 'auto',
           bottom:0,
           left:0
       });
       win.add(label1);
       
       var label2 = Ti.UI.createLabel({
           text: 'says',
           font: {fontStyle: 'italic', fontSize: 16},
           color:'black',
           width: 'auto',
           height: 'auto',
           bottom:0
       });
       win.add(label2);
       
       win.addEventListener('open', function(e) {
           label2.left = label1.size.width+20;
       });
       

    Positioning elements based on other autosize elements has to be done on window open (and yes, they are redrawn correctly before display). Handling table rows is all done internally and the user should have no control over it. Create another bug if that becomes an issue.

JSON Source