2
2
import type { RefObject } from 'react' ;
3
3
import React , { useCallback , useEffect , useMemo , useRef } from 'react' ;
4
4
import {
5
- ComputeItemKey ,
6
5
FollowOutputScalarType ,
7
6
ScrollSeekConfiguration ,
8
7
ScrollSeekPlaceholderProps ,
@@ -38,7 +37,6 @@ import { MessageProps, MessageSimple, MessageUIComponentProps } from '../Message
38
37
import { UnreadMessagesNotification as DefaultUnreadMessagesNotification } from './UnreadMessagesNotification' ;
39
38
import {
40
39
calculateFirstItemIndex ,
41
- calculateItemIndex ,
42
40
EmptyPlaceholder ,
43
41
Header ,
44
42
Item ,
@@ -167,10 +165,6 @@ function useCaptureResizeObserverExceededError() {
167
165
} , [ ] ) ;
168
166
}
169
167
170
- function fractionalItemSize ( element : HTMLElement ) {
171
- return element . getBoundingClientRect ( ) . height ;
172
- }
173
-
174
168
function findMessageIndex ( messages : Array < { id : string } > , id : string ) {
175
169
return messages . findIndex ( ( message ) => message . id === id ) ;
176
170
}
@@ -221,8 +215,6 @@ const VirtualizedMessageListWithContext = <
221
215
messages,
222
216
notifications,
223
217
openThread,
224
- // TODO: refactor to scrollSeekPlaceHolderConfiguration and components.ScrollSeekPlaceholder, like the Virtuoso Component
225
- overscan = 0 ,
226
218
reactionDetailsSort,
227
219
read,
228
220
returnAllReadData = false ,
@@ -234,7 +226,7 @@ const VirtualizedMessageListWithContext = <
234
226
showUnreadNotificationAlways,
235
227
sortReactionDetails,
236
228
sortReactions,
237
- stickToBottomScrollBehavior = 'auto ' ,
229
+ stickToBottomScrollBehavior = 'smooth ' ,
238
230
suppressAutoscroll,
239
231
threadList,
240
232
} = props ;
@@ -438,14 +430,6 @@ const VirtualizedMessageListWithContext = <
438
430
return isAtBottom ? stickToBottomScrollBehavior : false ;
439
431
} ;
440
432
441
- const computeItemKey = useCallback <
442
- ComputeItemKey < UnknownType , VirtuosoContext < StreamChatGenerics > >
443
- > (
444
- ( index , _ , { numItemsPrepended, processedMessages } ) =>
445
- processedMessages [ calculateItemIndex ( index , numItemsPrepended ) ] . id ,
446
- [ ] ,
447
- ) ;
448
-
449
433
atBottomRef . current = ( isAtBottom ) => {
450
434
atBottom . current = isAtBottom ;
451
435
setIsMessageListScrolledToBottom ( isAtBottom ) ;
@@ -479,34 +463,34 @@ const VirtualizedMessageListWithContext = <
479
463
} , [ highlightedMessageId , processedMessages ] ) ;
480
464
481
465
// force autoscrollToBottom if user hasn't interracted yet
482
- useEffect ( ( ) => {
483
- /**
484
- * a combination of parameters paired with extra data load on Virtuoso render causes
485
- * a message list to render a set of items not at the bottom of the list as expected
486
- * but rather either in the middle or a few hundredth pixels from the bottom
487
- *
488
- * `atTopStateChange` - if at top, load previous page, changing this to `startReached` reduces the amount of errors as it is not
489
- * being triggered at Virtuoso render but does not solve the core issue
490
- * `followOutput` - function which returns "smooth" value which is somehow more error-prone for Firefox and Safari
491
- */
466
+ // useEffect(() => {
467
+ /**
468
+ * a combination of parameters paired with extra data load on Virtuoso render causes
469
+ * a message list to render a set of items not at the bottom of the list as expected
470
+ * but rather either in the middle or a few hundredth pixels from the bottom
471
+ *
472
+ * `atTopStateChange` - if at top, load previous page, changing this to `startReached` reduces the amount of errors as it is not
473
+ * being triggered at Virtuoso render but does not solve the core issue
474
+ * `followOutput` - function which returns "smooth" value which is somehow more error-prone for Firefox and Safari
475
+ */
492
476
493
- if (
494
- highlightedMessageId ||
495
- userInterractedWithScrollableViewRef . current ||
496
- atBottom . current
497
- ) {
498
- return ;
499
- }
477
+ // if (
478
+ // highlightedMessageId ||
479
+ // userInterractedWithScrollableViewRef.current ||
480
+ // atBottom.current
481
+ // ) {
482
+ // return;
483
+ // }
500
484
501
- const timeout = setTimeout ( ( ) => {
502
- userInterractedWithScrollableViewRef . current = true ;
503
- virtuoso . current ?. autoscrollToBottom ( ) ;
504
- } , 0 ) ;
485
+ // const timeout = setTimeout(() => {
486
+ // userInterractedWithScrollableViewRef.current = true;
487
+ // virtuoso.current?.autoscrollToBottom();
488
+ // }, 0);
505
489
506
- return ( ) => {
507
- clearTimeout ( timeout ) ;
508
- } ;
509
- } , [ atBottom , highlightedMessageId , processedMessages ] ) ;
490
+ // return () => {
491
+ // clearTimeout(timeout);
492
+ // };
493
+ // }, [atBottom, highlightedMessageId, processedMessages]);
510
494
511
495
if ( ! processedMessages ) return null ;
512
496
@@ -535,7 +519,6 @@ const VirtualizedMessageListWithContext = <
535
519
< Virtuoso < UnknownType , VirtuosoContext < StreamChatGenerics > >
536
520
atBottomStateChange = { atBottomStateChange }
537
521
atBottomThreshold = { 100 }
538
- // atTopStateChange={atTopStateChange}
539
522
startReached = { atTopStateChange }
540
523
className = 'str-chat__message-list-scroll'
541
524
components = { {
@@ -544,7 +527,6 @@ const VirtualizedMessageListWithContext = <
544
527
Item,
545
528
...virtuosoComponentsFromProps ,
546
529
} }
547
- computeItemKey = { computeItemKey }
548
530
context = { {
549
531
additionalMessageInputProps,
550
532
closeReactionSelectorOnClick,
@@ -584,7 +566,6 @@ const VirtualizedMessageListWithContext = <
584
566
highlightedMessageId ,
585
567
) }
586
568
itemContent = { messageRenderer }
587
- itemSize = { fractionalItemSize }
588
569
itemsRendered = { handleItemsRendered }
589
570
key = { messageSetKey }
590
571
onTouchMove = { ( ) => {
@@ -593,10 +574,9 @@ const VirtualizedMessageListWithContext = <
593
574
onWheel = { ( ) => {
594
575
userInterractedWithScrollableViewRef . current = true ;
595
576
} }
596
- overscan = { overscan }
597
577
ref = { virtuoso }
598
578
style = { { overflowX : 'hidden' , overscrollBehavior : 'none' } }
599
- totalCount = { processedMessages . length }
579
+ data = { processedMessages }
600
580
{ ...extra }
601
581
/>
602
582
</ div >
0 commit comments