├── NavigationController.js └── README /NavigationController.js: -------------------------------------------------------------------------------- 1 | exports.NavigationController = function() { 2 | this.windowStack = []; 3 | this.theCurrentWindow = null; 4 | this.platformName = Ti.Platform.osname; 5 | }; 6 | 7 | exports.NavigationController.prototype.open = function(/*Ti.UI.Window*/windowToOpen) { 8 | 9 | var windows = this.windowStack.concat([]); 10 | 11 | if(windows.length === 0 && this.theCurrentWindow != null) { 12 | this.windowStack.push(this.theCurrentWindow); 13 | } 14 | 15 | //add the window to the stack of windows managed by the controller 16 | this.windowStack.push(windowToOpen); 17 | this.theCurrentWindow = windowToOpen; 18 | 19 | var windows = this.windowStack.concat([]); 20 | 21 | //grab a copy of the current nav controller for use in the callback 22 | var that = this; 23 | windowToOpen.addEventListener('close', function() { 24 | that.windowStack.pop(); 25 | }); 26 | 27 | //hack - setting this property ensures the window is "heavyweight" (associated with an Android activity) 28 | windowToOpen.navBarHidden = windowToOpen.navBarHidden || false; 29 | 30 | //This is the first window 31 | if(this.windowStack.length === 1) { 32 | 33 | if(this.platformName === 'android') { 34 | windowToOpen.exitOnClose = true; 35 | windowToOpen.open(); 36 | } else { 37 | this.navGroup = Ti.UI.iPhone.createNavigationGroup({ 38 | window : windowToOpen 39 | }); 40 | var containerWindow = Ti.UI.createWindow(); 41 | containerWindow.add(this.navGroup); 42 | containerWindow.open(); 43 | } 44 | } 45 | //All subsequent windows 46 | else { 47 | if(this.platformName === 'android') { 48 | windowToOpen.open(); 49 | } else { 50 | this.navGroup.open(windowToOpen); 51 | } 52 | } 53 | }; 54 | 55 | //go back to the initial window of the NavigationController 56 | exports.NavigationController.prototype.home = function() { 57 | //store a copy of all the current windows on the stack 58 | var windows = this.windowStack.concat([]); 59 | 60 | for(var i = 1, l = windows.length; i < l; i++) { 61 | if(this.platformName == 'android') { 62 | windows[i].close(); 63 | }else{ 64 | this.navGroup.close(this.windowStack[i]); 65 | } 66 | } 67 | this.theCurrentWindow = this.windowStack[0]; 68 | this.windowStack = []; //reset stack 69 | this.windowStack.push(this.theCurrentWindow); 70 | 71 | 72 | }; 73 | 74 | exports.NavigationController.prototype.back = function(w){ 75 | //store a copy of all the current windows on the stack 76 | if(Ti.Platform.osname === 'android') { 77 | w.close(); 78 | }else{ 79 | var win = Titanium.UI.currentWindow; 80 | this.navGroup.close(this.windowStack[this.windowStack.length -1]); 81 | } 82 | }; 83 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This is a drop in replacement for the Cross-Platform NavigationController written by Kevin Whinnery, we found we were having severe issues getting the CommonJS version of this working on Android, and therefore re-wrote it, this now works as expected, we also implemented an additional function named back. --------------------------------------------------------------------------------