[TIMOB-27807] Android: convertPointToView() returns pixels instead of default units
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | Release 10.0.0 |
Components | Android |
Labels | 2020-Q4, android, breaking-change, drag, parity, touch, unit |
Reporter | Joshua Quick |
Assignee | Joshua Quick |
Created | 2020-03-12T01:49:55.000+0000 |
Updated | 2020-12-11T13:04:38.000+0000 |
Description
*Summary:*
Titanium's Uncomment the
View.convertPointToView()
method is hardcoded to return pixels on Android. The returned coordinates should be using the "ti.ui.defaultunit" assigned to the "tiapp.xml" instead, which defaults to "dp".
iOS returns "dp", not pixels. So, this is a parity issue.
*Steps to reproduce:*
Build and run the below on Android.
Attempt to drag one of the squares onscreen.
Notice the square disappears.
Uncomment the Ti.Android
code block below. _(Converts pixels to dp.)_
Rebuild for Android.
Notice that dragging a square now works.
Build and run on iOS.
Notice that dragging a square now works.
function createDragSquare(top, left, color) {
var view = Ti.UI.createView({
touchEnabled: true,
backgroundColor: color,
center: { x: left + 50, y: top + 50 },
width: 100,
height: 100,
});
view.addEventListener("touchmove", function(event) {
var parentPoint = view.convertPointToView({ x: event.x, y: event.y }, window);
// if (Ti.Android) {
// parentPoint.x = Ti.UI.convertUnits(parentPoint.x + "px", "dip");
// parentPoint.y = Ti.UI.convertUnits(parentPoint.y + "px", "dip");
// }
Ti.API.info("@@@ touch point: (" + parentPoint.x + ", " + parentPoint.y + ")");
view.center = parentPoint;
event.cancelBubble = true;
});
return view;
}
var window = Ti.UI.createWindow({ backgroundColor: "white" });
window.add(createDragSquare(40, 40, "red"));
window.add(createDragSquare(120, 120, "green"));
window.add(createDragSquare(200, 200, "blue"));
window.open();
*Work-Around:*
Convert the convertPointToView()
method's returned results from pixels to dp only on Android as shown below.
var parentPoint = view.convertPointToView({ x: event.x, y: event.y }, window);
if (Ti.Android) {
parentPoint.x = Ti.UI.convertUnits(parentPoint.x + "px", "dip");
parentPoint.y = Ti.UI.convertUnits(parentPoint.y + "px", "dip");
}
PR (master): https://github.com/appcelerator/titanium_mobile/pull/12320
FR Passed, waiting on Jenkins build.