Skip to content

Commit

Permalink
Merge pull request #835 from The-Commit-Company/834-bug-mobile-incorr…
Browse files Browse the repository at this point in the history
…ect-cropping-of-images

fix: maintain aspect ratio of image on mobile even with max width
  • Loading branch information
nikkothari22 authored Apr 9, 2024
2 parents a676c38 + 09f9435 commit 6c7f1a9
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,28 @@ const options = {
const ImageMessageBlock = ({ message }: { message: ImageMessage }) => {
const { ref, inView } = useInView(options);

const height = `${message.thumbnail_height ?? 200}px`
const width = `${message.thumbnail_width ?? 300}px`
const { width, height } = useMemo(() => {
let height = message.thumbnail_height ?? 200
let width = message.thumbnail_width ?? 300

// Max width is 280px, so we need to adjust the height accordingly
const aspectRatio = width / height

if (width > 280) {
width = 280
height = width / aspectRatio
}

return {
height: `${height}px`,
width: `${width}px`
}

}, [message])


// const height = `${message.thumbnail_height ?? 200}px`
// const width = `${message.thumbnail_width ?? 300}px`
return <div className='py-1.5 rounded-lg' ref={ref} style={{
minWidth: width,
minHeight: height
Expand All @@ -250,14 +270,12 @@ const ImageMessageBlock = ({ message }: { message: ImageMessage }) => {
style={{
width: width,
height: height,
maxWidth: '280px'
}}
/>
:
<IonSkeletonText animated className='max-w-60 rounded-md' style={{
width: width,
height: height,
maxWidth: '280px'
}} />
}
</div>
Expand Down

0 comments on commit 6c7f1a9

Please sign in to comment.