Decouple Controller and View in Sencha MVC

The MVC Architecture for Ext JS and Touch provides a solid foundation for building large and scalable apps; but if you follow the guides and implement in the way described you’ll notice that controllers and views are highly coupled. Controllers associate listeners to view events using component queries, thus making them aware of how the view is composed. As result we have a MVC architecture where the view is very light and does nothing but define components, and controllers will do all the heavy lifting by responding to user gestures, updating the view, dealing with models, business logic and more.
Continue reading

LinkedInDeliciousPinterestTumblrEmailShare

Native Mobile to Web #2: Path Menu

Original iOS Interface

Here it is, another post where I take some cool native UI and reproduce using only HTML5 technologies. The first one was the Facebook Login page. The result was a pixel perfect UI, just as nice as the native one. Now I’m taking the Path animated menu!

For those who don’t know Path, it’s a social network for connecting with family and close friends, available for iOS and Android. It has very interesting features, but the thing that really caught my attention was their “fan-out animated menu”. When you tap the menu, the options fan out, with a nice circular animation. It’s so cool that I had to take this UI and port it. I translated <divs> to Ext.Buttons, created the CSS3 animation and calculations, so everything works properly with Touch components.
Continue reading

LinkedInDeliciousPinterestTumblrEmailShare

Advanced CSS3 animations with Sencha Touch


Touch has some nice CSS3 animations like slide, flip, fade, pop and cube…but what if you need something different, like a custom slide-fade animation?

I’ve covered how to use animations in Using CSS3 animations on Sencha Touch and Animate components in a view, but I didn’t cover the internals of the framework, nor how can you create a custom animation. So let’s take a look at it, step by step.
Continue reading

LinkedInDeliciousPinterestTumblrEmailShare

Sencha Performance Tips #1: Avoid Overnesting

As a member of the Professional Services Team here at Sencha, we are often asked for fix problems in our client’s apps. And the number one issue we can immediately detect is overnesting. But what’s overnesting, why it’s bad and how can we avoid it? Let’s check it out!

What is overnesting?

I’ve picked some quotes from our Sencha Forum users trying to verbalize what it is:

Overnesting is using an additional container that doesn’t actually do anything besides containing another component.

It adds no extra functionality, it’s a useless container…

Overnesting refers to nesting without reason.

Again, useless container…

Overnesting means have redundant panels in the hierarchy.

Good, has to do with the hierarchy…

Maybe it’s still not very clear…let’s see some code:
Continue reading

LinkedInDeliciousPinterestTumblrEmailShare

Animate components in a view

Since the last post (Using CSS3 animations on Sencha Touch) was about animations, and I stumbled upon this question at Sencha’s forum, I thought I would develop a simple demo showing how to take a view, and animate random components inside it.

Obviously there are simple page animations, such as with a card layout, but I’m looking for the right approach to animate an object like a button – for example to get it to fly in from the side after a delay, after the view is loaded.

Here’s hoping someone will take pity on me, and spell it out!

Allister

Continue reading

LinkedInDeliciousPinterestTumblrEmailShare

Using CSS3 animations on Sencha Touch

So you’ve seen all those cool animations on Touch demos right? Cards with slide effect, Message boxes that pop or fade out, etc… Here are some quick examples and tips on how you can change default animations and add more style to your app.

There’s basically 3 ways you can embed animations in your views:

  1. show(animationCfg) method: pass an individual config with show/hide methods
  2. showAnimation & hideAnimation configs
  3. animations with card layout

Continue reading

LinkedInDeliciousPinterestTumblrEmailShare

How to create a mobile Flickr app with Sencha Touch 2

Touchr App

The best way for developers to learn new technology is definitely coding. For learning the new changes introduced with Touch 2, I created this little app that I called Touchr. It features some common components and basic filtering interaction, but also a customized proxy with YQL integration to consume Flickr. Check the list:

  • MVC architecture
  • Customized JSONP proxy that consumes YQL queries
  • Use of sencha.io service to resize images, optimizing for mobile screens.
  • Use of controller listeners to filter data stores
  • Use of TabPanel, DataView, Buttons, Toolbar, TextField
  • Use of custom theme to define new color, new icons and css optimizations

In this post I’ll share some details so you can also exercise some Touch skills as well!
Continue reading

LinkedInDeliciousPinterestTumblrEmailShare

Quick Touch 2 scaffolding example

The new Sencha Touch 2 framework ships with a terminal SDK that makes it easier than ever to create, pack and deploy your application. Let’s take a look on how we start a brand new project with Touch 2.

First of all, make sure you check the official guide Using Sencha Command. It will help you have everything setup.

Scaffolding a new project requires a simple command.

sencha app create <namespace> <path_to_project>

The trick here is that you need to be at the sencha framework folder to execute this line. If you execute sencha app create from any other folder, it won’t work. Continue reading

LinkedInDeliciousPinterestTumblrEmailShare

