Skip to content

Commit

Permalink
fix: Prepare image placeholder for not loaded image and prevent jumpi…
Browse files Browse the repository at this point in the history
…ng (#16941)

* fix: Prepare image placeholder for not loaded image and prevent jumping

* fix displaying message warning

* code improvements

* code cleanup

* revert message-warning
  • Loading branch information
przemvs committed Feb 28, 2024
1 parent abf1536 commit b191858
Showing 1 changed file with 15 additions and 10 deletions.
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,24 @@ 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: asset.width,
maxHeight: '80vh',
}),
maxHeight: '80vh',
maxWidth: !imageUrl?.url ? '100%' : imageWidth,

...(!imageUrl?.url &&
!isImageWidthLargerThanDefined && {
height: asset.height,
}),
};

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

return (
Expand Down

0 comments on commit b191858

Please sign in to comment.