Created
September 1, 2011 18:33
-
-
Save pablasso/1186885 to your computer and use it in GitHub Desktop.
NavigationController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.NavigationController = function() { | |
this.windowStack = []; | |
}; | |
exports.NavigationController.prototype.open = function(/*Titanium.UI.Window*/windowToOpen) { | |
Titanium.API.info('nav OPEN triggered, old windowStack:' + this.windowStack.length); | |
this.windowStack.push(windowToOpen); | |
Titanium.API.info('nav OPEN triggered, new windowStack:' + this.windowStack.length); | |
var that = this; | |
windowToOpen.addEventListener('close', function() { | |
Titanium.API.info('nav CLOSE triggered, old windowStack:' + that.windowStack.length); | |
that.windowStack.pop(); | |
Titanium.API.info('nav CLOSE triggered, new windowStack:' + that.windowStack.length); | |
}); | |
// hack: ensures the window is "heavyweight" (associated with an Android activity) | |
windowToOpen.navBarHidden = windowToOpen.navBarHidden || false; | |
if (this.windowStack.length === 1) { | |
if (Titanium.Platform.osname === 'android') { | |
windowToOpen.exitOnClose = true; | |
windowToOpen.open(); | |
} | |
else { | |
this.navGroup = Titanium.UI.iPhone.createNavigationGroup({ | |
window:windowToOpen | |
}); | |
var mainWindow = Titanium.UI.createWindow(); | |
mainWindow.add(this.navGroup); | |
mainWindow.open(); | |
} | |
} | |
else { | |
if (Titanium.Platform.osname === 'android') { | |
windowToOpen.open(); | |
} | |
else { | |
this.navGroup.open(windowToOpen); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment