Skip to content

Commit f049521

Browse files
committed
fix(virtualScroll): detect changes in individual nodes
Closes #6137
1 parent b5107cd commit f049521

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

src/components/virtual-scroll/test/basic/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ import {ionicBootstrap} from '../../../../../src';
66
templateUrl: 'main.html'
77
})
88
class E2EPage {
9-
items = [];
9+
items: any[] = [];
1010

1111
@ViewChild('content') content: ElementRef;
1212

1313
constructor() {
1414
for (var i = 0; i < 200; i++) {
15-
this.items.push(i);
15+
this.items.push({
16+
value: i,
17+
someMethod: function() {
18+
return `!!`
19+
}
20+
});
1621
}
1722
}
1823

src/components/virtual-scroll/test/basic/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</ion-item-divider>
1919

2020
<ion-item *virtualItem="let item">
21-
Item: {{item}}
21+
Item: {{item.value}} {{item.someMethod()}}
2222
</ion-item>
2323

2424
</ion-list>

src/components/virtual-scroll/virtual-scroll.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
436436
this._ftrTmp && this._ftrTmp.templateRef, true);
437437

438438
// ******** DOM WRITE ****************
439-
this._cd.detectChanges();
439+
this.detectChanges();
440440

441441
// wait a frame before trying to read and calculate the dimensions
442442
nativeRaf(this.postRenderVirtual.bind(this));
@@ -470,6 +470,20 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
470470
);
471471
}
472472

473+
/**
474+
* @private
475+
*/
476+
detectChanges() {
477+
let node: VirtualNode;
478+
for (var i = 0; i < this._nodes.length; i++) {
479+
node = this._nodes[i];
480+
if (node.hasChanges) {
481+
node.view['detectChanges']();
482+
node.hasChanges = false;
483+
}
484+
}
485+
}
486+
473487
/**
474488
* @private
475489
*/
@@ -481,14 +495,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
481495

482496
if (this._queue === QUEUE_CHANGE_DETECTION) {
483497
// ******** DOM WRITE ****************
484-
let node: VirtualNode;
485-
for (var i = 0; i < this._nodes.length; i++) {
486-
node = this._nodes[i];
487-
if (node.hasChanges) {
488-
node.view['detectChanges']();
489-
node.hasChanges = false;
490-
}
491-
}
498+
this.detectChanges();
492499

493500
if (this._eventAssist) {
494501
// queue updating node positions in the next frame
@@ -573,7 +580,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
573580
adjustRendered(this._cells, this._data);
574581

575582
// ******** DOM WRITE ****************
576-
this._cd.detectChanges();
583+
this.detectChanges();
577584

578585
// ******** DOM WRITE ****************
579586
this.setVirtualHeight(

0 commit comments

Comments
 (0)