fix(virtualScroll): detect changes in individual nodes

Closes #6137
This commit is contained in:
Adam Bradley
2016-06-08 21:52:45 -05:00
parent b5107cdaf1
commit f049521095
3 changed files with 25 additions and 13 deletions

View File

@ -6,13 +6,18 @@ import {ionicBootstrap} from '../../../../../src';
templateUrl: 'main.html' templateUrl: 'main.html'
}) })
class E2EPage { class E2EPage {
items = []; items: any[] = [];
@ViewChild('content') content: ElementRef; @ViewChild('content') content: ElementRef;
constructor() { constructor() {
for (var i = 0; i < 200; i++) { for (var i = 0; i < 200; i++) {
this.items.push(i); this.items.push({
value: i,
someMethod: function() {
return `!!`
}
});
} }
} }

View File

@ -18,7 +18,7 @@
</ion-item-divider> </ion-item-divider>
<ion-item *virtualItem="let item"> <ion-item *virtualItem="let item">
Item: {{item}} Item: {{item.value}} {{item.someMethod()}}
</ion-item> </ion-item>
</ion-list> </ion-list>

View File

@ -436,7 +436,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
this._ftrTmp && this._ftrTmp.templateRef, true); this._ftrTmp && this._ftrTmp.templateRef, true);
// ******** DOM WRITE **************** // ******** DOM WRITE ****************
this._cd.detectChanges(); this.detectChanges();
// wait a frame before trying to read and calculate the dimensions // wait a frame before trying to read and calculate the dimensions
nativeRaf(this.postRenderVirtual.bind(this)); nativeRaf(this.postRenderVirtual.bind(this));
@ -470,6 +470,20 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
); );
} }
/**
* @private
*/
detectChanges() {
let node: VirtualNode;
for (var i = 0; i < this._nodes.length; i++) {
node = this._nodes[i];
if (node.hasChanges) {
node.view['detectChanges']();
node.hasChanges = false;
}
}
}
/** /**
* @private * @private
*/ */
@ -481,14 +495,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
if (this._queue === QUEUE_CHANGE_DETECTION) { if (this._queue === QUEUE_CHANGE_DETECTION) {
// ******** DOM WRITE **************** // ******** DOM WRITE ****************
let node: VirtualNode; this.detectChanges();
for (var i = 0; i < this._nodes.length; i++) {
node = this._nodes[i];
if (node.hasChanges) {
node.view['detectChanges']();
node.hasChanges = false;
}
}
if (this._eventAssist) { if (this._eventAssist) {
// queue updating node positions in the next frame // queue updating node positions in the next frame
@ -573,7 +580,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
adjustRendered(this._cells, this._data); adjustRendered(this._cells, this._data);
// ******** DOM WRITE **************** // ******** DOM WRITE ****************
this._cd.detectChanges(); this.detectChanges();
// ******** DOM WRITE **************** // ******** DOM WRITE ****************
this.setVirtualHeight( this.setVirtualHeight(