-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavigationController.js
115 lines (93 loc) · 3.27 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* Navigation controller; on iOS uses NavigationGroup but on Android transitions manually */
var nav = {};
function NavigationController(options) {
var $ = require('/' + Ti.App.DBVNo + '/lib/util');
nav.settings = $.extend({
animation: Titanium.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT
}, options);
nav.windowStack = [];
// We have our own checks here, but if they've already been done by the app, use the cached values
if (typeof Ti.App.isTablet !== 'undefined' && typeof Ti.App.iOS !== 'undefined' && typeof Ti.App.android !== 'undefined') {
nav.isTablet = Ti.App.isTablet;
nav.iOS = Ti.App.iOS;
nav.android = Ti.App.android;
} else {
var osname = Ti.Platform.osname,
version = Ti.Platform.version,
height = Ti.Platform.displayCaps.platformHeight,
width = Ti.Platform.displayCaps.platformWidth;
var isTablet = osname === 'ipad' || (osname === 'android' && (width > 899 || height > 899));
nav.isTablet = isTablet;
nav.iOS = osname === 'ipad' || osname === 'iphone';
nav.android = osname === 'android';
}
};
NavigationController.prototype.open = function(/*Ti.UI.Window*/windowToOpen) {
//add the window to the stack of windows managed by the controller
nav.windowStack.push(windowToOpen);
Ti.API.info('Ti.App.Nav.open() called! windows:' + nav.windowStack.length);
// Grab a copy of the current nav controller for use in the callback
windowToOpen.addEventListener('close', function() {
Ti.API.info('closed window, checking whether it is still on the stack');
if (nav.windowStack.length) {
var lastWindow = nav.windowStack[nav.windowStack.length-1];
if (lastWindow == windowToOpen) {
// Popping off
nav.windowStack.pop();
}
}
});
// Hack - setting nav.property ensures the window is "heavyweight" (associated with an Android activity)
windowToOpen.navBarHidden = windowToOpen.navBarHidden || false;
if (nav.windowStack.length === 1) {
// nav.is the first window
if (nav.android) {
windowToOpen.exitOnClose = true;
windowToOpen.open();
} else if (nav.iOS) {
nav.navGroup = Ti.UI.iOS.createNavigationWindow({
window : windowToOpen
});
nav.navGroup.open({
animation: Titanium.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT
});
} else {
alert('Requires Android or iOS');
}
} else {
// All subsequent windows
if (nav.android) {
windowToOpen.open();
} else if (nav.iOS) {
nav.navGroup.openWindow(windowToOpen);
} else {
alert('Requires Android or iOS');
}
}
};
NavigationController.prototype.back = function() {
Ti.API.info('Ti.App.Nav.back() called - windows:' + nav.windowStack.length);
var lastWindow = nav.windowStack.pop();
if (nav.navGroup) {
nav.navGroup.closeWindow(lastWindow);
} else {
lastWindow.hide();
lastWindow.close();
lastWindow = null;
}
};
// Go back to the initial window of the NavigationController
NavigationController.prototype.home = function() {
// Store a copy of all the current windows on the stack
var windows = nav.windowStack.concat([]);
//for(var i = 1, l = windows.length; i < l; i++) {Cont
for(var i = 1, l = windows.length; i < l; i++) {
if (nav.navGroup) {
nav.navGroup.closeWindow(windows[i]);
} else {
windows[i].close();
}
}
nav.windowStack = [nav.windowStack[0]]; // reset stack
};
module.exports = NavigationController;