Results 1 to 6 of 6

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

  1. #1
    Ext GWT Premium Member
    Join Date
    Aug 2011
    Posts
    7
    Vote Rating
    1
      1  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,553
    Answers
    3931
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    Jul 2012
    Posts
    5
    Vote Rating
    0
      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
      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
    149
    Answers
    5
    Vote Rating
    7
      1  

    Default

    Why would it be a memory leak?

  7. #6
    Sencha User
    Join Date
    Oct 2014
    Posts
    6
    Vote Rating
    0
      0  

    Default Onitem tap is not workinng if we use on itemtap hold

    Hi

    I have a list where i need to popup a message on itemtap hold and on itemtap it should go to another view.

    Two listeners on the same list. I am able to workout only itemtaphold but not itemtap,itemtap alone works without itemtaphold, if i keep itemtaphold listener itemtap event wnt trigger. I need two events to be triggered for the same list. Please help me with it.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •