Skip to content

Commit

Permalink
fix(virtual-scroll): fix image rendering bug
Browse files Browse the repository at this point in the history
Closes #6983
  • Loading branch information
adamdbradley committed Nov 20, 2016
1 parent 947780e commit 72276c3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
3 changes: 0 additions & 3 deletions src/components/img/img.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ ion-img {

ion-img img {
flex-shrink: 0;

min-width: 100%;
min-height: 100%;
}

ion-img .img-placeholder {
Expand Down
7 changes: 4 additions & 3 deletions src/components/virtual-scroll/test/list/app-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import { IonicApp, IonicModule } from '../../../..';
templateUrl: 'main.html'
})
export class E2EPage {
items: Array<{title: string}>;
items: Array<{title: string; id: number}>;

constructor() {
this.emptyList();
this.fillList();
}

fillList() {
this.items = [];
for (let i = 0; i < 500; i++) {
this.items.push({
title: 'Item ' + i
title: 'Item ' + i,
id: i
});
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/components/virtual-scroll/test/list/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
<button ion-button (click)="emptyList()">Empty List</button>
</div>

<ion-list [virtualScroll]="items">
<ion-list [virtualScroll]="items">

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

</ion-list>
<h2 class="text-wrap">{{item.title}}</h2>
</ion-item>

</ion-list>

</ion-content>
4 changes: 3 additions & 1 deletion src/components/virtual-scroll/virtual-scroll.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

.virtual-scroll {
position: relative;

contain: content;
}

.virtual-scroll .virtual-position,
Expand All @@ -15,7 +17,7 @@

transition-duration: 0ms;

contain: strict;
contain: content;
}

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

0 comments on commit 72276c3

Please sign in to comment.