Skip to content

Commit bdd3250

Browse files
committed
Merge branch 'master' into fix/923-module-not-destroyed
2 parents a4ee021 + 402fbde commit bdd3250

File tree

5 files changed

+150
-21
lines changed

5 files changed

+150
-21
lines changed

Diff for: CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
<a name="7.2.2"></a>
2+
## [7.2.2](https://github.com/NativeScript/nativescript-angular/compare/7.2.1...7.2.2) (2019-02-19)
3+
4+
5+
### Bug Fixes
6+
7+
* **list-view:** add support for default item template ([4061cc7](https://github.com/NativeScript/nativescript-angular/commit/4061cc7))
8+
9+
10+
111
<a name="7.2.1"></a>
212
## [7.2.1](https://github.com/NativeScript/nativescript-angular/compare/7.2.0...7.2.1) (2019-02-10)
313

Diff for: nativescript-angular/directives/templated-items-comp.ts

+6
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ export abstract class TemplatedItemsComponent implements DoCheck, OnDestroy, Aft
154154
}
155155

156156
viewRef = args.view[NG_VIEW];
157+
157158
// Getting angular view from original element (in cases when ProxyViewContainer
158159
// is used NativeScript internally wraps it in a StackLayout)
159160
if (!viewRef && args.view instanceof LayoutBase && args.view.getChildrenCount() > 0) {
@@ -163,6 +164,11 @@ export abstract class TemplatedItemsComponent implements DoCheck, OnDestroy, Aft
163164
if (!viewRef && isLogEnabled()) {
164165
listViewError(`ViewReference not found for item ${index}. View recycling is not working`);
165166
}
167+
168+
// No ng-template is setup, continue with 'defaultTemplate'
169+
if (!viewRef) {
170+
return;
171+
}
166172
}
167173

168174
if (!viewRef) {

Diff for: nativescript-angular/router/router.module.ts

+26-19
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,39 @@ export { NSEmptyOutletComponent } from "./ns-empty-outlet.component";
1919

2020
export type LocationState = LocationState;
2121

22+
const ROUTER_DIRECTIVES = [NSRouterLink, NSRouterLinkActive, PageRouterOutlet, NSEmptyOutletComponent];
23+
24+
const NS_ROUTER_PROVIDERS = [
25+
{
26+
provide: NSLocationStrategy,
27+
useFactory: provideLocationStrategy,
28+
deps: [[NSLocationStrategy, new Optional(), new SkipSelf()], FrameService],
29+
},
30+
{ provide: LocationStrategy, useExisting: NSLocationStrategy },
31+
NativescriptPlatformLocation,
32+
{ provide: PlatformLocation, useClass: NativescriptPlatformLocation },
33+
RouterExtensions,
34+
NSRouteReuseStrategy,
35+
{ provide: RouteReuseStrategy, useExisting: NSRouteReuseStrategy },
36+
];
37+
2238
@NgModule({
23-
declarations: [NSRouterLink, NSRouterLinkActive, PageRouterOutlet, NSEmptyOutletComponent],
24-
providers: [
25-
{
26-
provide: NSLocationStrategy,
27-
useFactory: provideLocationStrategy,
28-
deps: [[NSLocationStrategy, new Optional(), new SkipSelf()], FrameService],
29-
},
30-
{ provide: LocationStrategy, useExisting: NSLocationStrategy },
31-
NativescriptPlatformLocation,
32-
{ provide: PlatformLocation, useClass: NativescriptPlatformLocation },
33-
RouterExtensions,
34-
NSRouteReuseStrategy,
35-
{ provide: RouteReuseStrategy, useExisting: NSRouteReuseStrategy },
36-
],
39+
declarations: ROUTER_DIRECTIVES,
40+
entryComponents: [NSEmptyOutletComponent],
3741
imports: [RouterModule, NativeScriptCommonModule],
38-
exports: [RouterModule, NSRouterLink, NSRouterLinkActive, PageRouterOutlet, NSEmptyOutletComponent],
42+
exports: [RouterModule, ...ROUTER_DIRECTIVES],
3943
schemas: [NO_ERRORS_SCHEMA],
4044
})
4145
export class NativeScriptRouterModule {
42-
static forRoot(routes: Routes, config?: ExtraOptions): ModuleWithProviders {
43-
return RouterModule.forRoot(routes, config);
46+
static forRoot(routes: Routes, config?: ExtraOptions): ModuleWithProviders<NativeScriptRouterModule> {
47+
return {
48+
ngModule: NativeScriptRouterModule,
49+
providers: [...RouterModule.forRoot(routes, config).providers, ...NS_ROUTER_PROVIDERS]
50+
};
4451
}
4552

46-
static forChild(routes: Routes): ModuleWithProviders {
47-
return RouterModule.forChild(routes);
53+
static forChild(routes: Routes): ModuleWithProviders<NativeScriptRouterModule> {
54+
return { ngModule: NativeScriptRouterModule, providers: RouterModule.forChild(routes).providers };
4855
}
4956
}
5057

Diff for: tests/app/tests/list-view-tests.ts

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { assert } from "./test-config";
2-
import { Component, Input } from "@angular/core";
2+
import { Component, Input, ViewChild } from "@angular/core";
33
import { ComponentFixture, async } from "@angular/core/testing";
44
import { nsTestBedAfterEach, nsTestBedBeforeEach, nsTestBedRender } from "nativescript-angular/testing";
5+
import { ListViewComponent } from "nativescript-angular/directives";
56
// import trace = require("trace");
67
// trace.setCategories("ns-list-view, " + trace.categories.Navigation);
78
// trace.enable();
@@ -76,11 +77,34 @@ export class TestListViewSelectorComponent {
7677
constructor() { testTemplates = { first: 0, second: 0 }; }
7778
}
7879

80+
@Component({
81+
selector: "list-view-default-item-template",
82+
template: `
83+
<GridLayout>
84+
<ListView #listView [items]="myItems"></ListView>
85+
</GridLayout>
86+
`
87+
})
88+
export class TestDefaultItemTemplateComponent {
89+
public myItems: Array<DataItem>;
90+
constructor () {
91+
this.myItems = new Array<DataItem>();
92+
for (let i = 0; i < 100; i++) {
93+
this.myItems.push(new DataItem(i, "Name " + i));
94+
}
95+
}
96+
@ViewChild("listView") listViewElement: ListViewComponent;
97+
onScrollListViewTo() {
98+
this.listViewElement.nativeElement.scrollToIndex(100);
99+
}
100+
}
101+
79102
describe("ListView-tests", () => {
80103
beforeEach(nsTestBedBeforeEach([
81104
TestListViewComponent,
82105
TestListViewSelectorComponent,
83-
ItemTemplateComponent
106+
ItemTemplateComponent,
107+
TestDefaultItemTemplateComponent
84108
]));
85109
afterEach(nsTestBedAfterEach(false));
86110

@@ -98,4 +122,12 @@ describe("ListView-tests", () => {
98122
assert.deepEqual(testTemplates, { first: 2, second: 1 });
99123
});
100124
}));
125+
126+
it("'defaultTemplate' does not throw when list-view is scrolled", async(() => {
127+
nsTestBedRender(TestDefaultItemTemplateComponent)
128+
.then((fixture: ComponentFixture<TestDefaultItemTemplateComponent>) => {
129+
const component = fixture.componentRef.instance;
130+
assert.doesNotThrow(component.onScrollListViewTo.bind(component));
131+
});
132+
}));
101133
});

Diff for: tests/app/tests/router-module-tests.ts

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// make sure you import mocha-config before @angular/core
2+
import { Component, ViewChild } from "@angular/core";
3+
import { nsTestBedAfterEach, nsTestBedBeforeEach, nsTestBedRender } from "nativescript-angular/testing";
4+
import { NativeScriptRouterModule, RouterExtensions } from "nativescript-angular/router";
5+
import { NSRouterLink } from "nativescript-angular/router/ns-router-link";
6+
import { NSLocationStrategy } from "nativescript-angular/router/ns-location-strategy";
7+
import { assert } from "~/tests/test-config";
8+
import { ActivatedRoute, Router, RouteReuseStrategy } from "@angular/router";
9+
import { LocationStrategy, PlatformLocation } from "@angular/common";
10+
import { NSRouteReuseStrategy } from "nativescript-angular/router/ns-route-reuse-strategy";
11+
12+
@Component({
13+
template: `<StackLayout><Label nsRouterLink text="COMPONENT"></Label></StackLayout>`
14+
})
15+
class RouterTestComponent {
16+
@ViewChild(NSRouterLink)
17+
nsRouterLink: NSRouterLink;
18+
}
19+
20+
describe("NativeScriptRouterModule.forRoot", () => {
21+
beforeEach(nsTestBedBeforeEach(
22+
[RouterTestComponent],
23+
[],
24+
[NativeScriptRouterModule.forRoot([])],
25+
[]));
26+
27+
afterEach(nsTestBedAfterEach());
28+
29+
it("should provide nativescript routing services", () => {
30+
return nsTestBedRender(RouterTestComponent).then((fixture) => {
31+
const injector = fixture.componentRef.injector
32+
33+
assert.instanceOf(injector.get(LocationStrategy, null), NSLocationStrategy);
34+
assert.instanceOf(injector.get(RouterExtensions, null), RouterExtensions);
35+
assert.instanceOf(injector.get(RouteReuseStrategy, null), NSRouteReuseStrategy);
36+
});
37+
});
38+
39+
it("should provide nativescript routing directives", () => {
40+
return nsTestBedRender(RouterTestComponent).then((fixture) => {
41+
const linkDirective = fixture.componentRef.instance.nsRouterLink;
42+
assert.instanceOf(linkDirective, NSRouterLink);
43+
});
44+
});
45+
});
46+
47+
describe("NativeScriptRouterModule.forChild", () => {
48+
beforeEach(nsTestBedBeforeEach(
49+
[RouterTestComponent],
50+
[
51+
{ provide: Router, useValue: {} },
52+
{ provide: RouterExtensions, useValue: {} },
53+
{ provide: ActivatedRoute, useValue: {} },
54+
],
55+
[NativeScriptRouterModule.forChild([])],
56+
[]));
57+
afterEach(nsTestBedAfterEach());
58+
59+
it("should not provide nativescript routing services", () => {
60+
return nsTestBedRender(RouterTestComponent).then((fixture) => {
61+
const injector = fixture.componentRef.injector
62+
assert.isNull(injector.get(LocationStrategy, null));
63+
assert.isNull(injector.get(RouteReuseStrategy, null));
64+
});
65+
});
66+
67+
it("should provide nativescript routing directives", () => {
68+
return nsTestBedRender(RouterTestComponent).then((fixture) => {
69+
const linkDirective = fixture.componentRef.instance.nsRouterLink;
70+
assert.instanceOf(linkDirective, NSRouterLink);
71+
});
72+
});
73+
});
74+

0 commit comments

Comments
 (0)