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%".
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
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%".
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
Addressed review comments, ready for merge
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
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
https://github.com/appcelerator/titanium_mobile/pull/6323 Update the view proxies in the layout pass.
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