Skip to content

Commit ab04aba

Browse files
hdeshevsis0k0
authored andcommitted
fix(init): Bootstrap Angular on page "navigatingTo" event.
Avoid a brief flash of a blank page on slower devices.
1 parent 409e717 commit ab04aba

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

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

+13-3
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,20 @@ export const COMMON_PROVIDERS = [
6161

6262
export class NativeScriptPlatformRef extends PlatformRef {
6363
private _bootstrapper: BootstrapperAction;
64+
private static _rootPageRef: WeakRef<Page>;
6465

6566
constructor(private platform: PlatformRef, private appOptions?: AppOptions) {
6667
super();
6768
}
6869

70+
static set rootPage(page: Page) {
71+
NativeScriptPlatformRef._rootPageRef = new WeakRef(page);
72+
}
73+
74+
static get rootPage(): Page {
75+
return NativeScriptPlatformRef._rootPageRef.get();
76+
}
77+
6978
bootstrapModuleFactory<M>(moduleFactory: NgModuleFactory<M>): Promise<NgModuleRef<M>> {
7079
this._bootstrapper = () => this.platform.bootstrapModuleFactory(moduleFactory);
7180

@@ -149,12 +158,13 @@ export class NativeScriptPlatformRef extends PlatformRef {
149158
const navEntry: NavigationEntry = {
150159
create: (): Page => {
151160
let page = pageFactory({ isBootstrap: true, isLivesync });
161+
NativeScriptPlatformRef.rootPage = page;
152162
if (this.appOptions) {
153163
page.actionBarHidden = this.appOptions.startPageActionBarHidden;
154164
}
155165

156-
let onLoadedHandler = function () {
157-
page.off("loaded", onLoadedHandler);
166+
let initHandler = function () {
167+
page.off(Page.navigatingToEvent, initHandler);
158168
// profiling.stop("application-start");
159169
rendererLog("Page loaded");
160170

@@ -184,7 +194,7 @@ export class NativeScriptPlatformRef extends PlatformRef {
184194
});
185195
};
186196

187-
page.on("loaded", onLoadedHandler);
197+
page.on(Page.navigatingToEvent, initHandler);
188198

189199
return page;
190200
}

Diff for: nativescript-angular/renderer.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ import {
33
Renderer2, RendererFactory2, RendererType2,
44
RendererStyleFlags2, ViewEncapsulation,
55
} from "@angular/core";
6-
import { APP_ROOT_VIEW, DEVICE } from "./platform-providers";
6+
77
import { isBlank } from "./lang-facade";
88
import { View } from "ui/core/view";
99
import { addCss } from "application";
1010
import { topmost } from "ui/frame";
11+
import { escapeRegexSymbols } from "utils/utils";
12+
import { Device } from "platform";
13+
1114
import { ViewUtil } from "./view-util";
15+
import { APP_ROOT_VIEW, DEVICE } from "./platform-providers";
1216
import { NgView } from "./element-registry";
1317
import { rendererLog as traceLog } from "./trace";
14-
import { escapeRegexSymbols } from "utils/utils";
15-
import { Device } from "platform";
18+
import { NativeScriptPlatformRef } from "./platform-common";
1619

1720
// CONTENT_ATTR not exported from NativeScript_renderer - we need it for styles application.
1821
const COMPONENT_REGEX = /%COMP%/g;
@@ -41,7 +44,7 @@ export class NativeScriptRendererFactory implements RendererFactory2 {
4144

4245
private setRootNgView(rootView: any) {
4346
if (!rootView) {
44-
rootView = <NgView><any>topmost().currentPage;
47+
rootView = NativeScriptPlatformRef.rootPage || <NgView><any>topmost().currentPage;
4548
}
4649
rootView.nodeName = "NONE";
4750
this.rootNgView = rootView;

0 commit comments

Comments
 (0)