UNPKG

3.59 kBJavaScriptView Raw
1import { isArray, isPresent } from '../util/util';
2import { ViewController, isViewController } from './view-controller';
3export function getComponent(linker, nameOrPageOrView, params) {
4 if (typeof nameOrPageOrView === 'function') {
5 return Promise.resolve(new ViewController(nameOrPageOrView, params));
6 }
7 if (typeof nameOrPageOrView === 'string') {
8 return linker.getComponentFromName(nameOrPageOrView).then(function (component) {
9 var vc = new ViewController(component, params);
10 vc.id = nameOrPageOrView;
11 return vc;
12 });
13 }
14 return Promise.resolve(null);
15}
16export function convertToView(linker, nameOrPageOrView, params) {
17 if (nameOrPageOrView) {
18 if (isViewController(nameOrPageOrView)) {
19 // is already a ViewController
20 return Promise.resolve(nameOrPageOrView);
21 }
22 return getComponent(linker, nameOrPageOrView, params);
23 }
24 return Promise.resolve(null);
25}
26export function convertToViews(linker, pages) {
27 var views = [];
28 if (isArray(pages)) {
29 for (var i = 0; i < pages.length; i++) {
30 var page = pages[i];
31 if (page) {
32 if (isViewController(page)) {
33 views.push(page);
34 }
35 else if (page.page) {
36 views.push(convertToView(linker, page.page, page.params));
37 }
38 else {
39 views.push(convertToView(linker, page, null));
40 }
41 }
42 }
43 }
44 return Promise.all(views);
45}
46var portalZindex = 9999;
47export function setZIndex(nav, enteringView, leavingView, direction, renderer) {
48 if (enteringView) {
49 if (nav._isPortal) {
50 if (direction === DIRECTION_FORWARD) {
51 enteringView._setZIndex(nav._zIndexOffset + portalZindex, renderer);
52 }
53 portalZindex++;
54 return;
55 }
56 leavingView = leavingView || nav.getPrevious(enteringView);
57 if (leavingView && isPresent(leavingView._zIndex)) {
58 if (direction === DIRECTION_BACK) {
59 enteringView._setZIndex(leavingView._zIndex - 1, renderer);
60 }
61 else {
62 enteringView._setZIndex(leavingView._zIndex + 1, renderer);
63 }
64 }
65 else {
66 enteringView._setZIndex(INIT_ZINDEX + nav._zIndexOffset, renderer);
67 }
68 }
69}
70export function isTabs(nav) {
71 // Tabs (ion-tabs)
72 return !!nav && !!nav.getSelected;
73}
74export function isTab(nav) {
75 // Tab (ion-tab)
76 return !!nav && isPresent(nav._tabId);
77}
78export function isNav(nav) {
79 // Nav (ion-nav), Tab (ion-tab), Portal (ion-portal)
80 return !!nav && !!nav.push && nav.getType() === 'nav';
81}
82export function linkToSegment(navId, type, secondaryId, link) {
83 var segment = Object.assign({}, link);
84 segment.navId = navId;
85 segment.type = type;
86 segment.secondaryId = secondaryId;
87 return segment;
88}
89/**
90 * @hidden
91 */
92var DeepLinkMetadata = (function () {
93 function DeepLinkMetadata() {
94 }
95 return DeepLinkMetadata;
96}());
97export { DeepLinkMetadata };
98/**
99 * @hidden
100 */
101export var DeepLinkMetadataFactory;
102export var STATE_NEW = 1;
103export var STATE_INITIALIZED = 2;
104export var STATE_ATTACHED = 3;
105export var STATE_DESTROYED = 4;
106export var INIT_ZINDEX = 100;
107export var DIRECTION_BACK = 'back';
108export var DIRECTION_FORWARD = 'forward';
109export var DIRECTION_SWITCH = 'switch';
110export var NAV = 'nav';
111export var TABS = 'tabs';
112//# sourceMappingURL=nav-util.js.map
\No newline at end of file