-
1 Aug 2012 11:30 AM #1
Answered: Ext.app.Application.setCurrentProfile
Answered: Ext.app.Application.setCurrentProfile
I am attempting to programatically switch the active profile and redraw the viewport whenever the orientation changes. I was hoping for something like ST1's determineProfile function, which would scan all profiles and switch to whichever is active, but ST2 does not seem to have that functionality. I wrote a simple controller, and the profile is being set (I can call getCurrentProfile afterwards to see the change), but the profile's launch function is not called and the viewport is not being redrawn. Can anyone tell what I am missing?
Code:Ext.define('SenchaProfiles.controller.Main', { extend: 'Ext.app.Controller', config: { refs: { viewport: 'viewport', }, control: { viewport: { orientationchange: 'handleOrientationChange' } } }, handleOrientationChange: function(viewport, orientation, width, height){ var currOrientation = Ext.Viewport.determineOrientation(); if (currOrientation == 'portrait') SenchaProfiles.app.setCurrentProfile(Ext.create('SenchaProfiles.profile.TabletPortrait')); else if (currOrientation == 'landscape') SenchaProfiles.app.setCurrentProfile(Ext.create('SenchaProfiles.profile.TabletLandscape')); } });Last edited by MattUCG; 1 Aug 2012 at 12:12 PM. Reason: more specific question
-
Best Answer Posted by MattUCG
All I was missing was a manual call to the profile's launch function:
Code:Ext.define('SenchaProfiles.controller.Main', { extend: 'Ext.app.Controller', config: { refs: { viewport: 'viewport', }, control: { viewport: { orientationchange: 'handleOrientationChange' } } }, handleOrientationChange: function(viewport, orientation, width, height){ var currOrientation = Ext.Viewport.determineOrientation(); if (currOrientation == 'portrait') SenchaProfiles.app.setCurrentProfile(Ext.create('SenchaProfiles.profile.TabletPortrait')); else if (currOrientation == 'landscape') SenchaProfiles.app.setCurrentProfile(Ext.create('SenchaProfiles.profile.TabletLandscape')); SenchaProfiles.app.getCurrentProfile().launch(); } });
-
1 Aug 2012 12:27 PM #2
All I was missing was a manual call to the profile's launch function:
Code:Ext.define('SenchaProfiles.controller.Main', { extend: 'Ext.app.Controller', config: { refs: { viewport: 'viewport', }, control: { viewport: { orientationchange: 'handleOrientationChange' } } }, handleOrientationChange: function(viewport, orientation, width, height){ var currOrientation = Ext.Viewport.determineOrientation(); if (currOrientation == 'portrait') SenchaProfiles.app.setCurrentProfile(Ext.create('SenchaProfiles.profile.TabletPortrait')); else if (currOrientation == 'landscape') SenchaProfiles.app.setCurrentProfile(Ext.create('SenchaProfiles.profile.TabletLandscape')); SenchaProfiles.app.getCurrentProfile().launch(); } });
-
1 Aug 2012 12:35 PM #3
Before you changed your code you checked to see if the profile was active, but you didn't call the function right.
you had
when it should beCode:if(profiles[i].isActive)
Code:if(profiles[i].isActive())
-
1 Aug 2012 12:52 PM #4
That doesn't seem to work. The array returned by getProfiles() contains strings, not objects. When I call isActive() on profiles[i], i get:
Uncaught TypeError: Object SenchaProfiles.profile.TabletPortrait has no method 'isActive'
-
1 Aug 2012 12:57 PM #5
So the strings it passes you is SenchaProfiles.profile.TabletPortrait?
If so, then it should not be adding the Object part
Do you define the isActive function in your definition of SenchaProfiles.profile.TabletPortrait and other profiles?
Code://for Phone isActive: function(){ return Ext.os.is.Phone; }
-
1 Aug 2012 1:08 PM #6
I am defining isActive in the profile.
It's adding "object" because I am treating the string like an object. Running the following line of javascript demonstrates:
"test".hello()
TypeError: Object test has no method 'hello'
-
1 Aug 2012 2:16 PM #7
True. I figured getProfiles() would return the actual Profile objects and not just what is declared in the 'profiles' config array. I see now how your new code will work.



Reply With Quote