1
- import React , { useContext , useEffect , useLayoutEffect } from 'react' ;
1
+ import React , { useContext , useEffect , useLayoutEffect , useRef } from 'react' ;
2
2
3
3
import { useChannelHandler } from '@sendbird/uikit-chat-hooks' ;
4
4
import { isDifferentChannel , useFreshCallback , useUniqHandlerId } from '@sendbird/uikit-utils' ;
@@ -15,6 +15,19 @@ const GroupChannelThreadMessageList = (props: GroupChannelThreadProps['MessageLi
15
15
const { flatListRef, lazyScrollToBottom, lazyScrollToIndex } = useContext ( GroupChannelThreadContexts . MessageList ) ;
16
16
17
17
const id = useUniqHandlerId ( 'GroupChannelThreadMessageList' ) ;
18
+ const ignorePropReached = useRef ( false ) ;
19
+
20
+ const _onTopReached = ( ) => {
21
+ if ( ! ignorePropReached . current ) {
22
+ props . onTopReached ( ) ;
23
+ }
24
+ } ;
25
+
26
+ const _onBottomReached = ( ) => {
27
+ if ( ! ignorePropReached . current ) {
28
+ props . onBottomReached ( ) ;
29
+ }
30
+ } ;
18
31
19
32
const scrollToBottom = useFreshCallback ( async ( animated = false ) => {
20
33
if ( props . hasNext ( ) ) {
@@ -33,7 +46,12 @@ const GroupChannelThreadMessageList = (props: GroupChannelThreadProps['MessageLi
33
46
const foundMessageIndex = props . messages . findIndex ( ( it ) => it . createdAt === props . startingPoint ) ;
34
47
const isIncludedInList = foundMessageIndex > - 1 ;
35
48
if ( isIncludedInList ) {
36
- lazyScrollToIndex ( { index : foundMessageIndex , animated : true , timeout : 500 } ) ;
49
+ ignorePropReached . current = true ;
50
+ const timeout = 300 ;
51
+ lazyScrollToIndex ( { index : foundMessageIndex , animated : true , timeout : timeout } ) ;
52
+ setTimeout ( ( ) => {
53
+ ignorePropReached . current = false ;
54
+ } , timeout + 50 ) ;
37
55
}
38
56
}
39
57
} , [ props . startingPoint ] ) ;
@@ -73,6 +91,8 @@ const GroupChannelThreadMessageList = (props: GroupChannelThreadProps['MessageLi
73
91
< ChannelThreadMessageList
74
92
{ ...props }
75
93
ref = { flatListRef }
94
+ onTopReached = { _onTopReached }
95
+ onBottomReached = { _onBottomReached }
76
96
onEditMessage = { setMessageToEdit }
77
97
onPressNewMessagesButton = { scrollToBottom }
78
98
onPressScrollToBottomButton = { scrollToBottom }
0 commit comments