Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/ui/TypingIndicatorBubble/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useLayoutEffect } from 'react';
import React, { useLayoutEffect, useRef } from 'react';
import { Member } from '@sendbird/chat/groupChannel';
import Avatar from '../Avatar';
import TypingDots from './TypingDots';
Expand Down Expand Up @@ -82,11 +82,21 @@ const TypingIndicatorBubbleAvatar = (props: TypingIndicatorBubbleProps) => {

const TypingIndicatorBubble = (props: TypingIndicatorBubbleProps) => {
const { typingMembers, handleScroll } = props;
const didMountRef = useRef(false);

useLayoutEffect(() => {
// Keep the scrollBottom value after fetching new message list
handleScroll?.(true);
}, []);
// Also adjust scroll when typing indicator appears (0 -> 1+)
const shouldAdjustScroll = !didMountRef.current || typingMembers.length > 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (typingMembers.length === 0) return null; 로 length가 0일때는 useLayoutEffect 호출이 안되고 typingMembers.length > 0 이상일경우 마운트 이후 첫 호출이 될거라 didMountRef 는 제외 해도 될것 같습니다

didMountRef.current = true;
if (!shouldAdjustScroll) return;
const rafId = requestAnimationFrame(() => {
handleScroll?.(true);
});
return () => {
cancelAnimationFrame(rafId);
};
}, [handleScroll, typingMembers.length]);

if (typingMembers.length === 0) return null;

Expand Down