Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3e209cc

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 3e209cc

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

‎nativescript-angular/platform-common.ts‎

Lines changed: 13 additions & 3 deletions
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
}

‎nativescript-angular/renderer.ts‎

Lines changed: 2 additions & 1 deletion
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)

AltStyle によって変換されたページ (->オリジナル) /