forked from aaronksaunders/Titanium-Navigation-Controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavigationController.js
64 lines (56 loc) · 2.1 KB
/
NavigationController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var navigationController = {};
navigationController.windowStack = [];
navigationController.navGroup = {};
(function(){
navigationController.open = function(windowToOpen){
//add the window to the stack of windows managed by the controller
navigationController.windowStack.push(windowToOpen);
//grab a copy of the current nav controller for use in the callback
var that = this;
//hack - setting this property ensures the window is "heavyweight" (associated with an Android activity)
windowToOpen.navBarHidden = windowToOpen.navBarHidden || false;
//This is the first window
if(navigationController.windowStack.length === 1) {
if(Ti.Platform.osname === 'android') {
windowToOpen.exitOnClose = true;
windowToOpen.open();
} else {
navigationController.navGroup = Ti.UI.iPhone.createNavigationGroup({
window : windowToOpen
});
var containerWindow = Ti.UI.createWindow();
containerWindow.add(navigationController.navGroup);
containerWindow.open();
}
}
//All subsequent windows
else {
if(Ti.Platform.osname === 'android') {
windowToOpen.open();
} else {
navigationController.navGroup.open(windowToOpen);
}
}
};
navigationController.home = function(windowToOpen){
//store a copy of all the current windows on the stack
var windows = navigationController.windowStack.concat([]);
for(var i = 1, l = windows.length; i < l; i++) {
(navigationController.navGroup) ? navigationController.navGroup.close(windows[i]) : windows[i].close();
}
navigationController.windowStack = [navigationController.windowStack[0]]; //reset stack
Ti.API.info(navigationController.windowStack);
};
navigationController.back = function(){
if (navigationController.windowStack.length <= 1) {
Ti.API.warn("navigationController: Attempt made to go back from main home page.");
return;
}
var w = navigationController.windowStack.pop();
if(Ti.Platform.osname === 'android') {
w.close();
}else{
navigationController.navGroup.close(w);
}
};
})();