Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-28454

Android: "longpress" event wrongly fires when tapping a touch disabled view

    Details

    • Story Points:
      5

      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:

      1. Build and run the below on Android.
      2. Tap on the "Click Me" label.
      3. Notice you get a dialog displaying "click". (This is good.)
      4. 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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jquick Joshua Quick
                Reporter:
                jquick Joshua Quick
                Reviewer:
                Gary Mathews
              • Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                    Git Integration