Skip to content

Instantly share code, notes, and snippets.

@aaronksaunders
Created May 22, 2012 00:29
Show Gist options
  • Save aaronksaunders/2765676 to your computer and use it in GitHub Desktop.
Save aaronksaunders/2765676 to your computer and use it in GitHub Desktop.
Using Swipes to open and close windows in a navigation group with titanium appcelerator
//
// Aaron K. Saunders
//
// http://www.clearlyinnovative.com
// http://blog.clearlyinnovative.com
// @aaronksaunders
//
//
(function() {
var group, tab1, tab2, win1, win2;
group = Ti.UI.createTabGroup();
var windowFactory = function(options) {
this.tab = options.tab;
this.win = Ti.UI.createWindow({
title : options.title || 'Window 1'
});
this.win.addEventListener('swipe', function(e) {
Ti.API.info('swipe fired x ' + e.x + ' y ' + e.y + ' direction ' + e.direction);
if(e.direction === 'left') {
var newWindow = windowFactory({
"title" : new Date(),
"tab" : e.source.tab
}).win
e.source.tab.open(newWindow)
} else if(e.direction === 'right') {
e.source.close();
}
});
return this;
}
win1 = Ti.UI.createWindow({
title : 'Window 1'
});
win1.addEventListener('click', function(e) {
group.activeTab.open(windowFactory({
"title" : new Date(),
"tab" : group.activeTab
}).win);
});
win2 = Ti.UI.createWindow({
title : 'Window 2'
});
tab1 = Ti.UI.createTab({
window : win1,
title : 'Tab 1'
});
tab2 = Ti.UI.createTab({
window : win2,
title : 'Tab 2'
});
group.addTab(tab1);
group.addTab(tab2);
group.open();
}).call(this);
@bhurlow
Copy link

bhurlow commented Jun 27, 2012

cool idea

@frodfigu
Copy link

frodfigu commented Apr 7, 2015

Do you know in iOS 8 how can I get the native behavior with a custom leftNavButton in my window (into navigation window) Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment