1. #1
    Sencha User
    Join Date
    Sep 2011
    Posts
    60
    Answers
    3
    Vote Rating
    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
    Gainesville, FL
    Posts
    36,632
    Answers
    3452
    Vote Rating
    817
    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


    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
    ________________
    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.

Thread Participants: 1