Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions nativescript-angular/platform-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
on,
launchEvent,
LaunchEventData,
exitEvent,
ApplicationEventData,
} from "tns-core-modules/application";
import { TextView } from "tns-core-modules/ui/text-view";

Expand Down Expand Up @@ -255,7 +257,29 @@ export class NativeScriptPlatformRef extends PlatformRef {
args.root = rootContent;
}
);
const exitCallback = profile(
"nativescript-angular/platform-common.exitCallback", (args: ApplicationEventData) => {
const androidActivity = args.android;
if (androidActivity && !androidActivity.isFinishing()) {
// Exit event was triggered as a part of a restart of the app.
return;
}

const lastModuleRef = lastBootstrappedModule ? lastBootstrappedModule.get() : null;
if (lastModuleRef) {
// Make sure the module is only destroyed once
lastBootstrappedModule = null;

lastModuleRef.destroy();
}

if (!autoCreateFrame) {
rootContent = null;
}
}
);
on(launchEvent, launchCallback);
on(exitEvent, exitCallback);

applicationRun();
}
Expand Down
18 changes: 13 additions & 5 deletions nativescript-angular/router/page-router-outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,19 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire
// Add it to the new page
page.content = componentView;

page.on(Page.navigatedFromEvent, (<any>global).Zone.current.wrap((args: NavigatedData) => {
const navigatedFromCallback = (<any>global).Zone.current.wrap((args: NavigatedData) => {
if (args.isBackNavigation) {
this.locationStrategy._beginBackPageNavigation(this.frame);
this.locationStrategy.back(null, this.frame);
}
}));
});
page.on(Page.navigatedFromEvent, navigatedFromCallback);
componentRef.onDestroy(() => {
if (page) {
page.off(Page.navigatedFromEvent, navigatedFromCallback);
page = null;
}
});

const navOptions = this.locationStrategy._beginPageNavigation(this.frame);

Expand All @@ -367,14 +374,15 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire
if (this.outlet) {
this.routeReuseStrategy.clearCache(this.outlet.outletKeys[0]);
}
page.off(Page.navigatedToEvent, clearCallback);
});

page.on(Page.navigatedToEvent, clearCallback);
page.once(Page.navigatedToEvent, clearCallback);
}

this.frame.navigate({
create: () => { return page; },
create() {
return page;
},
clearHistory: navOptions.clearHistory,
animated: navOptions.animated,
transition: navOptions.transition
Expand Down