I have been writing about Sencha Touch and Cordova for some time now. In a way, it is the documentation of my learning of these two platforms in the last couple of months, which might help somebody out there struggling with the same issues, which I once had. I had never used Sencha Architect for my development environment. I am using Visual Studio as a Text Editor as well as Packager for Cordova Applications with TACO extension.
In my path of mastering Cordova and Sencha Touch, I have stumbled upon building the orientation aware Applications, using these frameworks and this is the part 1 of a multi-part tutorial about how to create orientation aware, cross-platform Application, using these two frameworks.
For any orientation aware Application, there are two things, which the developer should take care of:
- Device orientation at the start of the Application.
- Orientation change events.
We need to look into the Application architecture to decide, how to incorporate the orientation change in the Application. As you know, Sencha Touch framework works on MVC architecture with a slight twist of Stores and Profiles. If you are interested in Sencha Touch architecture and how profiles work in Sencha Touch, this post might be useful for you. Right now, our focus is not on Models, Controllers, and Stores but purely on Views of the Application as the orientation will only affect the views of the Application. In the context of Sencha Touch, profiles also play a crucial role, while designing an orientation awareness. A lot of times, your views are different for the different profiles of the Application. For the simplicity of the tutorial, I am going to take two profiles - one tablet and one phone and build orientation awareness for both of them.
Here are the steps, which we are going to follow, while building orientation aware Applications:
- Create a sample Application with the two profiles – Tablet and Mobile.
- Install Orientation Plugin from Cordova plugin manager.
- Create views and controller.
- Add views to the viewport, based on the orientation of the device at the start of the Application.
- Handle the orientation change event.
- Take care of the stylesheets.
To start with, I created a sample Cordova Application in Visual Studio 2015, named OrientationTutorial. I added Sencha-Touch-Debug.js and Sencha-Touch.css files to my Application’s root folder and loaded them in index.html. Pretty normal stuff, isn’t it? The tricky part is, unlike Sencha Architect, Visual Studio doesn’t have the desired visual builder for Sencha Touch, which can let you build your views, controllers, models, stores, profiles in the different folders and build a nice app.js for you in the end. Thus, we have to do it ourselves.
In app.js, I created the Application while in View, Profile and Controller folders, I created respective Views, profiles and the controllers. I load all the files in index.html body and pray to God that everything works fine. (Kidding, when Sencha Touch breaks, even God cannot fix it). Solution Explorer looks like:
Main View is basically just the toolbar on the top of the Application. Home View has some example buttons, which does nothing basically. (At least for now). Thus, here is how, we are going to do it. We create Main View, which is a container with a toolbar on the top and stick it to the Application forever. Based on the orientation of the application we change, add the appropriate Home View to the application.
Go to config.xml, open plugin tab, and add orientation plugin to your application. It should look something like this:
I have created the Main View at the launch of the respective profile. That means the Main View is added when the phone/tablet profile is launched.
All the default Views, such as homePhone and homeTablet are by default landscape Views. We will create portrait View differently. For that, add the folder to the View folder called ‘portrait’. Inside this, create homePortrait View.
Now, some important things. In our design architecture, we are going to create Views, based on their aliases. Sencha Touch creates aliases, based on xtypes in the background, which means we cannot use the same xtype for the Views, which are essentially the same , but are designed differently for the different profiles and orientation. For example, Home View has 5 buttons and all works in the similar fashion but, based on whether the view is rendered on a tablet or a phone and whether the orientation is a portrait or a landscape, the position of these buttons change. Thus, for these different renderings, we have different Views but we might need the same xtype in the Controller for these Views to tie these to some Model or load the data from the Store.








Mehul PrajapatiPosted Feb 3, 2018, 1:21 AM
Hi, Indraneel. I have issue in cordova app development using visual studio 2015 and framework7. so i need your help.http://www.c-sharpcorner.com/forums/unicode-text-issue-with-html-sub-pages-in-cordova
Ramesh PalaniappanPosted Aug 22, 2016, 1:49 AM
Good One
RajaPosted Aug 22, 2016, 12:14 AM
Good One....
Shamim UddinPosted Aug 21, 2016, 12:51 AM
Nice