Skip to content

Instantly share code, notes, and snippets.

@zaherg
Forked from aaronksaunders/app.js
Created September 15, 2012 10:19
Show Gist options
  • Save zaherg/3727267 to your computer and use it in GitHub Desktop.
Save zaherg/3727267 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment