|
1 |
| -import { platformNativeScriptDynamic } from "@nativescript/angular/platform"; |
2 |
| -import { animationsTraceCategory } from "@nativescript/angular/trace"; |
3 |
| -import { setCategories, enable } from "@nativescript/core/trace"; |
4 |
| -import { |
5 |
| - GridLayout, |
6 |
| - ItemSpec, |
7 |
| - GridUnitType, |
8 |
| -} from '@nativescript/core/ui/layouts/grid-layout'; |
9 |
| -import { |
10 |
| - HorizontalAlignment, |
11 |
| - VerticalAlignment, |
12 |
| -} from '@nativescript/core/ui/enums/enums'; |
| 1 | +import { platformNativeScriptDynamic, NativeScriptDebug, AppLaunchView } from "@nativescript/angular"; |
| 2 | +import { Trace, GridLayout, GridUnitType, ItemSpec, Application } from "@nativescript/core"; |
13 | 3 |
|
14 | 4 | import { AppModule } from "./app.module";
|
15 | 5 |
|
16 |
| -setCategories(animationsTraceCategory); |
17 |
| -enable(); |
| 6 | +Trace.setCategories(NativeScriptDebug.animationsTraceCategory); |
| 7 | +Trace.enable(); |
18 | 8 |
|
19 |
| -class LaunchAnimation extends GridLayout { |
| 9 | +class LaunchAnimation extends GridLayout implements AppLaunchView { |
20 | 10 | circle: GridLayout;
|
21 |
| - animatedContainer: GridLayout; |
22 | 11 | finished = false;
|
| 12 | + complete: () => void; |
23 | 13 |
|
24 | 14 | constructor() {
|
25 | 15 | super();
|
| 16 | + this.backgroundColor = "#4caef7"; |
| 17 | + this.className = "w-full h-full"; |
26 | 18 |
|
27 |
| - // setup container to house launch animation |
28 |
| - this.animatedContainer = new GridLayout(); |
29 |
| - this.animatedContainer.style.zIndex = 100; |
30 |
| - this.animatedContainer.backgroundColor = '#4caef7'; |
31 |
| - this.animatedContainer.className = 'w-full h-full'; |
32 |
| - |
33 |
| - // any creative animation can be put inside |
| 19 | + // construct any creative animation |
34 | 20 | this.circle = new GridLayout();
|
35 | 21 | this.circle.width = 30;
|
36 | 22 | this.circle.height = 30;
|
37 | 23 | this.circle.borderRadius = 15;
|
38 |
| - this.circle.horizontalAlignment = HorizontalAlignment.center; |
39 |
| - this.circle.verticalAlignment = VerticalAlignment.center; |
40 |
| - this.circle.backgroundColor = '#fff'; |
41 |
| - this.animatedContainer.addRow(new ItemSpec(1, GridUnitType.STAR)); |
42 |
| - this.animatedContainer.addRow(new ItemSpec(1, GridUnitType.AUTO)); |
43 |
| - this.animatedContainer.addRow(new ItemSpec(1, GridUnitType.STAR)); |
44 |
| - GridLayout.setRow(this.circle, 1); |
45 |
| - this.animatedContainer.addChild(this.circle); |
| 24 | + this.circle.horizontalAlignment = "center"; |
| 25 | + this.circle.verticalAlignment = "middle"; |
| 26 | + this.circle.backgroundColor = "#fff"; |
46 | 27 |
|
47 |
| - // add animation to top row since booted app will insert into bottom row |
48 |
| - GridLayout.setRow(this.animatedContainer, 1); |
49 |
| - this.addChild(this.animatedContainer); |
| 28 | + this.addChild(this.circle); |
50 | 29 | }
|
51 | 30 |
|
52 |
| - startAnimation() { |
53 |
| - this.circle |
54 |
| - .animate({ |
55 |
| - scale: { x: 2, y: 2 }, |
56 |
| - duration: 800, |
57 |
| - }) |
58 |
| - .then(() => { |
59 |
| - this.circle |
60 |
| - .animate({ |
61 |
| - scale: { x: 1, y: 1 }, |
62 |
| - duration: 800, |
63 |
| - }) |
64 |
| - .then(() => { |
65 |
| - if (this.finished) { |
66 |
| - this.circle |
67 |
| - .animate({ |
68 |
| - scale: { x: 30, y: 30 }, |
69 |
| - duration: 400, |
70 |
| - }) |
71 |
| - .then(() => { |
72 |
| - this.fadeOut(); |
73 |
| - }); |
74 |
| - } else { |
75 |
| - // keep looping |
76 |
| - this.startAnimation(); |
77 |
| - } |
78 |
| - }); |
| 31 | + async startAnimation() { |
| 32 | + await this.circle.animate({ |
| 33 | + scale: { x: 2, y: 2 }, |
| 34 | + duration: 800, |
| 35 | + }); |
| 36 | + |
| 37 | + await this.circle.animate({ |
| 38 | + scale: { x: 1, y: 1 }, |
| 39 | + duration: 800, |
| 40 | + }); |
| 41 | + |
| 42 | + if (this.finished) { |
| 43 | + await this.circle.animate({ |
| 44 | + scale: { x: 30, y: 30 }, |
| 45 | + duration: 400, |
79 | 46 | });
|
| 47 | + this.fadeOut(); |
| 48 | + } else { |
| 49 | + // keep looping |
| 50 | + this.startAnimation(); |
| 51 | + } |
80 | 52 | }
|
81 | 53 |
|
82 | 54 | cleanup() {
|
83 |
| - this.finished = true; |
| 55 | + return new Promise((resolve) => { |
| 56 | + this.complete = resolve; |
| 57 | + this.finished = true; |
| 58 | + }); |
84 | 59 | }
|
85 | 60 |
|
86 |
| - fadeOut() { |
87 |
| - this.animatedContainer |
88 |
| - .animate({ |
89 |
| - opacity: 0, |
90 |
| - duration: 400, |
91 |
| - }) |
92 |
| - .then(() => { |
93 |
| - this._removeView(this.animatedContainer); |
94 |
| - this.animatedContainer = null; |
95 |
| - this.circle = null; |
96 |
| - }); |
| 61 | + async fadeOut() { |
| 62 | + await this.animate({ |
| 63 | + opacity: 0, |
| 64 | + duration: 400, |
| 65 | + }); |
| 66 | + this.complete(); |
97 | 67 | }
|
98 | 68 | }
|
99 | 69 |
|
100 | 70 | platformNativeScriptDynamic({
|
101 | 71 | launchView: new LaunchAnimation(),
|
102 |
| - // backgroundColor: 'purple' |
| 72 | + // backgroundColor: 'purple', |
| 73 | + // async: true |
103 | 74 | }).bootstrapModule(AppModule);
|
0 commit comments