mirror of https://github.com/vector-im/riot-web
Merge pull request #6634 from matrix-org/palid/fix/less-blurhash-on-image-load
Make encrypted images loading even more pleasantpull/21833/head
commit
74ff93080d
|
@ -36,6 +36,10 @@ $timelineImageBorderRadius: 4px;
|
||||||
animation: mx--anim-pulse 1.75s infinite cubic-bezier(.4, 0, .6, 1);
|
animation: mx--anim-pulse 1.75s infinite cubic-bezier(.4, 0, .6, 1);
|
||||||
border-radius: $timelineImageBorderRadius;
|
border-radius: $timelineImageBorderRadius;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mx_no-image-placeholder {
|
||||||
|
background-color: $primary-bg-color;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.mx_MImageBody_thumbnail_container {
|
.mx_MImageBody_thumbnail_container {
|
||||||
|
|
|
@ -47,6 +47,7 @@ interface IState {
|
||||||
};
|
};
|
||||||
hover: boolean;
|
hover: boolean;
|
||||||
showImage: boolean;
|
showImage: boolean;
|
||||||
|
placeholder: 'no-image' | 'blurhash';
|
||||||
}
|
}
|
||||||
|
|
||||||
@replaceableComponent("views.messages.MImageBody")
|
@replaceableComponent("views.messages.MImageBody")
|
||||||
|
@ -68,6 +69,7 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
|
||||||
loadedImageDimensions: null,
|
loadedImageDimensions: null,
|
||||||
hover: false,
|
hover: false,
|
||||||
showImage: SettingsStore.getValue("showImages"),
|
showImage: SettingsStore.getValue("showImages"),
|
||||||
|
placeholder: 'no-image',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,6 +279,17 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
|
||||||
this.downloadImage();
|
this.downloadImage();
|
||||||
this.setState({ showImage: true });
|
this.setState({ showImage: true });
|
||||||
} // else don't download anything because we don't want to display anything.
|
} // else don't download anything because we don't want to display anything.
|
||||||
|
|
||||||
|
// Add a 150ms timer for blurhash to first appear.
|
||||||
|
if (this.media.isEncrypted) {
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!this.state.imgLoaded || !this.state.imgError) {
|
||||||
|
this.setState({
|
||||||
|
placeholder: 'blurhash',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, 150);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
@ -434,7 +447,14 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
|
||||||
// Overidden by MStickerBody
|
// Overidden by MStickerBody
|
||||||
protected getPlaceholder(width: number, height: number): JSX.Element {
|
protected getPlaceholder(width: number, height: number): JSX.Element {
|
||||||
const blurhash = this.props.mxEvent.getContent().info[BLURHASH_FIELD];
|
const blurhash = this.props.mxEvent.getContent().info[BLURHASH_FIELD];
|
||||||
if (blurhash) return <Blurhash className="mx_Blurhash" hash={blurhash} width={width} height={height} />;
|
|
||||||
|
if (blurhash) {
|
||||||
|
if (this.state.placeholder === 'no-image') {
|
||||||
|
return <div className="mx_no-image-placeholder" style={{ width: width, height: height }} />;
|
||||||
|
} else if (this.state.placeholder === 'blurhash') {
|
||||||
|
return <Blurhash className="mx_Blurhash" hash={blurhash} width={width} height={height} />;
|
||||||
|
}
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<InlineSpinner w={32} h={32} />
|
<InlineSpinner w={32} h={32} />
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue