1. #1
    Sencha User
    Join Date
    Feb 2012
    Location
    netherlands
    Posts
    11
    Vote Rating
    0
    pimskie is on a distinguished road

      0  

    Default Answered: Change layout on orientation change

    Answered: Change layout on orientation change


    Hey all, a common thing I guess but I haven't found a solution.

    I've got a panel with a hbox layout. When the orientation is changed to portrait I want the items underneath eachother, and so change the layout of the panel to vbox.

    I listen to the orientation event and execute this code:
    Code:
            
    handleOrientationChange: function(viewport, orientation, width, height) {
            var layout = (orientation == 'landscape') ? 'hbox' : 'vbox';
            this.getPage().setLayout(layout);
            console.log('layout set to ' + layout + ', ' + orientation);
            console.log(this.getPage());
        }
    In the console I see the layout property of the page is changed well, but the view isn't responding to it, I don't see anything change.

    Can anyone point me out what I'm doing wrong?

  2. Quote Originally Posted by mitchellsimoens View Post
    Changing layouts on the fly are supported fully currently.
    This would involve evaluating the DOM structure and add/delete/update the DOM elements to change the layout which is not currently supported natively. The JavaScript may be changed but the DOM may not be changed.

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,207
    Answers
    3517
    Vote Rating
    856
    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


    Changing layouts on the fly are supported fully currently.
    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
    Feb 2012
    Location
    netherlands
    Posts
    11
    Vote Rating
    0
    pimskie is on a distinguished road

      0  

    Default


    Thank you for the reply Mitchell. But in that case, the code I posted earlier should work?

    Do I have to update the component in some sort of way perhaps? Because I can't get it to work.
    More of the code from the controller:

    Code:
    createPage: function(orientation) {    	
         	var layout = (orientation == 'landscape') ? 'hbox' : 'vbox';
            
            var page = Ext.create('Ext.Panel', {
            	layout: layout,
            	id: 	'gallery',
            	items: [
            		{xtype: 'panel', html: 'one', flex: 1},
            		{xtype: 'panel', html: 'two', flex: 1},
            	],
            });       
    
    
            this.getPageContainer().setActiveItem(page);
        },
        
        
        handleOrientationChange: function(viewport, orientation, width, height) {
    		var layout = (Ext.Viewport.getOrientation() == 'landscape') ? 'hbox' : 'vbox';
    		this.getPage().setLayout(layout);
    		
    		console.log(this.getPage().getLayout());
        }
    As said, the console logs the correct layout of the page.

  5. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,207
    Answers
    3517
    Vote Rating
    856
    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


    Quote Originally Posted by mitchellsimoens View Post
    Changing layouts on the fly are supported fully currently.
    This would involve evaluating the DOM structure and add/delete/update the DOM elements to change the layout which is not currently supported natively. The JavaScript may be changed but the DOM may not be changed.
    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.

  6. #5
    Sencha User
    Join Date
    Feb 2012
    Location
    netherlands
    Posts
    11
    Vote Rating
    0
    pimskie is on a distinguished road

      0  

    Default


    Hey Mitchell, thanks for the reaction. That made the differences clear to me.

    Now I remove the component from the DOM first and add it again, solves the problem for me

  7. #6
    Sencha User
    Join Date
    Mar 2007
    Posts
    411
    Answers
    5
    Vote Rating
    18
    jweber will become famous soon enough

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    Changing layouts on the fly are supported fully currently.
    I assume you mean not supported.

Thread Participants: 2