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 b2e467f

Browse files
fix(router): link active directive (#2225)
1 parent d5a8c1c commit b2e467f

File tree

7 files changed

+52
-42
lines changed

7 files changed

+52
-42
lines changed

‎e2e/animation-examples/tsconfig.tns.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎e2e/tests-app-ng/app/modal/modal-dialogs/modal-dialog.component.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,15 @@ export class ModalContentComponent {
3535
}
3636
}
3737

38-
const TEMPLATE = `
39-
<GridLayout rows="auto, auto, *">
40-
<Button text="show component" (tap)="showModal()"></Button>
41-
<Button text="show component (async)" (tap)="showModalAsync()" row="1"></Button>
42-
<Label [text]="'RESULT: ' + result" row="2" margin="12"></Label>
43-
</GridLayout>
44-
`;
45-
4638
@Component({
4739
selector: "modal-test",
48-
providers: [ModalDialogService],
49-
template: TEMPLATE
40+
template: `
41+
<GridLayout rows="auto, auto, *">
42+
<Button text="show component" (tap)="showModal()"></Button>
43+
<Button text="show component (async)" (tap)="showModalAsync()" row="1"></Button>
44+
<Label [text]="'RESULT: ' + result" row="2" margin="12"></Label>
45+
</GridLayout>
46+
`
5047
})
5148
export class ModalTestComponent {
5249
public result: string = "---";
@@ -75,7 +72,13 @@ export class ModalTestComponent {
7572
@Component({
7673
selector: "modal-test-on-push",
7774
changeDetection: ChangeDetectionStrategy.OnPush,
78-
template: TEMPLATE
75+
template: `
76+
<GridLayout rows="auto, auto, *">
77+
<Button text="show component" (tap)="showModal()"></Button>
78+
<Button text="show component (async)" (tap)="showModalAsync()" row="1"></Button>
79+
<Label [text]="'RESULT: ' + result" row="2" margin="12"></Label>
80+
</GridLayout>
81+
`
7982
})
8083
export class ModalTestWithPushStrategyComponent {
8184
public result: string = "---";

‎e2e/tests-app-ng/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"version": "6.5.2"
1010
},
1111
"tns-android": {
12-
"version": "6.5.0"
12+
"version": "6.5.3"
1313
}
1414
},
1515
"dependencies": {
@@ -37,11 +37,11 @@
3737
"codelyzer": "^5.1.0",
3838
"filewalker": "^0.1.3",
3939
"lazy": "1.0.11",
40-
"@nativescript/webpack": "rc",
40+
"@nativescript/webpack": "~2.1.1",
4141
"typescript": "~3.9.0"
4242
},
4343
"scripts": {
44-
"clean": "npx rimraf hooks node_modules platforms package-lock.json",
44+
"clean": "npx rimraf hooks node_modules platforms package-lock.json webpack.config.js && npm i",
4545
"setup": "cd ../../nativescript-angular && npm run prep.apps && cd ../e2e/tests-app-ng && npm run clean",
4646
"ngcc": "ngcc --properties es2015 module main --first-only",
4747
"postinstall": "npm run ngcc",

‎e2e/tests-app-ng/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"compilerOptions": {
3-
"module": "esnext",
3+
"module": "ESNext",
44
"target": "es2015",
5+
"moduleResolution": "node",
56
"experimentalDecorators": true,
67
"emitDecoratorMetadata": true,
78
"noEmitHelpers": true,
@@ -20,6 +21,7 @@
2021
}
2122
},
2223
"files": [
24+
"./references.d.ts",
2325
"./app/main.ts"
2426
],
2527
"exclude": [

‎e2e/tests-app-ng/tsconfig.tns.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎nativescript-angular/router/ns-router-link-active.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,13 @@ export class NSRouterLinkActive implements OnChanges, OnDestroy, AfterContentIni
104104
if (this.active !== hasActiveLinks) {
105105
const currentUrlTree = this.router.parseUrl(this.router.url);
106106
const isActiveLinks = this.reduceList(currentUrlTree, this.links);
107-
this.classes.forEach((c) => this.renderer.setStyle(this.element.nativeElement, c, isActiveLinks));
107+
this.classes.forEach((c) => {
108+
if (isActiveLinks) {
109+
this.renderer.removeClass(this.element.nativeElement, c);
110+
} else {
111+
this.renderer.addClass(this.element.nativeElement, c);
112+
}
113+
});
108114
}
109115
Promise.resolve(hasActiveLinks).then((active) => (this.active = active));
110116
}

‎nativescript-angular/router/ns-router-link.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Directive, HostListener,Input } from '@angular/core';
1+
import { Directive, Input,ElementRef,NgZone } from '@angular/core';
22
import { NavigationExtras } from '@angular/router';
33
import { ActivatedRoute, Router, UrlTree } from '@angular/router';
44
import { NavigationTransition } from '@nativescript/core';
@@ -52,7 +52,30 @@ export class NSRouterLink {
5252

5353
private commands: any[] = [];
5454

55-
constructor(private router: Router, private navigator: RouterExtensions, private route: ActivatedRoute) {}
55+
constructor(private ngZone: NgZone, private router: Router, private navigator: RouterExtensions, private route: ActivatedRoute, private el: ElementRef) {
56+
}
57+
58+
ngAfterViewInit() {
59+
this.el.nativeElement.on('tap', () => {
60+
this.ngZone.run(() => {
61+
if (NativeScriptDebug.isLogEnabled()) {
62+
NativeScriptDebug.routerLog(`nsRouterLink.tapped: ${this.commands} ` + `clear: ${this.clearHistory} ` + `transition: ${JSON.stringify(this.pageTransition)} ` + `duration: ${this.pageTransitionDuration}`);
63+
}
64+
65+
const extras = this.getExtras();
66+
// this.navigator.navigateByUrl(this.urlTree, extras);
67+
this.navigator.navigate(this.commands, {
68+
...extras,
69+
relativeTo: this.route,
70+
queryParams: this.queryParams,
71+
fragment: this.fragment,
72+
preserveQueryParams: attrBoolValue(this.preserveQueryParams),
73+
queryParamsHandling: this.queryParamsHandling,
74+
preserveFragment: attrBoolValue(this.preserveFragment),
75+
});
76+
});
77+
});
78+
}
5679

5780
@Input('nsRouterLink')
5881
set params(data: any[] | string) {
@@ -63,16 +86,6 @@ export class NSRouterLink {
6386
}
6487
}
6588

66-
@HostListener('tap')
67-
onTap() {
68-
if (NativeScriptDebug.isLogEnabled()) {
69-
NativeScriptDebug.routerLog(`nsRouterLink.tapped: ${this.commands} ` + `clear: ${this.clearHistory} ` + `transition: ${JSON.stringify(this.pageTransition)} ` + `duration: ${this.pageTransitionDuration}`);
70-
}
71-
72-
const extras = this.getExtras();
73-
this.navigator.navigateByUrl(this.urlTree, extras);
74-
}
75-
7689
private getExtras(): NavigationExtras & NavigationOptions {
7790
const transition = this.getTransition();
7891
return {

0 commit comments

Comments
(0)

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