From 732eec3095ff4501d7c05d5c4d1cfb0bbea282db Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Thu, 16 Mar 2023 22:14:04 +0800 Subject: [PATCH] fix: reach start in message feed --- .../chat/Layout/VirtualMessageFeed/index.tsx | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/routes/chat/Layout/VirtualMessageFeed/index.tsx b/src/routes/chat/Layout/VirtualMessageFeed/index.tsx index be6b60ad..41c23a3a 100644 --- a/src/routes/chat/Layout/VirtualMessageFeed/index.tsx +++ b/src/routes/chat/Layout/VirtualMessageFeed/index.tsx @@ -64,17 +64,18 @@ const VirtualMessageFeed = ({ context, id }: Props) => { // }, [mids]); // 加载更多 - const handleLoadMore = useCallback(() => { - console.log("reach start "); - if (historyMid === "reached") return; - let lastMid = mids.slice(0, 1)[0]; - if (historyMid) { - lastMid = +historyMid; + const handleTopStateChange = (isTop: boolean) => { + console.log("reach top ", isTop); + if (isTop) { + if (historyMid === "reached") return; + let lastMid = mids.slice(0, 1)[0]; + if (historyMid) { + lastMid = +historyMid; + } + // prevMids = mids; + loadMoreMessage({ context, id, mid: lastMid }); } - // prevMids = mids; - loadMoreMessage({ context, id, mid: lastMid }); - // return false; - }, [mids, context, id]); + }; // 自动跟随 const handleFollowOutput = (isAtBottom: boolean) => { const [lastMid] = mids ? mids.slice(-1) : [0]; @@ -112,9 +113,10 @@ const VirtualMessageFeed = ({ context, id }: Props) => { }} // firstItemIndex={firstItemIndex} initialTopMostItemIndex={mids.length - 1} - startReached={handleLoadMore} + // startReached={handleLoadMore} data={mids} atTopThreshold={context == "channel" ? 160 : 0} + atTopStateChange={handleTopStateChange} atBottomStateChange={handleBottomStateChange} atBottomThreshold={400} followOutput={handleFollowOutput}