@@ -351,6 +351,11 @@ const MessageListWithContext = <
351351 */
352352 const initialScrollSettingTimeoutRef = useRef < ReturnType < typeof setTimeout > > ( ) ;
353353
354+ /**
355+ * The timeout id used to temporarily load the initial scroll set flag
356+ */
357+ const onScrollEventTimeoutRef = useRef < ReturnType < typeof setTimeout > > ( ) ;
358+
354359 /**
355360 * Last messageID that was scrolled to after loading a new message list,
356361 * this flag keeps track of it so that we dont scroll to it again on target message set
@@ -774,6 +779,29 @@ const MessageListWithContext = <
774779 . catch ( onError ) ;
775780 } ;
776781
782+ const onUserScrollEvent : NonNullable < ScrollViewProps [ 'onScroll' ] > = ( event ) => {
783+ const nativeEvent = event . nativeEvent ;
784+ clearTimeout ( onScrollEventTimeoutRef . current ) ;
785+ const offset = nativeEvent . contentOffset . y ;
786+ const visibleLength = nativeEvent . layoutMeasurement . height ;
787+ const contentLength = nativeEvent . contentSize . height ;
788+ if ( ! channel || ! channelResyncScrollSet . current ) {
789+ return ;
790+ }
791+
792+ // Check if scroll has reached either start of end of list.
793+ const isScrollAtStart = offset < 100 ;
794+ const isScrollAtEnd = contentLength - visibleLength - offset < 100 ;
795+
796+ if ( isScrollAtStart ) {
797+ maybeCallOnStartReached ( ) ;
798+ }
799+
800+ if ( isScrollAtEnd ) {
801+ maybeCallOnEndReached ( ) ;
802+ }
803+ } ;
804+
777805 const handleScroll : ScrollViewProps [ 'onScroll' ] = ( event ) => {
778806 const offset = event . nativeEvent . contentOffset . y ;
779807 const messageListHasMessages = processedMessageList . length > 0 ;
@@ -810,8 +838,8 @@ const MessageListWithContext = <
810838 const isNotLatestSet = channel . state . messages !== channel . state . latestMessages ;
811839
812840 if ( isNotLatestSet ) {
813- await reloadChannel ( ) ;
814841 resetPaginationTrackersRef . current ( ) ;
842+ await reloadChannel ( ) ;
815843 } else if ( flatListRef . current ) {
816844 flatListRef . current . scrollToOffset ( {
817845 offset : 0 ,
@@ -1001,12 +1029,14 @@ const MessageListWithContext = <
10011029 }
10021030 } ;
10031031
1004- const onScrollBeginDrag : ScrollViewProps [ 'onScrollBeginDrag' ] = ( ) => {
1032+ const onScrollBeginDrag : ScrollViewProps [ 'onScrollBeginDrag' ] = ( event ) => {
10051033 ! hasMoved && selectedPicker && setHasMoved ( true ) ;
1034+ onUserScrollEvent ( event ) ;
10061035 } ;
10071036
1008- const onScrollEndDrag : ScrollViewProps [ 'onScrollEndDrag' ] = ( ) => {
1037+ const onScrollEndDrag : ScrollViewProps [ 'onScrollEndDrag' ] = ( event ) => {
10091038 hasMoved && selectedPicker && setHasMoved ( false ) ;
1039+ onUserScrollEvent ( event ) ;
10101040 } ;
10111041
10121042 const refCallback = ( ref : FlatListType < MessageType < StreamChatGenerics > > ) => {
@@ -1119,12 +1149,11 @@ const MessageListWithContext = <
11191149 minIndexForVisible : 1 ,
11201150 } }
11211151 maxToRenderPerBatch = { 30 }
1122- onEndReached = { maybeCallOnEndReached }
1152+ onMomentumScrollEnd = { onUserScrollEvent }
11231153 onScroll = { handleScroll }
11241154 onScrollBeginDrag = { onScrollBeginDrag }
11251155 onScrollEndDrag = { onScrollEndDrag }
11261156 onScrollToIndexFailed = { onScrollToIndexFailedRef . current }
1127- onStartReached = { maybeCallOnStartReached }
11281157 onTouchEnd = { dismissImagePicker }
11291158 onViewableItemsChanged = { onViewableItemsChanged . current }
11301159 ref = { refCallback }
0 commit comments