|
1 | 1 | import { platformNativeScriptDynamic } from "@nativescript/angular/platform";
|
2 | 2 | import { animationsTraceCategory } from "@nativescript/angular/trace";
|
3 | 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'; |
4 | 13 |
|
5 | 14 | import { AppModule } from "./app.module";
|
6 | 15 |
|
7 | 16 | setCategories(animationsTraceCategory);
|
8 | 17 | enable();
|
9 | 18 |
|
10 |
| -platformNativeScriptDynamic().bootstrapModule(AppModule); |
| 19 | +class LaunchAnimation extends GridLayout { |
| 20 | + circle: GridLayout; |
| 21 | + animatedContainer: GridLayout; |
| 22 | + finished = false; |
| 23 | + |
| 24 | + constructor() { |
| 25 | + super(); |
| 26 | + |
| 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 |
| 34 | + this.circle = new GridLayout(); |
| 35 | + this.circle.width = 30; |
| 36 | + this.circle.height = 30; |
| 37 | + 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); |
| 46 | + |
| 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); |
| 50 | + } |
| 51 | + |
| 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 | + }); |
| 79 | + }); |
| 80 | + } |
| 81 | + |
| 82 | + cleanup() { |
| 83 | + this.finished = true; |
| 84 | + } |
| 85 | + |
| 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 | + }); |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +platformNativeScriptDynamic({ |
| 101 | + launchView: new LaunchAnimation(), |
| 102 | + // backgroundColor: 'purple' |
| 103 | +}).bootstrapModule(AppModule); |
0 commit comments