mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
Merge pull request #640 from vector-im/bwindels/lazyloadimageswhenpartiallyinview
load image in timeline from when it is partially visible
This commit is contained in:
commit
b5a1c419ca
@ -25,10 +25,8 @@ export class BaseMediaTile extends BaseMessageTile {
|
|||||||
super(options);
|
super(options);
|
||||||
this._decryptedThumbnail = null;
|
this._decryptedThumbnail = null;
|
||||||
this._decryptedFile = null;
|
this._decryptedFile = null;
|
||||||
|
this._isVisible = false;
|
||||||
this._error = null;
|
this._error = null;
|
||||||
if (!this.isPending) {
|
|
||||||
this._tryLoadEncryptedThumbnail();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get isUploading() {
|
get isUploading() {
|
||||||
@ -60,6 +58,9 @@ export class BaseMediaTile extends BaseMessageTile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get thumbnailUrl() {
|
get thumbnailUrl() {
|
||||||
|
if (!this._isVisible) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
if (this._decryptedThumbnail) {
|
if (this._decryptedThumbnail) {
|
||||||
return this._decryptedThumbnail.url;
|
return this._decryptedThumbnail.url;
|
||||||
} else {
|
} else {
|
||||||
@ -85,6 +86,15 @@ export class BaseMediaTile extends BaseMessageTile {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notifyVisible() {
|
||||||
|
super.notifyVisible();
|
||||||
|
this._isVisible = true;
|
||||||
|
this.emitChange("thumbnailUrl");
|
||||||
|
if (!this.isPending) {
|
||||||
|
this._tryLoadEncryptedThumbnail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get width() {
|
get width() {
|
||||||
const info = this._getContent()?.info;
|
const info = this._getContent()?.info;
|
||||||
return Math.round(info?.w * this._scaleFactor());
|
return Math.round(info?.w * this._scaleFactor());
|
||||||
|
@ -19,7 +19,6 @@ import {BaseMediaView} from "./BaseMediaView.js";
|
|||||||
export class ImageView extends BaseMediaView {
|
export class ImageView extends BaseMediaView {
|
||||||
renderMedia(t, vm) {
|
renderMedia(t, vm) {
|
||||||
const img = t.img({
|
const img = t.img({
|
||||||
loading: "lazy",
|
|
||||||
src: vm => vm.thumbnailUrl,
|
src: vm => vm.thumbnailUrl,
|
||||||
alt: vm => vm.label,
|
alt: vm => vm.label,
|
||||||
title: vm => vm.label,
|
title: vm => vm.label,
|
||||||
|
Loading…
Reference in New Issue
Block a user