Skip to content

Commit 999efac

Browse files
committed
fix(virtual-list): works with infinite-scroll
fixes #9350 fixes #9722 fixes #9247 fixes #10778
1 parent 1222c56 commit 999efac

File tree

7 files changed

+273
-96
lines changed

7 files changed

+273
-96
lines changed

src/components/img/img.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export class Img implements OnDestroy {
248248
const imgEle = this._img;
249249
const renderer = this._renderer;
250250

251-
if (imgEle.src !== srcAttr) {
251+
if (imgEle && imgEle.src !== srcAttr) {
252252
renderer.setElementAttribute(this._img, 'src', srcAttr);
253253
renderer.setElementAttribute(this._img, 'alt', this.alt);
254254
}

src/components/loading/test/basic/app.module.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ export class E2EPage {
253253
}
254254

255255
presentLoadingOpenDismiss() {
256-
// debugger;
257256
const loading = this.loadingCtrl.create({
258257
content: 'Loading 1'
259258
});

src/components/virtual-scroll/test/basic/app.module.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
import { Component, NgModule } from '@angular/core';
1+
import { Component, NgModule, enableProdMode } from '@angular/core';
22
import { IonicApp, IonicModule, NavController, Platform } from '../../../../../ionic-angular';
33

44

5+
enableProdMode();
6+
57
@Component({
68
templateUrl: 'main.html'
79
})
810
export class E2EPage {
911
items: any[] = [];
1012
webview: string = '';
13+
counter: number = 0;
1114

1215
constructor(plt: Platform, public navCtrl: NavController) {
1316
for (var i = 0; i < 200; i++) {
14-
this.items.push({
15-
value: i,
16-
someMethod: function() {
17-
return '!!';
18-
}
19-
});
17+
this.addItem();
2018
}
2119

2220
if (plt.is('ios')) {
@@ -43,6 +41,16 @@ export class E2EPage {
4341
this.navCtrl.push(E2EPage);
4442
}
4543

44+
addItem() {
45+
this.items.push({
46+
value: this.counter,
47+
someMethod: function() {
48+
return '!!';
49+
}
50+
});
51+
this.counter++;
52+
}
53+
4654
reload() {
4755
window.location.reload(true);
4856
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
<button ion-button (click)="reload()">
66
Reload
77
</button>
8+
<button ion-button icon-only (click)="addItem()">
9+
<ion-icon name="add"></ion-icon>
10+
</button>
811
</ion-buttons>
912
</ion-navbar>
1013
</ion-header>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { Component, NgModule } from '@angular/core';
2+
import { IonicApp, IonicModule } from '../../../../../ionic-angular';
3+
4+
5+
@Component({
6+
templateUrl: 'main.html'
7+
})
8+
export class E2EPage {
9+
counter = 1;
10+
items: any[] = [];
11+
enabled = true;
12+
13+
constructor() {
14+
for (let i = 0; i < 100; i++) {
15+
this.addItem();
16+
}
17+
}
18+
19+
addItem() {
20+
this.items.push(this.counter);
21+
this.counter++;
22+
}
23+
24+
doInfinite(): Promise<any> {
25+
console.log('Begin async operation');
26+
27+
return getAsyncData().then(newData => {
28+
for (var i = 0; i < newData.length; i++) {
29+
this.items.push( this.items.length );
30+
}
31+
32+
console.log('Finished receiving data, async operation complete');
33+
34+
if (this.items.length > 900) {
35+
this.enabled = false;
36+
}
37+
});
38+
}
39+
40+
}
41+
42+
function getAsyncData(): Promise<any[]> {
43+
// async return mock data
44+
return new Promise(resolve => {
45+
46+
setTimeout(() => {
47+
let data: number[] = [];
48+
for (var i = 0; i < 30; i++) {
49+
data.push(i);
50+
}
51+
52+
resolve(data);
53+
}, 500);
54+
55+
});
56+
}
57+
58+
59+
60+
@Component({
61+
template: '<ion-nav [root]="root"></ion-nav>'
62+
})
63+
export class E2EApp {
64+
root = E2EPage;
65+
}
66+
67+
68+
@NgModule({
69+
declarations: [
70+
E2EApp,
71+
E2EPage
72+
],
73+
imports: [
74+
IonicModule.forRoot(E2EApp)
75+
],
76+
bootstrap: [IonicApp],
77+
entryComponents: [
78+
E2EApp,
79+
E2EPage
80+
]
81+
})
82+
export class AppModule {}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<ion-header>
2+
<ion-navbar>
3+
<ion-title>Virtual Scroll</ion-title>
4+
5+
<ion-buttons end>
6+
<button ion-button icon-only (click)="addItem()">
7+
<ion-icon name="add"></ion-icon>
8+
</button>
9+
</ion-buttons>
10+
</ion-navbar>
11+
</ion-header>
12+
13+
14+
<ion-content padding>
15+
16+
<ion-list [virtualScroll]="items">
17+
18+
<ion-item *virtualItem="let item">
19+
Item: {{item}}
20+
</ion-item>
21+
22+
</ion-list>
23+
24+
<ion-infinite-scroll (ionInfinite)="$event.waitFor(doInfinite())" [enabled]="enabled" threshold="100px">
25+
<ion-infinite-scroll-content
26+
loadingSpinner="bubbles"
27+
loadingText="Loading more data...">
28+
</ion-infinite-scroll-content>
29+
</ion-infinite-scroll>
30+
31+
</ion-content>
32+

0 commit comments

Comments
 (0)