Skip to content

Commit b6ac290

Browse files
authored
feat: support for async APP_INITIALIZER and animated launch screens (#2170)
1 parent 1b191b0 commit b6ac290

File tree

3 files changed

+193
-130
lines changed

3 files changed

+193
-130
lines changed

e2e/animation-examples/app/app.module.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
22
NgModule,
33
NO_ERRORS_SCHEMA,
4-
NgModuleFactoryLoader
4+
NgModuleFactoryLoader,
5+
APP_INITIALIZER
56
} from "@angular/core";
67

78
import { NativeScriptModule } from "@nativescript/angular";
@@ -21,6 +22,14 @@ import { QueryStaggerComponent } from "./query-stagger.component";
2122

2223
import { AppComponent } from "./app.component";
2324

25+
export function asyncBoot(): Function {
26+
return (): Promise<any> => new Promise(resolve => {
27+
setTimeout(() => {
28+
resolve();
29+
}, 2000);
30+
})
31+
}
32+
2433
@NgModule({
2534
bootstrap: [
2635
AppComponent,
@@ -42,6 +51,16 @@ import { AppComponent } from "./app.component";
4251
NativeScriptAnimationsModule,
4352
AppRoutingModule,
4453
],
54+
/**
55+
* Uncomment to test APP_INITIALIZER
56+
*/
57+
// providers: [
58+
// {
59+
// provide: APP_INITIALIZER,
60+
// useFactory: asyncBoot,
61+
// multi: true
62+
// },
63+
// ],
4564
schemas: [NO_ERRORS_SCHEMA],
4665
})
4766
export class AppModule {}

e2e/animation-examples/app/main.ts

+94-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,103 @@
11
import { platformNativeScriptDynamic } from "@nativescript/angular/platform";
22
import { animationsTraceCategory } from "@nativescript/angular/trace";
33
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';
413

514
import { AppModule } from "./app.module";
615

716
setCategories(animationsTraceCategory);
817
enable();
918

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

Comments
 (0)