Skip to content

Commit 72276c3

Browse files
committed
fix(virtual-scroll): fix image rendering bug
Closes #6983
1 parent 947780e commit 72276c3

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

src/components/img/img.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ ion-img {
1414

1515
ion-img img {
1616
flex-shrink: 0;
17-
18-
min-width: 100%;
19-
min-height: 100%;
2017
}
2118

2219
ion-img .img-placeholder {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ import { IonicApp, IonicModule } from '../../../..';
66
templateUrl: 'main.html'
77
})
88
export class E2EPage {
9-
items: Array<{title: string}>;
9+
items: Array<{title: string; id: number}>;
1010

1111
constructor() {
12-
this.emptyList();
12+
this.fillList();
1313
}
1414

1515
fillList() {
1616
this.items = [];
1717
for (let i = 0; i < 500; i++) {
1818
this.items.push({
19-
title: 'Item ' + i
19+
title: 'Item ' + i,
20+
id: i
2021
});
2122
}
2223
}

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717
<button ion-button (click)="emptyList()">Empty List</button>
1818
</div>
1919

20-
<ion-list [virtualScroll]="items">
20+
<ion-list [virtualScroll]="items">
2121

22-
<ion-item text-wrap *virtualItem="let item" (click)="itemTapped($event, item)">
23-
{{item.title}}
24-
</ion-item>
22+
<ion-item class="item-text-wrap" *virtualItem="let item" (click)="itemTapped(item)">
23+
<ion-thumbnail item-left>
24+
<ion-img src="http://loremflickr.com/80/80/dog?{{item.id}}"></ion-img>
25+
</ion-thumbnail>
2526

26-
</ion-list>
27+
<h2 class="text-wrap">{{item.title}}</h2>
28+
</ion-item>
29+
30+
</ion-list>
2731

2832
</ion-content>

src/components/virtual-scroll/virtual-scroll.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
.virtual-scroll {
66
position: relative;
7+
8+
contain: content;
79
}
810

911
.virtual-scroll .virtual-position,
@@ -15,7 +17,7 @@
1517

1618
transition-duration: 0ms;
1719

18-
contain: strict;
20+
contain: content;
1921
}
2022

2123
.virtual-scroll .virtual-hidden {

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,13 @@ import { VirtualFooter, VirtualHeader, VirtualItem } from './virtual-item';
106106
* Ionic provides `<ion-img>` to manage HTTP requests and image rendering.
107107
* Additionally, it includes a customizable placeholder element which shows
108108
* before the image has finished loading. While scrolling through items
109-
* quickly, `<ion-img>` knows not to make any image requests, and only loads
110-
* the images that are viewable after scrolling. It's also important for app
111-
* developers to ensure image sizes are locked in, and after images have fully
112-
* loaded they do not change size and affect any other element sizes.
109+
* quickly, `<ion-img>` knows not to make any image http requests, and only
110+
* loads the images that are viewable after scrolling.
111+
*
112+
* It's also important for app developers to ensure image sizes are locked in,
113+
* and after images have fully loaded they do not change size and affect any
114+
* other element sizes. Simply put, to ensure rendering bugs are not introduced,
115+
* it's vital that elements within a virtual item does not dynamically change.
113116
*
114117
* We recommend using our `<ion-img>` element over the native `<img>` element
115118
* because when an `<img>` element is added to the DOM, it immediately
@@ -164,6 +167,9 @@ import { VirtualFooter, VirtualHeader, VirtualItem } from './virtual-item';
164167
* while scrolling.
165168
* - Image sizes should be locked in, meaning the size of any element
166169
* should not change after the image has loaded.
170+
* - For the most part, ensure the element size for each virtual item
171+
* does not dynamically change, but rather, their size must already be
172+
* locked in via CSS at the time they are rendered.
167173
* - Provide an approximate width and height so the virtual scroll can
168174
* best calculate the cell height.
169175
* - Changing the dataset requires the entire virtual scroll to be

0 commit comments

Comments
 (0)