Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix centering issue with sticker placeholder #8404

Merged
merged 2 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions res/css/views/messages/_MStickerBody.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,10 @@ limitations under the License.
align-items: center;
justify-content: center;
}

.mx_MStickerBody_placeholder {
// centering
position: absolute;
left: calc(50% - 40px);
top: calc(50% - 40px);
}
4 changes: 2 additions & 2 deletions src/components/views/messages/MImageBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
}
};

private onImageEnter = (e: React.MouseEvent<HTMLImageElement>): void => {
protected onImageEnter = (e: React.MouseEvent<HTMLImageElement>): void => {
this.setState({ hover: true });

if (!this.state.showImage || !this.state.isAnimated || SettingsStore.getValue("autoplayGifs")) {
Expand All @@ -148,7 +148,7 @@ export default class MImageBody extends React.Component<IBodyProps, IState> {
imgElement.src = this.state.contentUrl;
};

private onImageLeave = (e: React.MouseEvent<HTMLImageElement>): void => {
protected onImageLeave = (e: React.MouseEvent<HTMLImageElement>): void => {
this.setState({ hover: false });

if (!this.state.showImage || !this.state.isAnimated || SettingsStore.getValue("autoplayGifs")) {
Expand Down
14 changes: 11 additions & 3 deletions src/components/views/messages/MStickerBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ export default class MStickerBody extends MImageBody {
return <div className="mx_MStickerBody_wrapper" onClick={onClick}> { children } </div>;
}

// Placeholder to show in place of the sticker image if
// img onLoad hasn't fired yet.
// Placeholder to show in place of the sticker image if img onLoad hasn't fired yet.
protected getPlaceholder(width: number, height: number): JSX.Element {
if (this.props.mxEvent.getContent().info?.[BLURHASH_FIELD]) return super.getPlaceholder(width, height);
return <img src={require("../../../../res/img/icons-show-stickers.svg").default} width="75" height="75" />;
return (
<img
className="mx_MStickerBody_placeholder"
src={require("../../../../res/img/icons-show-stickers.svg").default}
width="80"
height="80"
onMouseEnter={this.onImageEnter}
onMouseLeave={this.onImageLeave}
/>
);
}

// Tooltip to show on mouse over
Expand Down