Исправлен скролл вниз при подгрузке новых сообщений
This commit is contained in:
@@ -21,6 +21,7 @@ export function Messages() {
|
|||||||
const isFirstRenderRef = useRef(true);
|
const isFirstRenderRef = useRef(true);
|
||||||
const previousScrollHeightRef = useRef(0);
|
const previousScrollHeightRef = useRef(0);
|
||||||
const distanceFromButtomRef = useRef(0);
|
const distanceFromButtomRef = useRef(0);
|
||||||
|
const distanceFromTopRef = useRef(0);
|
||||||
|
|
||||||
const [affix, setAffix] = useState(false);
|
const [affix, setAffix] = useState(false);
|
||||||
const [wallpaper] = useSetting<string>
|
const [wallpaper] = useSetting<string>
|
||||||
@@ -120,7 +121,8 @@ export function Messages() {
|
|||||||
const lastMessage = messages[messages.length - 1];
|
const lastMessage = messages[messages.length - 1];
|
||||||
|
|
||||||
// Скроллим если пользователь внизу или это его собственное сообщение
|
// Скроллим если пользователь внизу или это его собственное сообщение
|
||||||
if ((shouldAutoScrollRef.current || lastMessage.from_me)) {
|
if ((shouldAutoScrollRef.current || lastMessage.from_me) && distanceFromTopRef.current > 10) {
|
||||||
|
console.info(distanceFromTopRef.current);
|
||||||
scrollToBottom(true);
|
scrollToBottom(true);
|
||||||
}
|
}
|
||||||
}, [messages.length, loading, scrollToBottom]);
|
}, [messages.length, loading, scrollToBottom]);
|
||||||
@@ -175,6 +177,8 @@ export function Messages() {
|
|||||||
onScrollPositionChange={(scroll) => {
|
onScrollPositionChange={(scroll) => {
|
||||||
if (!viewportRef.current) return;
|
if (!viewportRef.current) return;
|
||||||
|
|
||||||
|
distanceFromTopRef.current = scroll.y;
|
||||||
|
|
||||||
// Загружаем старые сообщения при достижении верха
|
// Загружаем старые сообщения при достижении верха
|
||||||
if (scroll.y === 0 && !loading && messages.length >= 20) {
|
if (scroll.y === 0 && !loading && messages.length >= 20) {
|
||||||
loadMessagesToScrollAreaTop();
|
loadMessagesToScrollAreaTop();
|
||||||
|
|||||||
Reference in New Issue
Block a user