Skip to content

Commit aec8f51

Browse files
committed
fix(virtual-scroll): fix tabs content loading
1 parent cf725d3 commit aec8f51

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

src/components/tabs/test/basic/app-module.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,28 @@ export class Tab2 {
184184
</p>
185185
<p>
186186
<button ion-button (click)="selectPrevious()">Select Previous Tab</button>
187-
</p>
188-
<p>
189187
<button ion-button (click)="appNavPop()">App Nav Pop</button>
190188
</p>
189+
190+
<ion-list [virtualScroll]="items" [headerFn]="headerFn">
191+
192+
<ion-item *virtualItem="let item">
193+
Item: {{item}}
194+
</ion-item>
195+
196+
</ion-list>
197+
191198
</ion-content>
192199
`
193200
})
194201
export class Tab3 {
195-
constructor(private alertCtrl: AlertController, private modalCtrl: ModalController, private tabs: Tabs, private app: App) {}
202+
items: number[] = [];
203+
204+
constructor(private alertCtrl: AlertController, private modalCtrl: ModalController, private tabs: Tabs, private app: App) {
205+
for (var i = 0; i < 100; i++) {
206+
this.items.push(i);
207+
}
208+
}
196209

197210
presentAlert() {
198211
let alert = this.alertCtrl.create({

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

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,6 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
335335
this._trackBy = val;
336336
}
337337

338-
private _hasUpdate = false;
339-
340338
constructor(
341339
private _iterableDiffers: IterableDiffers,
342340
private _elementRef: ElementRef,
@@ -356,7 +354,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
356354

357355
// wait for the content to be rendered and has readable dimensions
358356
_content.readReady.subscribe(() => {
359-
this.readUpdate(true, true);
357+
this.readUpdate(true);
360358

361359
if (!this._scrollSub) {
362360
// listen for scroll events
@@ -370,19 +368,10 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
370368
});
371369
}
372370

373-
readUpdate(checkDataChanges: boolean, dimensionsUpdated: boolean) {
371+
readUpdate(dimensionsUpdated: boolean) {
374372
if (!this._records) return;
375373

376-
if (checkDataChanges && !dimensionsUpdated) {
377-
if (isPresent(this._differ) && !isPresent(this._differ.diff(this._records))) {
378-
// no changes
379-
return;
380-
}
381-
}
382-
383-
console.debug(`virtual-scroll, readUpdate, checkDataChanges: ${checkDataChanges}, dimensionsUpdated: ${dimensionsUpdated}`);
384-
385-
this._hasUpdate = true;
374+
console.debug(`virtual-scroll, readUpdate, dimensionsUpdated: ${dimensionsUpdated}`);
386375

387376
// reset everything
388377
this._cells.length = 0;
@@ -399,9 +388,7 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
399388
}
400389

401390
writeUpdate() {
402-
if (!this._hasUpdate) {
403-
return;
404-
}
391+
if (!this._records) return;
405392

406393
console.debug(`virtual-scroll, writeUpdate`);
407394

@@ -414,16 +401,20 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
414401

415402
// ******** DOM WRITE ****************
416403
this.renderVirtual();
404+
}
417405

418-
this._hasUpdate = false;
406+
private _hasChanges() {
407+
return (isPresent(this._records) && isPresent(this._differ) && isPresent(this._differ.diff(this._records)));
419408
}
420409

421410
/**
422411
* @private
423412
*/
424413
ngDoCheck() {
425-
if (this._init) {
426-
this.readUpdate(true, false);
414+
if (this._init && this._hasChanges()) {
415+
// only continue if we've already initialized
416+
// and if there actually are changes
417+
this.readUpdate(false);
427418
this.writeUpdate();
428419
}
429420
}
@@ -444,13 +435,6 @@ export class VirtualScroll implements DoCheck, AfterContentInit, OnDestroy {
444435
this.approxItemHeight = '40px';
445436
console.warn('Virtual Scroll: Please provide an "approxItemHeight" input to ensure proper virtual scroll rendering');
446437
}
447-
448-
// this.update(true);
449-
450-
// this._platform.onResize(() => {
451-
// console.debug('VirtualScroll, onResize');
452-
// this.update(false);
453-
// });
454438
}
455439
}
456440

0 commit comments

Comments
 (0)