From 93f4871b3dc1e08da386fd9bd6b744f655568d29 Mon Sep 17 00:00:00 2001 From: Nedyalko Nikolov Date: Mon, 29 Feb 2016 08:35:41 +0200 Subject: [PATCH] Angular ListView component to support {N} ListView. --- .gitignore | 1 + ng-sample/app/app.ts | 4 +- .../app/examples/list/list-test-async.ts | 23 ++-- ng-sample/app/examples/list/list-test.ts | 79 +++++++---- .../directives/list-view-comp.ts | 129 ++++++++++++++++++ .../directives/list-view.ts | 94 ------------- .../directives/ns-directives.ts | 5 +- 7 files changed, 195 insertions(+), 140 deletions(-) create mode 100644 src/nativescript-angular/directives/list-view-comp.ts delete mode 100644 src/nativescript-angular/directives/list-view.ts diff --git a/.gitignore b/.gitignore index e87afa0c2..bbc9ed3d0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ src/nativescript-angular/**/*.js .baseDir.ts .tscache .nvm +.vscode tests/app/**/*.js tests/app/global.d.ts diff --git a/ng-sample/app/app.ts b/ng-sample/app/app.ts index fbf58aaaf..4e5f5edd2 100644 --- a/ng-sample/app/app.ts +++ b/ng-sample/app/app.ts @@ -22,9 +22,9 @@ import {ImageTest} from "./examples/image/image-test"; import {NavigationTest} from "./examples/navigation/navigation-test"; -nativeScriptBootstrap(RendererTest); +//nativeScriptBootstrap(RendererTest); //nativeScriptBootstrap(Benchmark); //nativeScriptBootstrap(ListTest); -// nativeScriptBootstrap(ListTestAsync); +nativeScriptBootstrap(ListTestAsync); // nativeScriptBootstrap(ImageTest); //nativeScriptBootstrap(NavigationTest, [NS_ROUTER_PROVIDERS]); diff --git a/ng-sample/app/examples/list/list-test-async.ts b/ng-sample/app/examples/list/list-test-async.ts index 285a6a968..be2c74a5c 100644 --- a/ng-sample/app/examples/list/list-test-async.ts +++ b/ng-sample/app/examples/list/list-test-async.ts @@ -1,6 +1,5 @@ import { Component, Input, ChangeDetectionStrategy } from 'angular2/core'; import { Observable as RxObservable } from 'rxjs/Observable'; -import { Observable, WrappedValue } from 'data/observable'; class DataItem { constructor(public id: number, public name: string) { } @@ -10,15 +9,15 @@ class DataItem { selector: 'list-test-async', styleUrls: ['examples/list/list-test-async.css'], template: ` - - - - - + + + + + `, changeDetection: ChangeDetectionStrategy.OnPush }) @@ -34,7 +33,7 @@ export class ListTestAsync { var subscr; this.myItems = RxObservable.create(subscriber => { subscr = subscriber; - subscriber.next(WrappedValue.wrap(items)); + subscriber.next(items); return function () { console.log("Unsubscribe called!!!"); } @@ -45,7 +44,7 @@ export class ListTestAsync { counter++; console.log("Adding " + counter + "-th item"); items.push(new DataItem(counter, "data item " + counter)); - subscr.next(WrappedValue.wrap(items)); + subscr.next(items); }, 1000); setTimeout(() => { diff --git a/ng-sample/app/examples/list/list-test.ts b/ng-sample/app/examples/list/list-test.ts index 549a39a6c..48d73bda0 100644 --- a/ng-sample/app/examples/list/list-test.ts +++ b/ng-sample/app/examples/list/list-test.ts @@ -1,46 +1,51 @@ -import {Component, Input} from 'angular2/core'; +import {Component, Input, WrappedValue, ChangeDetectionStrategy} from 'angular2/core'; +import {Label} from 'ui/label'; +import {ObservableArray} from 'data/observable-array'; class DataItem { constructor(public id: number, public name: string) { } } -@Component({ - selector: 'item-component', - template: ` - - - - - ` -}) -export class ItemComponent { - @Input() data: DataItem; - @Input() odd: boolean; - @Input() even: boolean; - constructor() { } -} +// @Component({ +// selector: 'item-component', +// template: ` +// +// +// +// +// ` +// }) +// export class ItemComponent { +// @Input() data: DataItem; +// @Input() odd: boolean; +// @Input() even: boolean; +// constructor() { } +// } @Component({ selector: 'list-test', - directives: [ItemComponent], + //directives: [ItemComponent], template: ` - + - - - + - + + + + + - ` + `, + changeDetection: ChangeDetectionStrategy.OnPush // TEMPLATE WITH COMPONENT // }) export class ListTest { + //public myItems: ObservableArray; public myItems: Array; + private counter: number; constructor() { + //this.myItems = new ObservableArray(); this.myItems = []; - for (var i = 0; i < 30; i++) { + this.counter = 0; + for (var i = 0; i < 50; i++) { this.myItems.push(new DataItem(i, "data item " + i)); + this.counter = i; } } public onItemTap(args) { console.log("------------------------ ItemTapped: " + args.index); } + + onButtonTap() { + this.counter++; + this.myItems.push(new DataItem(this.counter, "data item " + this.counter)); + } + + onSecondButtonTap(args) { + var page = args.object.page; + var label =