-
Notifications
You must be signed in to change notification settings - Fork 45
[CLNP-7468] fix: resolve search item scroll issue #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,9 @@ export const GroupChannelContexts: GroupChannelContextsType = { | |
| lazyScrollToIndex: () => { | ||
| // noop | ||
| }, | ||
| lazyScrollToMessageId: () => { | ||
| // noop | ||
| }, | ||
| } as MessageListContextValue), | ||
| }; | ||
|
|
||
|
|
@@ -68,10 +71,11 @@ export const GroupChannelContextsProvider: GroupChannelModule['Provider'] = ({ | |
| const [messageToEdit, setMessageToEdit] = useState<SendbirdUserMessage | SendbirdFileMessage>(); | ||
| const [messageToReply, setMessageToReply] = useState<SendbirdUserMessage | SendbirdFileMessage>(); | ||
|
|
||
| const { flatListRef, lazyScrollToIndex, lazyScrollToBottom, scrollToMessage } = useScrollActions({ | ||
| messages, | ||
| onUpdateSearchItem, | ||
| }); | ||
| const { flatListRef, lazyScrollToIndex, lazyScrollToBottom, scrollToMessage, lazyScrollToMessageId } = | ||
| useScrollActions({ | ||
| messages, | ||
| onUpdateSearchItem, | ||
| }); | ||
|
|
||
| const updateInputMode = (mode: 'send' | 'edit' | 'reply', message?: SendbirdUserMessage | SendbirdFileMessage) => { | ||
| if (mode === 'send' || !message) { | ||
|
|
@@ -143,6 +147,7 @@ export const GroupChannelContextsProvider: GroupChannelModule['Provider'] = ({ | |
| scrollToMessage, | ||
| lazyScrollToIndex, | ||
| lazyScrollToBottom, | ||
| lazyScrollToMessageId, | ||
| onPressReplyMessageInThread, | ||
| }} | ||
| > | ||
|
|
@@ -159,9 +164,11 @@ type MessageListContextValue = ContextValue<GroupChannelContextsType['MessageLis | |
| const useScrollActions = (params: Pick<GroupChannelProps['Provider'], 'messages' | 'onUpdateSearchItem'>) => { | ||
| const { messages, onUpdateSearchItem } = params; | ||
| const flatListRef = useRef<FlatList<SendbirdMessage>>(null); | ||
| const messagesRef = useRef(messages); | ||
| messagesRef.current = messages; | ||
|
|
||
| // FIXME: Workaround, should run after data has been applied to UI. | ||
| const lazyScrollToBottom = useFreshCallback<MessageListContextValue['lazyScrollToIndex']>((params) => { | ||
| const lazyScrollToBottom = useFreshCallback<MessageListContextValue['lazyScrollToBottom']>((params) => { | ||
| if (!flatListRef.current) { | ||
| logFlatListRefWarning(); | ||
| return; | ||
|
|
@@ -188,6 +195,33 @@ const useScrollActions = (params: Pick<GroupChannelProps['Provider'], 'messages' | |
| }, params?.timeout ?? 0); | ||
| }); | ||
|
|
||
| // FIXME: Workaround, should run after data has been applied to UI. | ||
| const lazyScrollToMessageId = useFreshCallback<MessageListContextValue['lazyScrollToMessageId']>((params) => { | ||
| if (!flatListRef.current) { | ||
| logFlatListRefWarning(); | ||
| return; | ||
| } | ||
|
|
||
| setTimeout(() => { | ||
| let messageIndex = 0; | ||
| if (params?.messageId) { | ||
| const foundMessageIndex = messagesRef.current.findIndex((it) => it.messageId === params.messageId); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이건 첫 데이터 로드에서 찾은 index 는 스크롤로 가는 도중에 load more 등으로 리스트가 업데이트 되면
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네 현재 상태에서는 onBottomReached 가 loadNext를 호출하면서 문제가 발생하고있습니다. 어떤 경우라도 messages 가 변경되었다면 현재 messages 기준으로 인덱스를 다시 찾아야 스크롤 처리해주는게 기대 동작일것 같습니다 |
||
| if (foundMessageIndex > -1) { | ||
| messageIndex = foundMessageIndex; | ||
| } else { | ||
| Logger.warn('Message with messageId not found:', params.messageId); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| flatListRef.current?.scrollToIndex({ | ||
| index: messageIndex, | ||
| animated: params?.animated ?? false, | ||
| viewPosition: params?.viewPosition ?? 0.5, | ||
| }); | ||
| }, params?.timeout ?? 0); | ||
| }); | ||
|
|
||
| const scrollToMessage = useFreshCallback<MessageListContextValue['scrollToMessage']>((messageId, options) => { | ||
| if (!flatListRef.current) { | ||
| logFlatListRefWarning(); | ||
|
|
@@ -221,6 +255,7 @@ const useScrollActions = (params: Pick<GroupChannelProps['Provider'], 'messages' | |
| lazyScrollToIndex, | ||
| lazyScrollToBottom, | ||
| scrollToMessage, | ||
| lazyScrollToMessageId, | ||
| }; | ||
| }; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.