Skip to content

Commit

Permalink
fix: Prepare image placeholder for not loaded image and prevent jumping
Browse files Browse the repository at this point in the history
  • Loading branch information
przemvs committed Feb 28, 2024
1 parent 792d538 commit 19f3269
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export interface ImageAssetProps {
isFocusable?: boolean;
}

const MAX_ASSET_WIDTH = 800;

export const ImageAsset = ({
asset,
message,
Expand Down Expand Up @@ -103,21 +105,29 @@ export const ImageAsset = ({
maxWidth: 'var(--conversation-message-asset-width)',
};

const isImageWidthLargerThanDefined = parseInt(asset.width, 10) >= MAX_ASSET_WIDTH;
const imageWidth = isImageWidthLargerThanDefined ? `${MAX_ASSET_WIDTH}px` : asset.width;

const imageAsset: CSSObject = {
aspectRatio: isFileSharingReceivingEnabled ? `${asset.ratio}` : undefined,
...(!imageUrl?.url
? {
maxWidth: asset.width,
maxHeight: asset.height,
maxWidth: '100%',
...(!isImageWidthLargerThanDefined && {
height: asset.height,
}),
maxHeight: '80vh',
}
: {
maxWidth: asset.width,
maxWidth: imageWidth,
maxHeight: '80vh',
}),
};

const imageStyle: CSSObject = {
width: '100%',
width: imageWidth,
maxWidth: '100%',
height: 'auto',
};

return (
Expand Down

0 comments on commit 19f3269

Please sign in to comment.