-
26 Mar 2012 1:01 PM #1
Profile isActive is not taken into account
Profile isActive is not taken into account
I have created profiles as per the documentation (tablet and phone). If I create a profile and return false from the isActive method, the profile is still loaded and the views from that profile are displayed. Moreover, if I load multiple profiles and they all return false (meaning I wish for the default views to display), random profile views are used (sometimes tablet, sometimes phone.
-
26 Mar 2012 4:03 PM #2Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Redwood City, California
- Posts
- 3,652
- Vote Rating
- 14
Thank you for the report.
-
27 Mar 2012 11:36 AM #3Sencha - Community Support Team
- Join Date
- Jan 2009
- Location
- Palo Alto, California
- Posts
- 1,941
- Vote Rating
- 6
Loading all classes for all Profiles is actually the intended behavior - if we didn't do this then production builds would not work correctly. As it stands, a production build is a universal app - it works on all Profiles you have defined, without using dynamic loading in production.
Ext JS Senior Software Architect
Personal Blog: http://edspencer.net
Twitter: http://twitter.com/edspencer
Github: http://github.com/edspencer
-
27 Mar 2012 11:39 AM #4
I don't mind what it loads. I mind that isActive is not working. If isActive returns false, it should not be the active profile, so how is it that my view from that profile is being displayed?
-
27 Mar 2012 11:40 AM #5Sencha - Community Support Team
- Join Date
- Jan 2009
- Location
- Palo Alto, California
- Posts
- 1,941
- Vote Rating
- 6
The Profile itself doesn't determine which views your app instantiates. At some point your code must be calling something like Ext.create('MyApp.view.someProfile.someView') - the framework doesn't do that for you, it's all in the app itself.
Ext JS Senior Software Architect
Personal Blog: http://edspencer.net
Twitter: http://twitter.com/edspencer
Github: http://github.com/edspencer
-
27 Mar 2012 11:58 AM #6
According to the docs here: http://docs.sencha.com/touch/2-0/#!/guide/profiles, this does not seem to be correct:
"Once the Profiles have been loaded, their isActive functions are called in turn. The first one to return true is the Profile that the Application will boot with" and "Now when we load the app on a phone, the Phone profile is activated and the application will load the following files:"
Clearly the application is making the decision about which profiles to launch. In our application our views are being autocreated via their xtype as such:
this.getNav().push(
{
xtype: 'vehicleDetail'
}
);
If I have profiles defined in my application controller: profiles: ['Tablet', 'Phone'], then the above code AUTOMATICALLY creates a view from one of the profiles, even though both profiles are marked as inActive. If I remove the profile declaration, then the default views are created.
-
27 Mar 2012 12:33 PM #7Sencha - Community Support Team
- Join Date
- Jan 2009
- Location
- Palo Alto, California
- Posts
- 1,941
- Vote Rating
- 6
Ah - sounds like you're registering the same xtype for both the Phone and Tablet profiles, is that correct? That's one are where our guidance could be better - in general that pattern is not a good one as it makes the xtype mapping potentially nondeterministic. I would suggest you use unique xtypes for every component (even if it's just a Profile-specific variant) until we figure out a more elegant solution to this
Ext JS Senior Software Architect
Personal Blog: http://edspencer.net
Twitter: http://twitter.com/edspencer
Github: http://github.com/edspencer
-
28 Mar 2012 5:33 AM #8
Yes, that was it. I had multiple views with the same xtype. My mistake. So what I did was implement my own "View Factory", using the current active profile, something like:
createView: function (viewName, profile) {
var view = null;
if (profile)
view = Ext.create('App.view.' + profile._namespace + '.' + viewName);
else
view = Ext.create('App.view.' + viewName);
return view;
},
getView: function (className) {
var profile = this.getApplication().getCurrentProfile();
var views = profile.getViews();
if (views.indexOf(className) > -1)
return this.createView(className, profile);
else
return this.createView(className);
},
pushView: function (className, title) {
var view = this.getView(className);
var nav = this.getNav();
nav.push(view);
nav.getNavigationBar().titleComponent.setTitle(title);
}
So I can push views onto my navigator like this:
this.pushView('MyViewClassName', 'Some view title');
-
28 Mar 2012 10:32 AM #9Sencha - Community Support Team
- Join Date
- Jan 2009
- Location
- Palo Alto, California
- Posts
- 1,941
- Vote Rating
- 6
Awesome, glad you were able to solve it

The framework really should offer a neat way to do this without the confusion though, I don't know what the solution looks like yet (could just be some written conventions) but it's something we're thinking aboutExt JS Senior Software Architect
Personal Blog: http://edspencer.net
Twitter: http://twitter.com/edspencer
Github: http://github.com/edspencer
-
30 Mar 2012 10:01 PM #10
Had exactly the same problem - tearing my hair out on this one.
I assumed I could use same xtype across platforms and that profile executed views down the tree from its initial view loaded - even using fully pathed 'requires' statements didnt help.
profile specific xtypes fixed it - thx.
Yes I think some guidance around this in the doco on profiles would be great.
cheers
Looks like we can't reproduce the issue or there's a problem in the test case provided.


Reply With Quote