Construindo um aplicativo com Ext 4 – Parte 2

Sorry, this entry is only available in Português.

No post anterior iniciamos a estrutura da nossa aplicação de blog. Agora vamos ver melhor a respeito da arquitetura MVC do Ext JS 4.

Model

1. Criar model no arquivo app/model/Post.js

Ext.define('EB.model.Post', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'id',		type: 'int'     },
        {name: 'title',		type: 'string'  },
        {name: 'content',	type: 'string'  }
    ],
	proxy: {
		type: 'ajax',
        url: 'data/posts.json',
        reader: {
            type: 'json',
			root: 'posts',
			idProperty: 'id'
        }
    }
});

2. Criar store no arquivo app/store/Posts.js

Ext.define('EB.store.Posts', {
    extend      : 'Ext.data.Store',
    model       : 'EB.model.Post'
});

3. Criar dados fictícios no arquivo data/posts.json

{
	"posts": [
		{"id":1, "title": "Post 1", "content": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id nisl tellus, nec pretium tortor. Duis luctus posuere felis vitae viverra. Vivamus nisl purus, pulvinar eget rhoncus et, mattis nec leo. Donec sagittis ultrices molestie. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas."},
		{"id":2, "title": "Post 2", "content": "In hac habitasse platea dictumst. Nam commodo, augue id consequat ultricies, lacus augue pharetra odio, in aliquet neque magna vitae ipsum. Praesent porta dictum nibh, quis aliquam tortor volutpat nec. Nulla egestas nibh ac neque congue eu commodo dui elementum. Sed interdum massa sit amet odio aliquet at blandit mauris condimentum."},
		{"id":3, "title": "Post 3", "content": "Vestibulum commodo pellentesque sagittis. Nullam sed venenatis mi. Etiam convallis turpis at velit faucibus lobortis. Sed pretium viverra dui vitae adipiscing. Quisque mattis mollis lectus. Nullam a convallis sapien. Donec vitae eleifend ipsum. Nam tortor ipsum, ultrices eget feugiat nec, sodales et magna."}
	]
}

Fazendo desta forma a nossa camada de dados está pronta. Temos um model, aonde descrevemos os campos que o compõem, e o proxy que fará a conexão com o servidor. Definimos também o reader, que é o responsável por traduzir os dados que vêm do servidor para que o Ext possa criar as instâncias do model.

View

Agora vamos criar a listagem de posts, no arquivo app/view/post/List.js

Ext.define('EB.view.post.List',{
    extend  : 'Ext.view.View',
    alias   : 'widget.postlist',
    
//inits
    initComponent: function()
    {
        Ext.apply(this,{
			title		: 'Posts',
			store		: 'Posts',
			itemSelector: 'div.post-wrap',
			tpl			: new Ext.XTemplate(
			    '<tpl for=".">',
					'<div style="margin-bottom: 10px;" class="post-wrap">',
						'<h2>{title}</h2>',
						'<p>{content}</p>',
			        '</div>',
			    '</tpl>'
			)
		});
        
		this.callParent(arguments);
		this.store.load();
    }
});

EB.view.post.List é uma view bem simples. Ela extende de Ext.view.View, definindo o store e também o template utilizado para essa listagem. Vamos deixar os links de edição e exlusão de fora por enquanto.

Controller

Este é a parte responsável por juntar models, stores, views, e adicionar os eventos e interações. Por enquanto não vamos definir os eventos, vamos só criar o arquivo app/controller/Posts.js e juntar todas as partes

Ext.define('EB.controller.Posts', {
    extend  : 'Ext.app.Controller',
    views   : ['post.List'],
    models  : ['Post'],
	stores	: ['Posts']
});

Unindo as partes

Vamos adicionar o controller Posts à nossa definição de application em app.js

Ext.application({
    name: 'EB',					//app namespace (from ExtBlog)
    controllers: ['Posts'],		//here goes the controllers
    autoCreateViewport: true	//automatically creates Viewport
});

O app.js é nosso arquivo de entrada. Ele irá disparar o carregamento de controller definido em app/controller/Posts.js. Como dentro do nosso controller nós indicamos suas views, models e stores envolvidas, estes também serão carregados. No final temos tudo carregado e pronto para o uso!

Basta agora adicionar nossa listagem de posts ao Viewport, usando diretamente o alias postlist

//...	
	xtype: 'tabpanel',
	region: 'center',
	items: [{
		xtype: 'postlist'
	},{
		title: 'Post 1',
		html: '...post 1...'
	}]
//...

Como resultado já podemos ver nossa listagem de arquivos sendo carregada. A estrutura MVC do Ext 4 permite que cada diferente parte de uma interface seja definida no seu devido lugar.

Apesar de termos já uma listagem, ainda falta interação para abrir o post e também as regras SASS para deixar a interface do jeito que queremos. Tudo isso será feito no próximo post!

LinkedInDeliciousPinterestTumblrEmailShare