@@ -8,7 +8,6 @@ import React, {
88import {
99 FlatListProps ,
1010 FlatList as FlatListType ,
11- Platform ,
1211 ScrollViewProps ,
1312 StyleSheet ,
1413 View ,
@@ -425,19 +424,6 @@ const MessageListWithContext = <
425424 setTimeout ( ( ) => {
426425 initialScrollSet . current = true ;
427426 } , 500 ) ;
428- } else if (
429- // On android, you can't overscroll. So we are going to scroll up just a little
430- // which gives user some offset to scroll down and trigger onStartReached.
431- Platform . OS === 'android' &&
432- ! channel ?. state . isUpToDate &&
433- flatListRef . current
434- ) {
435- flatListRef . current . scrollToOffset ( {
436- offset : 50 ,
437- } ) ;
438- setTimeout ( ( ) => {
439- initialScrollSet . current = true ;
440- } , 500 ) ;
441427 } else if ( ! initialScrollSet . current ) {
442428 initialScrollSet . current = true ;
443429 }
@@ -547,6 +533,19 @@ const MessageListWithContext = <
547533 setScrollToBottomButtonVisible ( true ) ;
548534 }
549535
536+ if (
537+ ! channel ?. state . isUpToDate &&
538+ flatListRef . current &&
539+ messageListLengthBeforeUpdate . current === 0 &&
540+ messageListLengthAfterUpdate < 10
541+ ) {
542+ /**
543+ * Trigger onStartReached on first load, if messages are not enough to fill the screen.
544+ * This is important especially for android, where you can't overscroll.
545+ */
546+ maybeCallOnStartReached ( 10 ) ;
547+ }
548+
550549 /**
551550 * channelLastRead and topMessage are only used for setting initial scroll.
552551 * So lets not set it if `initialScrollToFirstUnreadMessage` prop is false.
@@ -679,7 +678,7 @@ const MessageListWithContext = <
679678 * 2. Ensures that we call `loadMoreRecent`, once per content length
680679 * 3. If the call to `loadMore` is in progress, we wait for it to finish to make sure scroll doesn't jump.
681680 */
682- const maybeCallOnStartReached = ( ) => {
681+ const maybeCallOnStartReached = ( limit ?: number ) => {
683682 // If onStartReached has already been called for given data length, then ignore.
684683 if (
685684 messageList ?. length &&
@@ -708,12 +707,12 @@ const MessageListWithContext = <
708707 // If onEndReached is in progress, better to wait for it to finish for smooth UX
709708 if ( onEndReachedInPromise . current ) {
710709 onEndReachedInPromise . current . finally ( ( ) => {
711- onStartReachedInPromise . current = loadMoreRecent ( )
710+ onStartReachedInPromise . current = loadMoreRecent ( limit )
712711 . then ( callback )
713712 . catch ( onError ) ;
714713 } ) ;
715714 } else {
716- onStartReachedInPromise . current = loadMoreRecent ( )
715+ onStartReachedInPromise . current = loadMoreRecent ( limit )
717716 . then ( callback )
718717 . catch ( onError ) ;
719718 }
0 commit comments