Skip to content

Commit 6a4a3bf

Browse files
committed
chore: cleanup
1 parent f53ceaf commit 6a4a3bf

File tree

5 files changed

+76
-74
lines changed

5 files changed

+76
-74
lines changed

Diff for: e2e/animation-examples/app/main.ts

+41-52
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ class LaunchAnimation extends GridLayout implements AppLaunchView {
1010
circle: GridLayout;
1111
animatedContainer: GridLayout;
1212
finished = false;
13-
resolve: () => void;
13+
complete: () => void;
1414

1515
constructor() {
1616
super();
1717

1818
// setup container to house launch animation
1919
this.animatedContainer = new GridLayout();
2020
this.animatedContainer.style.zIndex = 100;
21-
this.animatedContainer.backgroundColor = '#4caef7';
22-
this.animatedContainer.className = 'w-full h-full';
21+
this.animatedContainer.backgroundColor = "#4caef7";
22+
this.animatedContainer.className = "w-full h-full";
2323

2424
// any creative animation can be put inside
2525
this.circle = new GridLayout();
2626
this.circle.width = 30;
2727
this.circle.height = 30;
2828
this.circle.borderRadius = 15;
29-
this.circle.horizontalAlignment = 'center';
30-
this.circle.verticalAlignment = 'middle';
31-
this.circle.backgroundColor = '#fff';
29+
this.circle.horizontalAlignment = "center";
30+
this.circle.verticalAlignment = "middle";
31+
this.circle.backgroundColor = "#fff";
3232
this.animatedContainer.addRow(new ItemSpec(1, GridUnitType.STAR));
3333
this.animatedContainer.addRow(new ItemSpec(1, GridUnitType.AUTO));
3434
this.animatedContainer.addRow(new ItemSpec(1, GridUnitType.STAR));
@@ -40,62 +40,51 @@ class LaunchAnimation extends GridLayout implements AppLaunchView {
4040
this.addChild(this.animatedContainer);
4141
}
4242

43-
startAnimation() {
44-
this.circle
45-
.animate({
46-
scale: { x: 2, y: 2 },
47-
duration: 800,
48-
})
49-
.then(() => {
50-
this.circle
51-
.animate({
52-
scale: { x: 1, y: 1 },
53-
duration: 800,
54-
})
55-
.then(() => {
56-
if (this.finished) {
57-
this.circle
58-
.animate({
59-
scale: { x: 30, y: 30 },
60-
duration: 400,
61-
})
62-
.then(() => {
63-
this.fadeOut();
64-
});
65-
} else {
66-
// keep looping
67-
this.startAnimation();
68-
}
69-
});
43+
async startAnimation() {
44+
await this.circle.animate({
45+
scale: { x: 2, y: 2 },
46+
duration: 800,
47+
});
48+
49+
await this.circle.animate({
50+
scale: { x: 1, y: 1 },
51+
duration: 800,
52+
});
53+
54+
if (this.finished) {
55+
await this.circle.animate({
56+
scale: { x: 30, y: 30 },
57+
duration: 400,
7058
});
59+
this.fadeOut();
60+
} else {
61+
// keep looping
62+
this.startAnimation();
63+
}
7164
}
7265

7366
cleanup() {
74-
return new Promise(resolve => {
75-
this.resolve = resolve;
67+
return new Promise((resolve) => {
68+
this.complete = resolve;
7669
this.finished = true;
77-
})
70+
});
7871
}
7972

80-
fadeOut() {
81-
this.animatedContainer
82-
.animate({
83-
opacity: 0,
84-
duration: 400,
85-
})
86-
.then(() => {
87-
// done with animation, can safely remove to reveal bootstrapped app
88-
this.removeChild(this.animatedContainer);
89-
this.animatedContainer = null;
90-
this.circle = null;
91-
if (this.resolve) {
92-
this.resolve();
93-
}
94-
});
73+
async fadeOut() {
74+
await this.animatedContainer.animate({
75+
opacity: 0,
76+
duration: 400,
77+
});
78+
// done with animation, can safely remove to reveal bootstrapped app
79+
this.removeChild(this.animatedContainer);
80+
this.animatedContainer = null;
81+
this.circle = null;
82+
this.complete();
9583
}
9684
}
9785

9886
platformNativeScriptDynamic({
9987
launchView: new LaunchAnimation(),
100-
// backgroundColor: 'purple'
88+
// backgroundColor: 'purple',
89+
// async: true
10190
}).bootstrapModule(AppModule);

Diff for: nativescript-angular/app-host-view.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class AppHostView extends ContentView {
4343
}
4444
}
4545

46-
export class AppHostLaunchAnimationView extends GridLayout {
46+
export class AppHostAsyncView extends GridLayout {
4747
constructor(backgroundColor: Color) {
4848
super();
4949
this.backgroundColor = backgroundColor;

Diff for: nativescript-angular/directives/dialogs.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ComponentFactoryResolver, ComponentRef, Injectable, Injector, NgModuleR
22
import { Frame, View, ViewBase, ProxyViewContainer, ShowModalOptions } from '@nativescript/core';
33

44
import { NSLocationStrategy } from '../router/ns-location-strategy';
5-
import { AppHostView } from '../app-host-view';
5+
import { AppHostView, AppHostAsyncView } from '../app-host-view';
66
import { DetachedLoader } from '../common/detached-loader';
77
import { PageFactory, PAGE_FACTORY } from '../platform-providers';
88
import { once } from '../common/utils';
@@ -44,7 +44,7 @@ export class ModalDialogService {
4444
parentView = options.target;
4545
}
4646

47-
if (parentView instanceof AppHostView && parentView.ngAppRoot) {
47+
if ((parentView instanceof AppHostView || parentView instanceof AppHostAsyncView) && parentView.ngAppRoot) {
4848
parentView = parentView.ngAppRoot;
4949
}
5050

Diff for: nativescript-angular/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript/angular",
3-
"version": "10.0.0-rc.7",
3+
"version": "10.0.0-rc.8",
44
"description": "An Angular renderer that lets you build mobile apps with NativeScript.",
55
"homepage": "https://www.nativescript.org/",
66
"bugs": "https://github.com/NativeScript/nativescript-angular/issues",

Diff for: nativescript-angular/platform-common.ts

+31-18
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { DOCUMENT } from '@angular/common';
77

88
import { NativeScriptDebug } from './trace';
99
import { defaultPageFactoryProvider, setRootPage, PageFactory, PAGE_FACTORY, getRootPage } from './platform-providers';
10-
import { AppHostView, AppHostLaunchAnimationView } from './app-host-view';
10+
import { AppHostView, AppHostAsyncView } from './app-host-view';
1111

1212
export const onBeforeLivesync = new EventEmitter<NgModuleRef<any>>();
1313
export const onAfterLivesync = new EventEmitter<{
@@ -57,8 +57,19 @@ export interface AppOptions {
5757
cssFile?: string;
5858
startPageActionBarHidden?: boolean;
5959
hmrOptions?: HmrOptions;
60+
/**
61+
* Background color of the root view
62+
*/
6063
backgroundColor?: string;
64+
/**
65+
* Use animated launch view (async by default)
66+
*/
6167
launchView?: AppLaunchView;
68+
/**
69+
* When using Async APP_INITIALIZER, set this to `true`.
70+
* (Not needed when using launchView)
71+
*/
72+
async?: boolean;
6273
}
6374

6475
export type PlatformFactory = (extraProviders?: StaticProvider[]) => PlatformRef;
@@ -170,16 +181,18 @@ export class NativeScriptPlatformRef extends PlatformRef {
170181
NativeScriptDebug.bootstrapLog('Application launch event fired');
171182
}
172183

184+
// Create a temp page for root of the renderer
173185
let tempAppHostView: AppHostView;
174-
let animatedHostView: AppHostLaunchAnimationView;
175-
if (this.appOptions && this.appOptions.launchView) {
176-
animatedHostView = new AppHostLaunchAnimationView(new Color(this.appOptions && this.appOptions.backgroundColor ? this.appOptions.backgroundColor : '#fff'));
177-
this.appOptions.launchView.style.zIndex = 1000;
178-
animatedHostView.addChild(this.appOptions.launchView);
179-
rootContent = animatedHostView.ngAppRoot;
180-
setRootPage(<any>animatedHostView);
186+
let tempAppHostAsyncView: AppHostAsyncView;
187+
if (this.appOptions && (this.appOptions.async || this.appOptions.launchView)) {
188+
tempAppHostAsyncView = new AppHostAsyncView(new Color(this.appOptions && this.appOptions.backgroundColor ? this.appOptions.backgroundColor : '#fff'));
189+
if (this.appOptions.launchView) {
190+
this.appOptions.launchView.style.zIndex = 1000;
191+
tempAppHostAsyncView.addChild(this.appOptions.launchView);
192+
}
193+
rootContent = tempAppHostAsyncView.ngAppRoot;
194+
setRootPage(<any>tempAppHostAsyncView);
181195
} else {
182-
// Create a temp page for root of the renderer
183196
tempAppHostView = new AppHostView(new Color(this.appOptions && this.appOptions.backgroundColor ? this.appOptions.backgroundColor : '#fff'));
184197
setRootPage(<any>tempAppHostView);
185198
}
@@ -196,10 +209,10 @@ export class NativeScriptPlatformRef extends PlatformRef {
196209
if (this.appOptions.launchView && this.appOptions.launchView.cleanup) {
197210
this.appOptions.launchView.cleanup().then(() => {
198211
// cleanup any custom launch views
199-
animatedHostView.removeChild(this.appOptions.launchView);
212+
tempAppHostAsyncView.removeChild(this.appOptions.launchView);
200213
this.appOptions.launchView = null;
201214
});
202-
} else {
215+
} else if (tempAppHostView) {
203216
rootContent = tempAppHostView.content;
204217
}
205218

@@ -235,13 +248,13 @@ export class NativeScriptPlatformRef extends PlatformRef {
235248
});
236249
}
237250
bootstrap();
238-
if (!bootstrapPromiseCompleted) {
239-
const errorMessage = "Bootstrap promise didn't resolve";
240-
if (NativeScriptDebug.isLogEnabled()) {
241-
NativeScriptDebug.bootstrapLogError(errorMessage);
242-
}
243-
rootContent = this.createErrorUI(errorMessage);
244-
}
251+
// if (!bootstrapPromiseCompleted) {
252+
// const errorMessage = "Bootstrap promise didn't resolve";
253+
// if (NativeScriptDebug.isLogEnabled()) {
254+
// NativeScriptDebug.bootstrapLogError(errorMessage);
255+
// }
256+
// rootContent = this.createErrorUI(errorMessage);
257+
// }
245258
args.root = rootContent;
246259
});
247260
const exitCallback = profile('@nativescript/angular/platform-common.exitCallback', (args: ApplicationEventData) => {

0 commit comments

Comments
 (0)