Skip to content

Commit

Permalink
fix(init): Bootstrap Angular on page "navigatingTo" event.
Browse files Browse the repository at this point in the history
Avoid a brief flash of a blank page on slower devices.
  • Loading branch information
hdeshev committed Mar 21, 2017
1 parent 6e35152 commit 85b9d01
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 13 additions & 3 deletions nativescript-angular/platform-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,20 @@ export const COMMON_PROVIDERS = [

export class NativeScriptPlatformRef extends PlatformRef {
private _bootstrapper: BootstrapperAction;
private static _rootPageRef: WeakRef<Page>;

constructor(private platform: PlatformRef, private appOptions?: AppOptions) {
super();
}

static set rootPage(page: Page) {
NativeScriptPlatformRef._rootPageRef = new WeakRef(page);
}

static get rootPage(): Page {
return NativeScriptPlatformRef._rootPageRef.get();
}

bootstrapModuleFactory<M>(moduleFactory: NgModuleFactory<M>): Promise<NgModuleRef<M>> {
this._bootstrapper = () => this.platform.bootstrapModuleFactory(moduleFactory);

Expand Down Expand Up @@ -149,12 +158,13 @@ export class NativeScriptPlatformRef extends PlatformRef {
const navEntry: NavigationEntry = {
create: (): Page => {
let page = pageFactory({ isBootstrap: true, isLivesync });
NativeScriptPlatformRef.rootPage = page;
if (this.appOptions) {
page.actionBarHidden = this.appOptions.startPageActionBarHidden;
}

let onLoadedHandler = function () {
page.off("loaded", onLoadedHandler);
let initHandler = function () {
page.off(Page.navigatingToEvent, initHandler);
// profiling.stop("application-start");
rendererLog("Page loaded");

Expand Down Expand Up @@ -184,7 +194,7 @@ export class NativeScriptPlatformRef extends PlatformRef {
});
};

page.on("loaded", onLoadedHandler);
page.on(Page.navigatingToEvent, initHandler);

return page;
}
Expand Down
3 changes: 2 additions & 1 deletion nativescript-angular/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { NgView } from "./element-registry";
import { rendererLog as traceLog } from "./trace";
import { escapeRegexSymbols } from "tns-core-modules/utils/utils";
import { Device } from "tns-core-modules/platform";
import { NativeScriptPlatformRef } from "./platform-common";

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

Expand Down Expand Up @@ -46,7 +47,7 @@ export class NativeScriptRootRenderer implements RootRenderer {

public get rootView(): View {
if (!this._rootView) {
this._rootView = topmost().currentPage;
this._rootView = NativeScriptPlatformRef.rootPage || topmost().currentPage;
}
return this._rootView;
}
Expand Down

0 comments on commit 85b9d01

Please sign in to comment.