This repository has been archived by the owner on Aug 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 97
/
main-page.ts
147 lines (128 loc) · 4.42 KB
/
main-page.ts
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { EventData } from "tns-core-modules/data/observable";
import { Page } from "tns-core-modules/ui/page";
import { RadSideDrawer } from "nativescript-ui-sidedrawer";
import { LayoutBase } from "tns-core-modules/ui/layouts/layout-base";
import * as gestures from "tns-core-modules/ui/gestures";
import * as examplesVM from "../../view-models/examples-model"
import * as mainPageVM from "../../view-models/main-page-view-model";
import * as navigator from "../../common/navigator";
import * as prof from "../../common/profiling";
import { View } from "tns-core-modules/ui/core/view";
import { grayTouch } from "../../common/effects";
import { onAfterIntro } from "../../common/firebase";
import { isIOS } from "tns-core-modules/platform";
import { getRootView } from "tns-core-modules/application"
export function onLoaded(args) {
prof.stop("main-page");
let page = (args.object as View).page as Page;
setTimeout(() => {
(page as any).canEnter = true;
}, 3500);
}
export function onNavigatedTo(args: EventData) {
getRootSideDrawer().gesturesEnabled = true;
}
export function onNavigatingTo(args: EventData) {
(args.object as View).bindingContext = mainPageVM.getInstance();
}
export function toggleWrapLayout(e: any) {
e.object.bindingContext.toggleWrapLayout();
}
export function tileTouch(args: gestures.TouchGestureEventData) {
let page = (args.object as View).page as Page;
if (!(page as any).introPlayed) {
return;
}
grayTouch(args);
}
export function navigateToExample(args: gestures.GestureEventData) {
let page = (args.object as View).page as Page;
if (!(page as any).introPlayed) {
return;
}
prof.start("example");
getRootSideDrawer().gesturesEnabled = false;
getRootSideDrawer().closeDrawer();
var example = (args as any).object.bindingContext as examplesVM.Example;
navigator.navigateToExample(example, examplesVM.featuredExamples);
}
export function showSlideout() {
getRootSideDrawer().toggleDrawerState();
}
export function tapHome() {
getRootSideDrawer().closeDrawer();
}
export function tapAbout() {
getRootSideDrawer().closeDrawer();
navigator.navigateToAbout();
}
export function tapDrawerLink(args) {
getRootSideDrawer().closeDrawer();
navigator.openLink(args.object);
}
export function tapPage(args) {
enter(args);
}
export function tapGetStarted(args) {
enter(args);
}
export function enter(args) {
let page = (args.object as View).page as Page;
if (!(page as any).canEnter) {
return;
}
if ((page as any).entered) {
return;
}
(page as any).entered = true;
let content = page.getViewById<View>("content");
content.isEnabled = true;
content.opacity = 1;
startEnterAnimation(page);
startExamplesAnimation(page);
setTimeout(() => {
page.getViewById<View>("intro-elements").visibility = "collapse";
onAfterIntro();
}, 1500);
showActionBar(page);
}
function getRootSideDrawer(): RadSideDrawer {
return getRootView() as RadSideDrawer;
}
function startEnterAnimation(page: Page) {
["intro-background", "intro-logo-bg", "intro-logo-n", "intro-logo-ns", "intro-text-one", "intro-text-two", "intro-get-started"]
.forEach(id => page.getViewById(id).className = id + "-enter");
}
function startExamplesAnimation(page: Page) {
let examplesList = page.getViewById("examples-wrap-layout") as LayoutBase;
let odd = true;
let timeout = 1000;
setTimeout(() => (page as any).introPlayed = true, timeout);
let classSetterFactory = (child, className) => () => child.className = className;
for (let i = 0, length = examplesList.getChildrenCount(); i < length; i++) {
let child = examplesList.getChildAt(i);
setTimeout(classSetterFactory(child, odd ? "example-odd-enter" : "example-even-enter"), timeout);
setTimeout(classSetterFactory(child, ""), timeout + 400);
if (odd = !odd) {
timeout += 220;
}
}
}
function showActionBar(page: Page) {
var introElements = page.getViewById<View>("intro-elements");
if (isIOS) {
setTimeout(() => {
introElements.margin = "-44 0 0 0";
page.actionBarHidden = false;
}, 300);
}
else {
setTimeout(() => {
console.log("Animate android actionbar...");
page.actionBar.animate({
opacity: 1,
duration: 200
});
}, 300);
}
}