Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-11866] iOS: Click event in UIView is firing immediately

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2012-12-06T01:25:08.000+0000
Affected Version/sRelease 2.1.2, Release 2.1.3, Release 2.1.4, Release 3.0.0
Fix Version/sRelease 3.0.1, Release 3.1.0, 2012 Sprint 25, 2012 Sprint 25 API
ComponentsiOS
Labelsapi, module_views, qe-testadded, triage
ReporterRafael Kellermann Streit
AssigneeVishal Duggal
Created2012-10-11T20:42:15.000+0000
Updated2013-01-15T15:36:00.000+0000

Description

*Actual result* UIView 'click' event is fired instantly when the user puts their finger inside the UIView. *Expected result* The event should only be fired when click is completed. Examples: *ImageView*
var window = Ti.UI.createWindow({
	backgroundColor : 'white'
});

var image = Ti.UI.createImageView({
	image : "KS_nav_ui.png"
});

image.addEventListener("click", function() {
	alert("I didn't removed my finger from touch yet!");
});

window.add(image);
window.open();
*View*
var window = Ti.UI.createWindow({
	backgroundColor : 'white'
});

var view = Ti.UI.createView({
	width : 100,
	height : 100,
	backgroundColor : "#FF0000"
});

view.addEventListener("click", function() {
	alert("It happens here too.")
});

window.add(view);
window.open();

Comments

  1. Daniel Sefton 2012-10-11

    Needs more info - what Titanium Mobile SDK? What iOS version?
  2. Rafael Kellermann Streit 2012-10-11

    Hello Daniel, I think it happens since first SDK. But I'm using SDK 2.1.3.GA and iOS 6. Thanks!
  3. Daniel Sefton 2012-10-11

    Is it possible to provide a copy + paste reproduction case that doesn't involve an image view? Or does it only happen with image views?
  4. Rafael Kellermann Streit 2012-10-11

    I think the problem is in all components based in UIView. For example:
       var view = Ti.UI.createView({
       	width: 100,
       	height: 100,
       	backgroundColor: "#FF0000"
       });
       self.add(view);
       
       view.addEventListener("click", function() {
       	alert("It happens here too.")
       });
       
    Probably the event *click* is inherited from UIView delegate, so, it happens to all components based in UIView. Thanks
  5. Rafael Kellermann Streit 2012-10-11

    Here is the code that produces it: **TiUIView.m** LINE: 1033 - Titanium SDK 2.1.3.GA
       - (void)processTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
       {
           UITouch *touch = [touches anyObject];
       	
       	if (handlesTouches)
       	{
       		NSMutableDictionary *evt = [NSMutableDictionary dictionaryWithDictionary:[TiUtils pointToDictionary:[touch locationInView:self]]];
       		[evt setValue:[TiUtils pointToDictionary:[touch locationInView:nil]] forKey:@"globalPoint"];
       		
       		if ([proxy _hasListeners:@"touchstart"])
       		{
       			[proxy fireEvent:@"touchstart" withObject:evt propagate:YES];
       			[self handleControlEvents:UIControlEventTouchDown];
       		}
               // Click handling is special; don't propagate if we have a delegate,
               // but DO invoke the touch delegate.
       		// clicks should also be handled by any control the view is embedded in.
       		if ([touch tapCount] == 1 && [proxy _hasListeners:@"click"])
       		{
       			if (touchDelegate == nil) {
       				[proxy fireEvent:@"click" withObject:evt propagate:YES];
       				return;
       			} else {
       				[touchDelegate touchesBegan:touches withEvent:event];
       			}
       		} else if ([touch tapCount] == 2 && [proxy _hasListeners:@"dblclick"]) {
       			[proxy fireEvent:@"dblclick" withObject:evt propagate:YES];
       			return;
       		}
       	}
       }
       
    You can see, that *processTouchesBegan* is firing *click* event.
  6. Rafael Kellermann Streit 2012-10-23

    Is there any update? I really think that it needs to be resolved in 3.0 SDK.
  7. Daniel Sefton 2012-11-27

    Tested and confirmed iOS 5.1, TISDK 2.1.2 GA, 2.1.3 GA, 2.1.4 GA, 3.0.0 CI.
  8. Vishal Duggal 2012-12-04

    Pull pending https://github.com/appcelerator/titanium_mobile/pull/3524
  9. Vishal Duggal 2012-12-27

    Backport PR to 3_0_X https://github.com/appcelerator/titanium_mobile/pull/3637
  10. Shyam Bhadauria 2013-01-04

    Verified with following Titanium SDK: 3.1.0.v20130102102603 Titanium SDK:3.0.1.v20121228113204 Titanium Studio:3.0.1.201212181159 Device: Simulator iOS 6.0
  11. Shawn Lipscomb 2013-01-15

    As of SDK 3.1.0.20130109175536, there's a side effect of this fix: if a slow click is performed (where the click lasts longer than half a second), the click event doesn't fire at all. I'm doing this with the mouse in the simulator, so there is no movement during the click. Is this intentional?
  12. Sabil Rahim 2013-01-15

    @Shawn Lipscomb - I believe that is a intended behavior change. If you click for more than half a second then it no longer is a click event , it becomes a long press instead.
  13. Rafael Kellermann Streit 2013-01-15

    I agree with Sabil. If you wanna handle a long press, you should use the longpress event. BTW, we could verify if UIView have some listener for *longpress*. If not have, we can fire event to click handler. What do you think? It probably will reduce some bugs in currently applications (and future).

JSON Source