Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15621] Android: convertPointToView gives different results with SDK 3.1.3 compared to 3.0.2

GitHub Issuen/a
TypeBug
PriorityMedium
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/s2014 Sprint 10, 2014 Sprint 10 SDK
ComponentsAndroid
Labelsmodule_android, qe-3.4.1, qe-manualtest
ReporterDavide Cassenti
AssigneeUnknown
Created2013-10-31T16:06:24.000+0000
Updated2020-03-12T01:54:17.000+0000

Description

Problem description

User relies on convertPointToView to show a tooltip in a particular position, based on the user's click. However, using SDK 3.1.3, the coordinates given back by the function are negative, and the code is not working anymore.

Sample code

I reduced their code as much as possible. This sample shows the different values of 'y' when clicking the button using SDK 3.0.2 and SDK 3.1.3 index.xml
<Alloy>
	<Window class="container">
		<View id="cartWindow" class="container">
			<View id="containerWindow" class="container">
				<TableView id="table" zIndex="1" height="Ti.UI.SIZE" onClick="tableClick"></TableView>
			</View>
		</View>
	</Window>
</Alloy>
pickerRow.xml
<Alloy>
	<TableViewRow id="rowcss" backgroundSelectedColor='transparent' selectedBackgroundColor = 'transparent'>
		<Button id='btnAddToCart' left='0' backgroundColor='red' textAlign='left' width="55" height="20" />
	</TableViewRow>
</Alloy>
index.tss
".container": {
	backgroundColor:"white",
	width: Ti.UI.SIZE,
	height: Ti.UI.SIZE,
	navBarHidden: true
}
index.js
var item = Alloy.createController('pickerRow').getView();
$.table.appendRow(item);

var parentWin = $.index, button = '';
function changeQuant(e) {
	try {
		button = e.source;
		Ti.API.info("coordinates before convertPointToView :x" + e.x + " y" + e.y);
		var pos = button.convertPointToView({
			x : e.x,
			y : e.y
		}, parentWin);
		Ti.API.info("********Position after convertPointToView**************" + JSON.stringify(pos));
	} catch(e) {
		Ti.API.info(e.message);
	}
};

function tableClick(e) {
	if (e.source.id == 'btnAddToCart') {
		changeQuant(e);
	}
}

$.index.open();

Steps

1. Build with SDK 3.0.2 2. Open the app on Android 3. Click the red button and see logs 4. Repeat the steps using SDK 3.1.3

**Result**

The values for 'y' are very different; in particular, with 3.0.2 and my device I get around 600, while 3.1.3 gives a -500 (negative) for the same value.

Work-around:

The workaround is setting the height of the tableview to some specific number e.g. "500dp" or "90%".

Comments

  1. Ping Wang 2013-10-31

    First, the test case uses the Ti.UI.SIZE as window's width and height. Those two parameters are ignored for the heavyweight window before 3.1.2. After the window refactor (TIMOB-13796), the width and height are respected for the heavyweight window now. Therefore, in order to compare the behavior between 3.0.2 and 3.1.3, we should use a window without setting width and height. The test app should be
       var win = Ti.UI.createWindow({
           backgroundColor:"white",
           //width: Ti.UI.SIZE,
           //height: Ti.UI.SIZE,
           navBarHidden: true
       });
       
       var cartWindow = Ti.UI.createView({
           backgroundColor:"yellow",
           width: Ti.UI.SIZE,
           height: Ti.UI.SIZE,
           navBarHidden: true
       });
       
       var containerWindow = Ti.UI.createView({
           backgroundColor:"blue",
           width: Ti.UI.SIZE,
           height: Ti.UI.SIZE,
           navBarHidden: true
       });
       
       var table = Ti.UI.createTableView({
       	zIndex: 1,
       	height: Ti.UI.SIZE
       });
       
       var rowcss = Ti.UI.createTableViewRow({
       	backgroundSelectedColor: 'transparent', 
       	selectedBackgroundColor: 'transparent'
       });
       
       var btnAddToCart = Ti.UI.createButton({
       	left:'0', 
       	backgroundColor:'red', 
       	textAlign:'left',
       	width:"100",
       	height:"80",
       });
       
       rowcss.add(btnAddToCart);
       table.appendRow(rowcss);
       containerWindow.add(table);
       cartWindow.add(containerWindow);
       win.add(cartWindow);
       
       
       table.addEventListener("click", function(e) {
       	if (e.source == btnAddToCart) {
       		Ti.API.info("coordinates before convertPointToView :x" + e.x + " y" + e.y);
       		var pos = e.source.convertPointToView({
       			x : e.x,
       			y : e.y
       		}, win);
       		Ti.API.info("********Position after convertPointToView**************" + JSON.stringify(pos));
       	}
       }); 
       
       win.open();
       
    The above app breaks in 3.1.1 due to [PR#4205](https://github.com/appcelerator/titanium_mobile/pull/4205). When the height of the table is Ti.UI.SIZE, the coordinates of the button "btnAddToCart" in the window which is obtained by [*getLocationInWindow()*](http://developer.android.com/reference/android/view/View.html#getLocationInWindow(int[))] always return (0,0). But its y coordinate should be ~500 because it's rendered in the center of the screen. This issue may be related to TIMOB-14632 and TIMOB-15049. The workaround is setting the height of the tableview to some specific number e.g. "500dp" or "90%".
  2. Sunila 2014-01-20

    If the proxy is already assigned to the RowProxyItem during the layout pass, reuse it. I am not completely sure about this fix, this may require some regressions to rule out any side effects. https://github.com/appcelerator/titanium_mobile/pull/5239
  3. Sunila 2014-04-02

    Addressed review comments, ready for merge
  4. Vishal Duggal 2014-05-22

    We have a bunch of issues on TableView when the height of the TableView is set to Ti.UI.SIZE. If you really need a size behavior then either use a scrollview or a regular Ti.UI.View with a vertical layout. Recommend not backporting this to 3.3.0 release to avoid regressions this late in the cycle
  5. Lokesh Choudhary 2014-08-20

    Verified the fix. The co ordinates which we get back are not negative & are as expected. Closing Environment: Appc Studio : 3.4.0.201408180158 Ti SDK : 3.4.0.v20140819094113 Mac OSX : 10.8.5 Alloy : 1.5.0-dev CLI - 3.4.0-dev Code Processor: 1.1.1 Nexus 5 - android 4.4.4
  6. Hieu Pham 2014-09-19

  7. Sunila 2014-11-07

    https://github.com/appcelerator/titanium_mobile/pull/6323 Update the view proxies in the layout pass.
  8. Lokesh Choudhary 2015-12-10

    Reopening. This is not a regression it is seen with SDK 5.1.1.GA & 5.1.0.GA The y co ordinate returns negative value. Environment: Appc Studio : 4.4.0.201511241829 Ti SDK : 5.1.2.v20151208161231 Ti CLI : 5.0.5 Alloy : 1.7.26 MAC Yosemite : 10.10.5 Appc NPM : 4.2.2 Appc CLI : 5.1.0 Node: v0.12.27 Nexus 6P - Android 6.0

JSON Source