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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: maintain aspect ratio of image on mobile even with max width #835

Merged
merged 1 commit into from
Apr 9, 2024
Merged
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
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
Loading