PDA

View Full Version : A better way to implement Back Button in Sencha Touch’s NavigationView



locutusUT
9 May 2013, 2:26 PM
Check out my blog on how to implement a simple device/browser back button solution here (http://loutilities.wordpress.com/2013/05/09/a-better-way-to-implement-back-button-with-sencha-touch-navigationview/). I've tested it successfully on several different phones including Android and iOS.

Kurt001
9 May 2013, 11:24 PM
I like that.
So far I was writing my own history controller to make sure I get the history I want, wiht the option to jump back to certain places.
But never used the history states.
Man - this really rocks and is so simple. :)

Porbalbly an override would do for the launch method.

About Android. Usually I add a event listener to Ext.Viewport.down('button[ui=back]') and do: setHidden(true).

As Android usually should be only used with the hardware back-button.

My way to do this is to listen to the hashchange event and pop the active item from the sencha history. At the same time I keep the sencha history to a minimum, so that sencha does not get confused, with what to do. So basically I keep it like a hashmap.

Kurt001
10 May 2013, 12:59 AM
Why do you not use replaceState() ?
You are not working with routes at all?

locutusUT
10 May 2013, 6:31 AM
Thanks Kurt for the comments...

Why pollute your application with a bunch of routing logic if it's not needed? This is the most elegant solution I've found and it works beautifully across many devices.

Also, my blot post talks about using with NavigationView...I wouldn't want to do this at the Viewport level because I want back button to be different depending the NV tab I'm on. Does that make sense?

Kurt001
10 May 2013, 7:16 AM
=D>

armode
29 May 2013, 2:48 AM
Thanks for sharing, this is an awesome and elegant idea!

I'm working on a ST app, that exists since ST1 and isn't still 100% MVC; that's why I had my own simple history for my back button. It's just an array of view IDs. But I never thougt about this history solution. It was really easy to implement on top of my back button logic and brings a big improvement for my Android customers.

Thanks again :)