Skip to content

Commit 85b9d01

Browse files
committed
fix(init): Bootstrap Angular on page "navigatingTo" event.
Avoid a brief flash of a blank page on slower devices.
1 parent 6e35152 commit 85b9d01

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
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

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { NgView } from "./element-registry";
1414
import { rendererLog as traceLog } from "./trace";
1515
import { escapeRegexSymbols } from "tns-core-modules/utils/utils";
1616
import { Device } from "tns-core-modules/platform";
17+
import { NativeScriptPlatformRef } from "./platform-common";
1718

1819
import { NativeScriptAnimationDriver } from "./animation-driver";
1920

@@ -46,7 +47,7 @@ export class NativeScriptRootRenderer implements RootRenderer {
4647

4748
public get rootView(): View {
4849
if (!this._rootView) {
49-
this._rootView = topmost().currentPage;
50+
this._rootView = NativeScriptPlatformRef.rootPage || topmost().currentPage;
5051
}
5152
return this._rootView;
5253
}

0 commit comments

Comments
 (0)