From 658185a39fc1a8dc91131393a86e9079e2dbfb2f Mon Sep 17 00:00:00 2001 From: sup39 Date: Thu, 18 Jan 2024 07:58:58 +0900 Subject: [PATCH] fix: auto scroll to bottom properly --- src/app/organisms/room/RoomTimeline.tsx | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/app/organisms/room/RoomTimeline.tsx b/src/app/organisms/room/RoomTimeline.tsx index 56d895e..483356d 100644 --- a/src/app/organisms/room/RoomTimeline.tsx +++ b/src/app/organisms/room/RoomTimeline.tsx @@ -666,13 +666,13 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli // Stay at bottom when room editor resize useResizeObserver( useMemo(() => { - let mounted = false; + // let mounted = false; return (entries) => { - if (!mounted) { - // skip initial mounting call - mounted = true; - return; - } + // if (!mounted) { + // // skip initial mounting call + // mounted = true; + // return; + // } if (!roomInputRef.current) return; const editorBaseEntry = getResizeObserverEntry(roomInputRef.current, entries); const scrollElement = getScrollElement(); @@ -1100,13 +1100,17 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli if (typeof mxcUrl !== 'string') { return null; } - // const height = scaleYDimension(imgInfo?.w || 400, 400, imgInfo?.h || 400); + // FIXME + const imgW = imgInfo?.w ?? 400; + const imgH = imgInfo?.h ?? 400; + const maxW = scrollRef.current?.querySelector(`[data-message-id]>div>div:nth-child(2)`)?.clientWidth ?? 400; + const height = imgW <= maxW ? imgH : scaleYDimension(imgW, maxW, imgH); return (