Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26503] Windows: Touch event coordinate units do not match between platforms

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2018-12-03T09:53:56.000+0000
Affected Version/sRelease 6.0.0
Fix Version/sRelease 8.0.0
ComponentsWindows
Labelsbreaking-change, parity
ReporterJoshua Quick
AssigneeKota Iguchi
Created2018-10-31T02:25:59.000+0000
Updated2018-12-03T12:10:11.000+0000

Description

*Summary:* The (x,y) units provided by View event's "touchstart", "touchmove", "touchend", and "touchcancel" do not match between Android and iOS. Both platforms ignore the "ti.ui.defaultunit" property setting in "tiapp.xml". On Android, the touch coordinates are always in "px" (ie: pixels). On iOS, the touch coordinates are always in "dip" (aka: "dp"). *Steps to Reproduce:*

Build and run the below code on Android.

Drag your finger in the gray view.

Notice that the blue square does *not* correctly following your finger.

Build and run on iOS.

Drag your finger in the gray view.

Notice that the blue square *correctly* follows your finger.

Change "tiapp.xml" property "ti.ui.defaultunit" to "px".

Build and run on iOS.

Drag your finger in the gray view.

Notice that the blue square does *not* correctly following your finger.

Build and run on Android.

Drag your finger in the gray view.

Notice that the blue square *correctly* follows your finger.

function onTouch(event) {
	touchView.center = { x: event.x, y: event.y };
}

var window = Ti.UI.createWindow(
{
	layout: "vertical",
	fullscreen: true,
});
window.add(Ti.UI.createLabel(
{
	text: "Touch Drag Test",
	top: "20dp",
}));
var containerView = Ti.UI.createView(
{
	touchEnabled: true,
	backgroundColor: "gray",
	top: "10dp",
	bottom: "20dp",
	width: "90%",
});
var touchView = Ti.UI.createView(
{
	touchEnabled: false,
	backgroundColor: "#008800",
	width: "100dp",
	height: "100dp",
});
containerView.add(touchView);
containerView.addEventListener("touchstart", onTouch);
containerView.addEventListener("touchmove", onTouch);
containerView.addEventListener("touchend", onTouch);
containerView.addEventListener("touchcancel", onTouch);
window.add(containerView);
window.open();
*Work-Around:* The following will work-around this issue on both Android and iOS...
// Fetch the default unit property set in "tiapp.xml".
var defaultUnit = Ti.App.Properties.getString("ti.ui.defaultunit", "dip");
if (defaultUnit === "dp") {
	defaultUnit = "dip";
} else if (defaultUnit === "system") {
	defaultUnit = (Ti.Platform.name === "android") ? "px" : "dip";
}

// Do the below when a touch event has been received.
function onTouch(event) {
	if (Ti.Platform.name === "android") {
		event.x = Ti.UI.convertUnits(event.x + "px", defaultUnit);
		event.y = Ti.UI.convertUnits(event.y + "px", defaultUnit);
	} else if ((Ti.Platform.name === "iOS") || (Ti.Platform.name === "iPhone OS")) {
		event.x = Ti.UI.convertUnits(event.x + "dip", defaultUnit);
		event.y = Ti.UI.convertUnits(event.y + "dip", defaultUnit);
	}
	touchView.center = { x: event.x, y: event.y };
}
*Ideal Solution:* Convert native touch coordinates to use "ti.ui.defaultunit" on both Android and iOS. This way views can easily be dragged since their "x", "y", and "center" properties already respect the "ti.ui.defaultunit" property. Note that this would be a breaking change.

Comments

  1. Kota Iguchi 2018-11-01

    https://github.com/appcelerator/titanium_mobile_windows/pull/1301
  2. Samir Mohammed 2018-11-27

    FR Passed, awaiting CR.
  3. Samir Mohammed 2018-12-03

    Closing ticket. Verified feature in SDK version 8.0.0.v20181130132038. Test and other information can be found at: https://github.com/appcelerator/titanium_mobile_windows/pull/1301

JSON Source