/
xp.ui.js
executable file
·114 lines (95 loc) · 3.94 KB
/
xp.ui.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
exports.createNavigationWindow = function(args) {
if (OS_ANDROID) {
var NavigationWindow = function(args) {
this.args = args;
};
NavigationWindow.prototype.open = function(params) {
params = params || {};
params.displayHomeAsUp = this.args.modal || false;
return this.openWindow(this.args.window, params);
};
NavigationWindow.prototype.close = function(params) {
return this.closeWindow(this.args.window, params);
};
NavigationWindow.prototype.openWindow = function(window, options) {
var that = this;
options = options || {};
options.swipeBack = (typeof options.swipeBack === 'boolean') ? options.swipeBack : that.args.swipeBack;
options.displayHomeAsUp = (typeof options.displayHomeAsUp === 'boolean') ? options.displayHomeAsUp : that.args.displayHomeAsUp;
if (options.swipeBack !== false) {
window.addEventListener('swipe', function(e) {
if (e.direction === 'right') {
that.closeWindow(window, options);
}
});
}
if (OS_ANDROID && options.displayHomeAsUp !== false && !window.navBarHidden) {
window.addEventListener('open', function (){
var activity = window.getActivity();
if (activity) {
var actionBar = activity.actionBar;
if (actionBar) {
actionBar.displayHomeAsUp = true;
actionBar.onHomeIconItemSelected = function (){
that.closeWindow(window, options);
};
}
}
});
}
return window.open(options);
};
NavigationWindow.prototype.closeWindow = function(window, options) {
return window.close(options || {});
};
}
var navigationWindow = OS_IOS ? Ti.UI.iOS.createNavigationWindow(args) : new NavigationWindow(args);
if (args && args.id) {
Alloy.Globals[args.id] = navigationWindow;
}
return navigationWindow;
};
exports.createWindow = function(args)
{
var role = args.role || false;
var window = Ti.UI[(OS_ANDROID && _.contains(["main", "menu"], role)) ? "createView" : "createWindow"](args);
if (OS_IOS) {
Alloy.Globals.windowStack.on("sizechanged", _.debounce(function(e) {
toggleSwipe();
toggleMenuButton(e);
}, 300, false));
}
if (OS_ANDROID && window.getApiName() === "Ti.UI.Window") {
window.addEventListener("open", function() {
if (Alloy.Globals.windowStack && Alloy.Globals.windowStack.isNotRootLevel()) {
// Show the home button and set onClick action
window._internalActivity.actionBar.setDisplayHomeAsUp(true);
window._internalActivity.actionBar.setOnHomeIconItemSelected(function() {
// Close the current window
Alloy.Globals.windowStack.back();
});
}
});
}
return window;
};
var toggleMenuButton = function(e) {
if (!Alloy.Globals.drawer || !Alloy.Globals.windowStack) {
return;
}
if (Alloy.Globals.windowStack.isRootLevel()) {
e.source.LeftNavButton = Alloy.createController("_menuButton").getView();
}
};
var toggleSwipe = function() {
if (!Alloy.Globals.drawer || !Alloy.Globals.windowStack) {
return;
}
if (Alloy.Globals.windowStack.isRootLevel()) {
Alloy.Globals.drawer.setOpenDrawerGestureMode("OPEN_MODE_ALL");
Alloy.Globals.drawer.setCloseDrawerGestureMode("CLOSE_MODE_ALL");
} else {
Alloy.Globals.drawer.setOpenDrawerGestureMode("OPEN_MODE_NONE");
Alloy.Globals.drawer.setCloseDrawerGestureMode("CLOSE_MODE_NONE");
}
};