From a89b2b963b91b9b7dc81d6a86ce461cb02c2d7ae Mon Sep 17 00:00:00 2001 From: Bill Date: Wed, 16 Mar 2022 22:19:54 -0400 Subject: [PATCH] Fix chat history scroll --- .../chat-history/ChatHistoryView.tsx | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/components/chat-history/ChatHistoryView.tsx b/src/components/chat-history/ChatHistoryView.tsx index 76e868eb..e8b1afa6 100644 --- a/src/components/chat-history/ChatHistoryView.tsx +++ b/src/components/chat-history/ChatHistoryView.tsx @@ -1,7 +1,6 @@ import { ILinkEventTracker } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { AutoSizer, CellMeasurer, CellMeasurerCache, List, ListRowProps, ListRowRenderer, Size } from 'react-virtualized'; -import { RenderedRows } from 'react-virtualized/dist/es/List'; import { AddEventLinkTracker, LocalizeText, RemoveLinkEventTracker } from '../../api'; import { Flex, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../common'; import { BatchUpdates } from '../../hooks'; @@ -15,7 +14,6 @@ import { RoomHistoryState } from './common/RoomHistoryState'; export const ChatHistoryView: FC<{}> = props => { const [ isVisible, setIsVisible ] = useState(false); - const [ needsScroll, setNeedsScroll ] = useState(false); const [ chatHistoryUpdateId, setChatHistoryUpdateId ] = useState(-1); const [ roomHistoryUpdateId, setRoomHistoryUpdateId ] = useState(-1); const [ chatHistoryState, setChatHistoryState ] = useState(new ChatHistoryState()); @@ -51,16 +49,6 @@ export const ChatHistoryView: FC<{}> = props => const onResize = (info: Size) => cache.clearAll(); - const onRowsRendered = (info: RenderedRows) => - { - if(elementRef && elementRef.current && isVisible && needsScroll) - { - elementRef.current.scrollToRow(chatHistoryState.chats.length); - - setNeedsScroll(false); - } - } - const linkReceived = useCallback((url: string) => { const parts = url.split('/'); @@ -118,10 +106,8 @@ export const ChatHistoryView: FC<{}> = props => useEffect(() => { - if(elementRef && elementRef.current && isVisible) elementRef.current.scrollToRow(chatHistoryState.chats.length); - - setNeedsScroll(true); - }, [ isVisible, chatHistoryState.chats, chatHistoryUpdateId ]); + if(elementRef && elementRef.current && isVisible) elementRef.current.scrollToRow(-1); + }, [ isVisible ]); return ( @@ -142,7 +128,6 @@ export const ChatHistoryView: FC<{}> = props => rowHeight={ cache.rowHeight } className={ 'chat-history-list' } rowRenderer={ RowRenderer } - onRowsRendered={ onRowsRendered } deferredMeasurementCache={ cache } /> ) } }