Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8929] MobileWeb: View.rect x and y values appear to be switched

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2012-05-01T15:51:32.000+0000
Affected Version/sRelease 2.1.0
Fix Version/sRelease 2.1.0, Sprint 2012-09 MW
ComponentsMobileWeb
Labelsqe-port
ReporterArthur Evans
AssigneeBryan Hughes
Created2012-04-30T16:11:10.000+0000
Updated2013-11-01T09:21:40.000+0000

Description

For some reason, the View.rect.y value is returning a large value, no matter where the view is position. On further investigation, it appears that the x and y values are being switched. Also, the values are not updated when the view is animated. Consider the following example:
var win1 = Titanium.UI.createWindow({  
    title:'Window',
    backgroundColor:'#fff'
});

var label1 = Titanium.UI.createLabel({
	color:'#999',
	text:'Click Me',
	top: 10,
	font:{fontSize:20,fontFamily:'Helvetica Neue'},
	textAlign:'center',
	width:'auto',
	touchEnabled: true
});

label1.addEventListener('click', function(e) {
	Ti.API.info("Label pos is: " +label1.rect.x + ","+label1.rect.y);
	if (label1.rect.y < 100) {
		label1.animate({ top: 100, duration: 500 });
	} else {
		label1.animate({ top: 10, duration: 500 });
	}
});

win1.add(label1);

win1.open();
On iOS and Android, this behaves as expected--the label moves up when clicked the first time, then down when clicked the second time. On Mobile Web, the label moves up after the first click, but then stays fixed. The console logging shows why:
index.html:10460[INFO] Label pos is: 10,446
index.html:10460[INFO] Label pos is: 10,446
Since the view is pinned to the top and centered horizontally, it should be at 446,10. Also note that the reported value doesn't change before and after animation. (Update: Filed this as a separate issue, TIMOB-8930.)

Comments

  1. Bryan Hughes 2012-04-30

    Pull request: https://github.com/appcelerator/titanium_mobile/pull/2108
  2. Lokesh Choudhary 2012-08-28

    Verified fix on: Titanium studio : 2.1.1.201207271312 SDK version : 2.2.0.v20120827143312 Chrome 21.0.xx Firefox 15 Safari 6.0 Android 4.0.4 default browser,chrome 18.0.xx ,firefox 15.0 Iphone 5.0.1 mobile safari

JSON Source