1. #1
    Sencha User
    Join Date
    Sep 2011
    Posts
    60
    Vote Rating
    3
    Answers
    3
    janelle is on a distinguished road

      0  

    Default Unanswered: Why is onOrientationChange being triggered twice?

    Unanswered: Why is onOrientationChange being triggered twice?


    When I change the orientation, its triggering the call to onOrientationChange twice for each time it changes. Is it supposed to do that? I will be putting some code in there to alter the layout, and I dont want to have it called twice.

    Code:
    app.views.Viewport = Ext.extend(Ext.TabPanel, {
        fullscreen: true,
        id: 'viewport',
        layout: 'card',
        monitorOrientation: true,
        tabBar: {
            dock: 'bottom',
            ui: 'light',
            layout: {pack: 'center'}
        },
        cardSwitchAnimation: 'slide',
        initComponent: function() {
            // ...
            
            app.views.Viewport.superclass.initComponent.apply(this, arguments);
        },
                                    
        onOrientationChange: function(orientation, w, h)
        {
            console.log(orientation);
            console.log(w);
            console.log(h);
        }
    });
    
    
    Ext.regApplication({
        name: 'app',
        setup: 
        {
            phoneStartupScreen: "img/test.jpg"
        },
        launch: function() 
        {
            this.launched = true;
            this.mainLaunch();
        },
        mainLaunch: function() 
        {
            
            if(!device || !this.launched)
            {
                return;
            }
                       
            this.views.viewport = new this.views.Viewport();
        }
    });

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,624
    Vote Rating
    435
    Answers
    3106
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    It will fire when the browser's resize event is thrown. Is the orientationchange event fired twice? It would be simple to buffer them to only fire once:

    Code:
    this.on('orientationchange', someFn, this, { buffer : 50 });
    50 is the number of milliseconds to buffer the event firings together. Basically only the last one in that 50ms will fire.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    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 almost in print!

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