Skip to content

Modus-Logo-Long-BlackCreated with Sketch.

  • What we do
  • Who we are
    Our story

    Learn about our values, vision, and commitment to client success

    Open source

    Discover how we contribute to and benefit from the global open source ecosystem

    Careers

    Join our dynamic team and shape the future of digital transformation

    How we built our unique culture
  • Who we serve
    Life Sciences

    Advancing health with smarter technologies

    Financial Services

    Building trust through secure, digital solutions

    Automotive

    Driving innovation in mobility and manufacturing

    Retail

    Enhancing customer experiences across every channel

    industries-menu-cta
  • Our work
  • Our blog
  • Resources
  • Get in touch
  • EN
  • FR

Sencha Touch 2 Touch Events Re-firing

Published on July 11, 2012
Last Updated on June 11, 2020
Application Development

While generally we try to avoid native browser alert() and confirm() we sometimes have no control over their use. I have come across a situation where working in a Native iOS app that a certain call caused a confirm dialog to pop up. This call was triggered from a tap event on a custom button.

Here’s an example of what happens:

This scenario was done on iOS Simulator 5.1 iPad mode with the app on the home screen.
Mobile Safari exhibits the same results.
Console logging/remote debugging is provided by weinre

The code behind this:

Ext.define("Storefront.view.Test", {
    extend : 'Ext.Container',
    xtype  : 'test',
    config : {
        centered : true,
        tpl      : '<div class="sf-button sf-button-main">Hello World</div>',
        data     : {}
    },
    initialize   : function() {
        this.callParent();
        this.element.on({
            tap        : this.onTap,
            touchstart : this.onTouchStart,
            touchend   : this.onTouchEnd,
            delegate   : '.sf-button'
        });
    },
    onTap        : function(evtObj) {
        alert('button tapped');
    },
    onTouchStart : function(evtObj) {
        console.log('touchstart fired ' + evtObj.getTime());
        var btn = evtObj.getTarget('.sf-button');
        if(btn) {
            Ext.fly(btn).addCls("sf-button-pressed-main");
        }
    },
    onTouchEnd   : function(evtObj) {
        console.log('touchend fired ' + evtObj.getTime());
        var btn = evtObj.getTarget('.sf-button');
        if(btn) {
            Ext.fly(btn).removeCls("sf-button-pressed-main");
        }
    }
});

To alleviate this issue, all we have to do is wrap the alert in a setTimeout. The setTimeout forces the function to execute after the touch event cycle has fully completed.

onTap        : function(evtObj) {
    setTimeout(function() {
        alert('button tapped');
    }, 0);
}

Further reading:

  • Mozilla MDN setTimeOut
  • How JavaScript Timers Work – John Resig
Posted in Application Development
Share this

Stan Bershadskiy

Stan Bershadskiy specializes in all things JavaScript with vast knowledge in Sencha frameworks. Recently, he has directed his focus towards React Native and has co-authored The React Native Cookbook. Stan is located in New York City and can be found presenting at conferences around the country. During his time with Modus Create, Stan filled the role of Architect.
Follow

Related Posts

  • Touch DJ A Sencha Touch DJ App
    Touch DJ - A Sencha Touch DJ App

    During the DJing with Sencha Touch talk at SenchaCon 2013 we finally unveiled and demonstrated…

  • Touch DJ A Sencha Touch DJ App
    Touch DJ - A Sencha Touch DJ App

    During the DJing with Sencha Touch talk at SenchaCon 2013 we finally unveiled and demonstrated…

Want more insights to fuel your innovation efforts?

Sign up to receive our monthly newsletter and exclusive content about digital transformation and product development.

What we do

Our services
AI and data
Product development
Design and UX
Modernization
Platform and MLOps
Developer experience
Security

Our partners
Atlassian
AWS
GitHub
Other partners

Who we are

Our story
Careers
Open source

Our work

Our case studies

Our resources

Blog
Innovation podcast
Guides & playbooks

Connect with us

Get monthly insights on AI adoption

© 2025 Modus Create, LLC

Privacy PolicySitemap
Scroll To Top
  • What we do
  • Who we are
    • Our story
    • Careers
    • Open source
  • Who we serve
    • Life Sciences
    • Automotive
    • Financial Services
  • Our work
  • Our blog
  • Resources
  • Get in touch
  • EN
  • FR