Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14923] iOS: rect and getRect values returning empty object

GitHub Issuen/a
TypeBug
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 2.1.4, Release 3.0.2, Release 3.1.1, Release 3.1.2
Fix Version/sn/a
ComponentsiOS
Labelsdefect, ios
ReporterMark Ross
AssigneeUnknown
Created2013-08-20T16:14:41.000+0000
Updated2018-02-28T20:03:41.000+0000

Description

*Problem* I cannot get values for rect or getRect on a view. I try to see the values after adding to the window and after a postlayout event (per the docs). Both return an empty object. *Test case*
var win = Ti.UI.createWindow({
	backgroundColor: 'white'
});

var v1 = Ti.UI.createView({
	height: 104,
	width: Ti.UI.FILL,
	top: 30,
	backgroundColor: '#f2f2ff'
});

var l1 = Ti.UI.createLabel({
	text: 'I am a label',
	height: Ti.UI.SIZE,
	top: 20,
	left: 97,
	right: 1,
	textAlign: 'center',
	color: 'black',
	font: {
		fontSize: 18,
		fontWeight: 'bold'
	},
	minimumFontSize: 14
});

function v1post() {
	Ti.API.info('v1 rect (postlayout): ' + JSON.stringify(this.getRect()));
	v1.removeEventListener('postlayout', v1post);
}

v1.addEventListener('postlayout', v1post);

v1.add(l1);
win.add(v1);

Ti.API.info('v1 rect: ' + JSON.stringify(v1.getRect()));

win.open();
*Output*
[INFO] :   v1 rect: {}
[INFO] :   v1 rect (postlayout): {}

Comments

  1. Jamie Buckley 2013-08-20

    Tested with SDK versions 2.1.4, 3.0.2, 3.1.1, 3.1.2 reproduced error on each.
  2. Tayler Summers 2013-09-03

    Just a note: the getRect() return value is not JSON.stringifiable, but you should still be able to look at the return value's properties individually. Try replacing your ln. 28 with something like this: var v1Rect = this.getRect(); Ti.API.info('v1Rect x: ' + v1Rect.x); Ti.API.info('v1Rect y: ' + v1Rect.y); Ti.API.info('v1Rect height: ' + v1Rect.height); Ti.API.info('v1Rect width: ' + v1Rect.width); While you can't see all the values at once stringified, this at least shows that those values exist and that you can use them.

JSON Source