Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-24793] Android: Fix Ti.UI.View.center calculation #9125

Merged
merged 3 commits into from Jun 8, 2017

Conversation

garymathews
Copy link
Contributor

@garymathews garymathews commented Jun 7, 2017

  • Fix Ti.UI.View.center property when {x: 0, y: 0} is used
TEST CASE
var window = Ti.UI.createWindow({backgroundColor: 'gray'}),
    a = Ti.UI.createView({backgroundColor: 'red', width: 200, height: 200, top: 0, left: 0}),
    b = Ti.UI.createView({backgroundColor: 'blue', width: 100, height: 100, center: {x: 150, y: 150}}),
    btn_a = Ti.UI.createButton({title: 'TOP LEFT', bottom: 0, left: 0, width: '50%'}),
    btn_b = Ti.UI.createButton({title: 'ZERO', bottom: 0, right: 0, width: '50%'});

btn_a.addEventListener('click', function(){
    b.center = {x: 50, y: 50};
});

btn_b.addEventListener('click', function(){
    b.center = {x: 0, y: 0};
});

window.add([btn_a, btn_b, a, b]);
window.open();

JIRA Ticket

Copy link
Contributor

@jquick-axway jquick-axway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The center point is supposed to be relative to the top-left corner of the parent view. We document it here.

This new code breaks this behavior and makes the center point relative to center of the parent view. This is not correct. Nor does it match iOS (I tested it).

Also, I do see an old bug here (before your change) where a center point of (0,0) is wrongly ignored. (0,0) should position the view in the top-left corner of the parent, which I've confirmed is how it works on iOS.

@garymathews
Copy link
Contributor Author

Thanks for pointing that out, I assumed center of parent due to not having to calculate for zero.

Updated PR

@jquick-axway
Copy link
Contributor

No worries! :)
Lokesh and I were confused about what it was supposed to do too. Especially with a center point of (50%,50%) and (0,0) both ending up in the center of the view on Android.

Copy link
Contributor

@jquick-axway jquick-axway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: Pass

@lokeshchdhry
Copy link
Contributor

FR Passed.

Used the code below to test:

var window = Ti.UI.createWindow({backgroundColor: 'gray'}),
    a = Ti.UI.createView({backgroundColor: 'red', width: 200, height: 200}),
    b = Ti.UI.createView({backgroundColor: 'blue', width: 100, height: 100, center: {x: 0, y: 0}}),
    btnLeft = Ti.UI.createButton({title: 'TOP LEFT', top: 0, left: 0, width: Ti.UI.SIZE});
    btnRight = Ti.UI.createButton({title: 'TOP RIGHT', top: 0, left: '25%', width: Ti.UI.SIZE});
    btnBottomLeft = Ti.UI.createButton({title: 'BOTTOM \nLEFT', top: 0, left: '50%', width: Ti.UI.SIZE});
    btnBottomRight = Ti.UI.createButton({title: 'BOTTOM RIGHT', top: 0, left: '75%', width: Ti.UI.SIZE});
	width = 0,
	height = 0;
    
window.addEventListener('postlayout', function(){
	alert(window.getSize());
	width = window.getSize().width;
	height = window.getSize().height;
});

 
btnLeft.addEventListener('click', function(){
    b.center = {x: 0, y: 0};
});

btnRight.addEventListener('click', function(){
    b.center = {x: width, y: 0};
});
 
btnBottomLeft.addEventListener('click', function(){
    b.center = {x: 0, y: height};
});
  
btnBottomRight.addEventListener('click', function(){
    b.center = {x: width, y: height};
});
 

window.add([btnLeft, btnRight, btnBottomLeft, btnBottomRight, b]);
window.open();

Center is the right center now & is calculated properly.

Studio Ver: 4.9.0.201705302345
SDK Ver: 6.2.0 local build
OS Ver: 10.12.3
Xcode Ver: Xcode 8.3.3
Appc NPM: 4.2.9
Appc CLI: 6.2.2
Ti CLI Ver: 5.0.14
Alloy Ver: 1.9.11
Node Ver: 6.10.1
Java Ver: 1.8.0_101
Devices: ⇨ google Pixel --- Android 7.1.1
⇨ google Nexus 5 --- Android 6.0.1

@lokeshchdhry lokeshchdhry merged commit 9c5c53f into tidev:master Jun 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants