1. #1
    Ext GWT Premium Member
    Join Date
    Aug 2011
    Posts
    7
    Vote Rating
    1
    oren.s is on a distinguished road

      1  

    Default Answered: How to disable lists's itemtap if itemtaphold already fired?

    Answered: How to disable lists's itemtap if itemtaphold already fired?


    I'm using a list and listening to itemtap and itemtaphold. For each event I want to perform a different action.
    When I click/tap on an item and hold, the itemtaphold event fires. However, when I leave the mouse button / lift my finger, the itemtap event fires.

    How can I make the itemtap not fire if the current "click/touch" already triggered the itemtaphold?

    Thanks

  2. You can do something like:

    Code:
    listeners : {
        itemtap : function(list) {
            if (!list.lastTapHold || (list.lastTapHold - new Date() > 1000)) {
                console.log('itemtap');
            }
        },
        itemtaphold : function(list) {
            list.lastTapHold = new Date();
            console.log('itemtaphold');
        }
    }
    Of course you would need to clean up the lastTapHold property or it could be a memory leak.

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,522
    Answers
    3447
    Vote Rating
    814
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You can do something like:

    Code:
    listeners : {
        itemtap : function(list) {
            if (!list.lastTapHold || (list.lastTapHold - new Date() > 1000)) {
                console.log('itemtap');
            }
        },
        itemtaphold : function(list) {
            list.lastTapHold = new Date();
            console.log('itemtaphold');
        }
    }
    Of course you would need to clean up the lastTapHold property or it could be a memory leak.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha User
    Join Date
    Jul 2012
    Posts
    5
    Vote Rating
    0
    jase7777 is on a distinguished road

      0  

    Default


    I wasn't able to get that example working as expected but got around it by disabling list events in the itemtaphold event.

    This is the skeleton code (in controller) -

    Code:
    'myList list': {
        itemtap: 'doSomething',
        itemtaphold: 'doSomethingElse'
    },
    
    doSomethingElse: function(list, index, element, record) {    
        /* stop the itemtap event */
        list.suspendEvents(false);
            
        Ext.Msg.confirm('Confirmation box Title', 'Text inside ', function(btn, text){
                if (btn == 'ok'){
                                   //some processing
                }
    
                /* unblock itemtap */
                list.resumeEvents();
        });
    },
    Not sure if this is a better way to do it. I'm quite new to Sencha so still trying to get my head around the concepts.

  5. #4
    Sencha User
    Join Date
    Nov 2010
    Posts
    118
    Vote Rating
    9
    Bunchofstring will become famous soon enough

      1  

    Default


    In my onTapHold handler function, I have:
    Code:
    target.onBefore('tap',function(e){
        e.stopEvent();
    },this,{single:true});
    Basically, it prevents the next tap event from firing on the particular list item (element). There may be drawbacks to this approach, but it works for me.

    Edit: @Mitchell's looks a bit better because it'll still work if someday the Sencha team decides that itemtaphold shouldn't also fire taphold. My code would prevent the next completely independent itemtap... which would be bad :o(

  6. #5
    Sencha User
    Join Date
    Sep 2011
    Location
    Boston
    Posts
    137
    Answers
    5
    Vote Rating
    6
    drb is on a distinguished road

      1  

    Default


    Why would it be a memory leak?