From 0b94854cbf4c21825467e70a89c290ea0f7ea09b Mon Sep 17 00:00:00 2001 From: 7w1 Date: Wed, 18 Mar 2026 22:21:04 -0500 Subject: [PATCH] mobile scroll fixes attempttttt --- src/app/features/room/RoomTimeline.tsx | 54 +++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/src/app/features/room/RoomTimeline.tsx b/src/app/features/room/RoomTimeline.tsx index bd0a975f..e5042603 100644 --- a/src/app/features/room/RoomTimeline.tsx +++ b/src/app/features/room/RoomTimeline.tsx @@ -1,4 +1,12 @@ -import { Fragment, RefObject, useCallback, useEffect, useMemo, useRef, useState } from 'react'; +import { + Fragment, + useCallback, + useEffect, + useLayoutEffect, + useMemo, + useRef, + useState, +} from 'react'; import { Editor } from 'slate'; import { useAtomValue, useSetAtom } from 'jotai'; import { PushProcessor, Room, Direction } from '$types/matrix-sdk'; @@ -182,6 +190,12 @@ export function RoomTimeline({ const { isAtBottom, onScroll, scrollToBottom, sentryRef } = useScrollManager(scrollRef); + const scrollDataRef = useRef({ + eventsLength: 0, + scrollHeight: 0, + scrollTop: 0, + }); + const timelineSync = useTimelineSync({ room, mx, @@ -266,6 +280,32 @@ export function RoomTimeline({ } }, [room, unreadInfo, timelineSync.timeline.linkedTimelines, virtualPaginator, eventId]); + useLayoutEffect(() => { + const scrollEl = scrollRef.current; + if (!scrollEl) return; + + const { + eventsLength: oldLength, + scrollHeight: oldHeight, + scrollTop: oldTop, + } = scrollDataRef.current; + const newLength = timelineSync.eventsLength; + + if (newLength > oldLength && oldLength > 0) { + const newHeight = scrollEl.scrollHeight; + const heightDiff = newHeight - oldHeight; + if (oldTop < 500) { + scrollEl.scrollTop = oldTop + heightDiff; + } + } + + scrollDataRef.current = { + eventsLength: newLength, + scrollHeight: scrollEl.scrollHeight, + scrollTop: scrollEl.scrollTop, + }; + }, [timelineSync.eventsLength]); + const actions = useTimelineActions({ room, mx, @@ -448,7 +488,17 @@ export function RoomTimeline({ )} - + { + onScroll(); + if (scrollRef.current) { + scrollDataRef.current.scrollTop = scrollRef.current.scrollTop; + scrollDataRef.current.scrollHeight = scrollRef.current.scrollHeight; + } + }} + >