Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28454] Android: "longpress" event wrongly fires when tapping a touch disabled view

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2021-05-24T14:51:13.000+0000
Affected Version/sn/a
Fix Version/sRelease 10.0.1
ComponentsAndroid
Labelsandroid, click, longpress, touch
ReporterJoshua Quick
AssigneeJoshua Quick
Created2021-05-18T21:23:13.000+0000
Updated2021-05-24T14:51:24.000+0000

Description

*Summary:* When tapping on a view with "touchEnabled" set to false, the parent will wrongly fire a "longpress" event if it has a listener set up on it. That is, it fires when you're not actually long pressing it and should be a click instead. This issue does not happen if "touchEnabled" is set to true. *Steps to reproduce:*

Build and run the below on Android.

Tap on the "Click Me" label.

Notice you get a dialog displaying "click". _(This is good.)_

Notice you also get a dialog displaying "longpress". _(This is the bug.)_

const window = Ti.UI.createWindow({ backgroundColor: "white" });
const view = Ti.UI.createView({
	backgroundColor: "blue",
	touchFeedback: true,
	width: "250dp",
	height: "250dp",
});
view.add(Ti.UI.createLabel({
	text: "Click Me\nor\nLong Press Me",
	textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
	color: "white",
	touchEnabled: false,
}));
view.addEventListener("click", () => {
	alert("click");
});
view.addEventListener("longpress", (e) => {
	const formatter = new Intl.NumberFormat(Ti.Locale.currentLocale, {
		maximumFractionDigits: 0,
		minimumFractionDigits: 0,
	});
	alert(longpress (${formatter.format(e.x)},${formatter.format(e.y)}));
});
window.add(view);
window.open();
*Cause:* We're running into the same issue mentioned here... https://stackoverflow.com/questions/24326530/long-press-in-gesturedetector-also-fires-on-tap The issue is that Google's GestureDetector sends a "longpress" message via a timeout which doesn't get canceled since the touch event isn't handled. The solution may be to implement our own custom long press event handling. *Note:* A "longpress" event should also cause the device to vibrate like how the native "longclick" works. This would match the behavior seen in Google's apps. The vibration should only happen if an event listener has been added for it.

Comments

  1. Joshua Quick 2021-05-18

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/12820
  2. Christopher Williams 2021-05-24

    merged to master and 10_0_X for 10.0.1 target

JSON Source