I have the following NavigationController that lives in android and iphone folders:
Android
var NavigationController = function() {
var self = this;
self.open = function(windowToOpen) {
windowToOpen.navBarHidden = windowToOpen.navBarHidden || false;
if(!self.rootWindow) {
windowToOpen.exitOnClose = true;
self.rootWindow = windowToOpen;
}
windowToOpen.open();
};
self.close = function(windowToClose) {
windowToClose.close();
};
return self;
};
module.exports = NavigationController;
iphone
var NavigationController = function() {
var self = this;
function createNavGroup(windowToOpen) {
self.navGroup = Ti.UI.iPhone.createNavigationGroup({
window : windowToOpen
});
var containerWindow = Ti.UI.createWindow();
containerWindow.add(self.navGroup);
containerWindow.open();
};
self.open = function(windowToOpen) {
if(!self.navGroup) {
createNavGroup(windowToOpen);
}
else {
self.navGroup.open(windowToOpen);
}
};
self.close = function(windowToClose) {
if(self.navGroup) {
self.navGroup.close(windowToClose);
}
};
return self;
};
module.exports = NavigationController;
Then you can just use it (you will automatically get the correct option depending on the execution time):
var NavigationController = require('NavigationController')
var MyView = require("ui/MyView");
var controller = new NavigationController();
var myView = new MyView(controller);
controller.open(myView);
You can continue to open windows, and they go on the stack. Please note that I passed the controller to the first view. You keep doing this:
controller.open(new SecondView(controller));
back . , , :
controller.close(myView);