Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

'touchcancel' event being fired prematurely?

Hi! I have some ImageViews inside a ScrollView. I'm listening to 'touchmove' events on the ImageViews and moving the ImageViews to the center of the event position - ie. I'm making draggable images inside a scroll view.

Scrolling works fine, but for some reason the 'touchcancel' event is being fired from the ImageViews after barely a few pixels of dragging. I could understand the 'touchcancel' event being fired when the touch position is outside the hit area of the ImageView, but it's firing while it's still inside it.

Has anyone else experienced a similar issue?

Thanks for your help.

— asked June 6th 2010 by Michael Park
  • imageview
  • scrollview
  • touchcancel
  • touchmove
0 Comments

3 Answers

  • I have met the same problem.

    My api 2.0.2, my platform android.

    In my case, I add a view into a ScrollableView and want to move left and right. but when i moved the view to left, the view moved a little right and fire the event touchcancel, if i moved the view to right the view moved a little right and fire the event touch cancel. If I move the view a little up or down then i could move the view correctly. below is my test code.

    By the way, I test the code in iOS , it works fine.

    var win1 = Titanium.UI.createWindow({  
        backgroundColor:'#fff'
    });
    
    var W = Ti.Platform.displayCaps.platformWidth;
    
    var sview = Ti.UI.createScrollableView({
        height: '100%',
        width: '100%',
        showPagingControl: true
    });
    var view = Ti.UI.createView({
        height: '100%',
        width: '100%'
    });
    
    var view1 = Titanium.UI.createView({
        height: '20%',
        width: '20%',
        top: W * 0.2,
        backgroundColor: 'red'
    });
    view1.addEventListener('touchmove', function(e){
        var point = e.source.convertPointToView({x: e.x, y: e.y}, win1);
        view1.left = point.x;
        label.text = point.x;
    });
    view1.addEventListener('touchcancel', function(e){
        label.text = 'cancel';
    });
    
    var label = Ti.UI.createLabel({
        height: '20%',
        width: '20%',
        bottom: '20%',
        left: '20%',
        color: 'black',
        font: {fontSize: W * 0.04}
    });
    view.add(label);
    
    view.add(view1);
    
    sview.views = [view];
    
    win1.add(sview);
    
    win1.open();
    
    — answered June 25th 2012 by Ryu ShinChu
    permalink
    0 Comments
  • This question is 2 years old and still no working solution?

    On Android, touchmove is still interrupted by touchcancel. Also, once the touchcancel event has fired, the touchend event never gets fired either (which is the correct behavior - assuming the touch cancel event is being fired correctly).

    The interesting thing is that iOS also fires the touchcancel event prematurely (you can test this by updating a label when the touchcancel event fires), however, it seems iOS is clever enough to realise that the user is still "touchmoving" on the screen and it keeps firing the touchmove event regardless of whether or not the touchcancel event was fired. It seems to me that this is actually a bug, but thanks to this bug, it works on iOS.

    I'm using Ti Studio with SDK version 2.1.3.GA

    I've tested this on both the V8 and Rhino Android Runtimes (as seen in the tiapp.xml editor)

    I must say, this is really disappointing. One would think that for touch enabled devices, getting the touchmove/touchcancel events working properly would be one of the core issues to deal with?

    I've also tried the TiDraggable module (https://github.com/pec1985/TiDraggable/), however, the behavior is identical.

    — answered November 2nd 2012 by Robin Stoker
    permalink
    0 Comments
  • Finally got it! If you put a "draggable/moveable" object inside a ScrollView, then the ScrollView's touch events are going to conflict with the draggable object's touch events. Doesn't seem to be an issue on iOS though.

    Take the same moveable object and add it to a normal View and the problem disappears like magic.

    — answered November 2nd 2012 by Robin Stoker
    permalink
    1 Comment
    • Also, the ScrollView has a "canCancelEvents" property. Duh!

      — commented November 2nd 2012 by Robin Stoker
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.