@@ -7,7 +7,7 @@ import { DOCUMENT } from '@angular/common';
77
88import { NativeScriptDebug } from './trace' ;
99import { defaultPageFactoryProvider , setRootPage , PageFactory , PAGE_FACTORY , getRootPage } from './platform-providers' ;
10- import { AppHostView } from './app-host-view' ;
10+ import { AppHostView , AppHostLaunchAnimationView } from './app-host-view' ;
1111
1212export const onBeforeLivesync = new EventEmitter < NgModuleRef < any > > ( ) ;
1313export const onAfterLivesync = new EventEmitter < {
@@ -161,7 +161,6 @@ export class NativeScriptPlatformRef extends PlatformRef {
161161 @profile
162162 private bootstrapNativeScriptApp ( ) {
163163 let rootContent : View ;
164- let launchView : AppLaunchView ;
165164
166165 if ( NativeScriptDebug . isLogEnabled ( ) ) {
167166 NativeScriptDebug . bootstrapLog ( 'NativeScriptPlatform bootstrap started.' ) ;
@@ -172,12 +171,13 @@ export class NativeScriptPlatformRef extends PlatformRef {
172171 }
173172
174173 let tempAppHostView : AppHostView ;
175- let usingCustomLaunchView = false ;
174+ let animatedHostView : AppHostLaunchAnimationView ;
176175 if ( this . appOptions && this . appOptions . launchView ) {
177- launchView = this . appOptions . launchView ;
178- usingCustomLaunchView = true ;
179- rootContent = launchView ;
180- setRootPage ( < any > rootContent ) ;
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 ) ;
181181 } else {
182182 // Create a temp page for root of the renderer
183183 tempAppHostView = new AppHostView ( new Color ( this . appOptions && this . appOptions . backgroundColor ? this . appOptions . backgroundColor : '#fff' ) ) ;
@@ -193,20 +193,11 @@ export class NativeScriptPlatformRef extends PlatformRef {
193193 NativeScriptDebug . bootstrapLog ( `Angular bootstrap bootstrap done. uptime: ${ profilingUptime ( ) } ` ) ;
194194 }
195195
196- if ( launchView && launchView . cleanup ) {
197- // cleanup any custom launch views
198- launchView . cleanup ( ) . then ( ( ) => {
199- // swap launchView with actual booted view
200- // todo: experiment in Angular 11 with a setup like this
201- // Application.resetRootView({
202- // create: () => {
203- // // const { page, frame } = this.createFrameAndPage(false);
204- // // frame._addView(launchView.getChildAt(0));
205- // const rootView = launchView.getChildAt(0);
206- // // launchView.parent._removeView(launchView);
207- // return rootView;//launchView.getChildAt(0);//page;
208- // },
209- // });
196+ if ( this . appOptions . launchView && this . appOptions . launchView . cleanup ) {
197+ this . appOptions . launchView . cleanup ( ) . then ( ( ) => {
198+ // cleanup any custom launch views
199+ animatedHostView . removeChild ( this . appOptions . launchView ) ;
200+ this . appOptions . launchView = null ;
210201 } ) ;
211202 } else {
212203 rootContent = tempAppHostView . content ;
@@ -236,19 +227,15 @@ export class NativeScriptPlatformRef extends PlatformRef {
236227 }
237228 } ;
238229
239- if ( usingCustomLaunchView ) {
240- // Since custom LaunchView could engage with animations, Launch Angular app on next tick
230+ if ( this . appOptions && this . appOptions . launchView && this . appOptions . launchView . startAnimation ) {
231+ // start animations on next tick (after initial boot)
241232 setTimeout ( ( ) => {
242- if ( this . appOptions . launchView . startAnimation ) {
243- // ensure launch animation is executed after launchView added to view stack
244- this . appOptions . launchView . startAnimation ( ) ;
245- }
246- bootstrap ( ) ;
233+ // ensure launch animation is executed after launchView added to view stack
234+ this . appOptions . launchView . startAnimation ( ) ;
247235 } ) ;
248- } else {
249- bootstrap ( ) ;
250236 }
251- if ( ! bootstrapPromiseCompleted && ! usingCustomLaunchView ) {
237+ bootstrap ( ) ;
238+ if ( ! bootstrapPromiseCompleted ) {
252239 const errorMessage = "Bootstrap promise didn't resolve" ;
253240 if ( NativeScriptDebug . isLogEnabled ( ) ) {
254241 NativeScriptDebug . bootstrapLogError ( errorMessage ) ;
0 commit comments