@@ -9,6 +9,7 @@ import type {OnyxEntry} from 'react-native-onyx';
99import { renderScrollComponent as renderActionSheetAwareScrollView } from '@components/ActionSheetAwareScrollView' ;
1010import Button from '@components/Button' ;
1111import InvertedFlatList from '@components/FlatList/InvertedFlatList' ;
12+ import { AUTOSCROLL_TO_TOP_THRESHOLD } from '@components/FlatList/hooks/useFlatListScrollKey' ;
1213import { usePersonalDetails } from '@components/OnyxListItemProvider' ;
1314import ReportActionsSkeletonView from '@components/ReportActionsSkeletonView' ;
1415import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails' ;
@@ -236,6 +237,10 @@ function ReportActionsList({
236237
237238 return getSortedReportActions ( [ ...sortedVisibleReportActions , draftReportAction ] , true ) ;
238239 } , [ draftReportAction , sortedVisibleReportActions ] ) ;
240+ const draftMessageHTML = draftReportAction ? getReportActionMessage ( draftReportAction ) ?. html : undefined ;
241+ const isSyntheticDraftVisible = ! ! draftReportAction && ! sortedVisibleReportActions . some ( ( action ) => action . reportActionID === draftReportAction . reportActionID ) ;
242+ const draftAutoScrollKey = isSyntheticDraftVisible ? `${ draftReportAction . reportActionID } :${ draftMessageHTML ?? '' } ` : '' ;
243+ const previousDraftAutoScrollKey = usePrevious ( draftAutoScrollKey ) ;
239244 const topReportAction = renderedVisibleReportActions . at ( - 1 ) ;
240245 const [ shouldScrollToEndAfterLayout , setShouldScrollToEndAfterLayout ] = useState ( shouldFocusToTopOnMount && ! reportActionID ) ;
241246 const isAnonymousUser = useIsAnonymousUser ( ) ;
@@ -400,6 +405,21 @@ function ReportActionsList({
400405 resetKey : linkedReportActionID ,
401406 } ) ;
402407
408+ useEffect ( ( ) => {
409+ if ( ! draftAutoScrollKey || previousDraftAutoScrollKey === draftAutoScrollKey ) {
410+ return ;
411+ }
412+
413+ if ( scrollOffsetRef . current >= AUTOSCROLL_TO_TOP_THRESHOLD || ! hasNewestReportActionRef . current ) {
414+ return ;
415+ }
416+
417+ setIsFloatingMessageCounterVisible ( false ) ;
418+ requestAnimationFrame ( ( ) => {
419+ reportScrollManager . scrollToBottom ( ) ;
420+ } ) ;
421+ } , [ draftAutoScrollKey , previousDraftAutoScrollKey , reportScrollManager , setIsFloatingMessageCounterVisible ] ) ;
422+
403423 useEffect ( ( ) => {
404424 const shouldTriggerScroll = shouldFocusToTopOnMount && prevHasCreatedActionAdded && ! hasCreatedActionAdded ;
405425 if ( ! shouldTriggerScroll ) {
@@ -789,7 +809,6 @@ function ReportActionsList({
789809
790810 // Native mobile does not render updates flatlist the changes even though component did update called.
791811 // To notify there something changes we can use extraData prop to flatlist
792- const draftMessageHTML = draftReportAction ? getReportActionMessage ( draftReportAction ) ?. html : undefined ;
793812 const extraData = useMemo (
794813 ( ) => [ shouldUseNarrowLayout ? unreadMarkerReportActionID : undefined , isArchivedNonExpenseReport ( report , isReportArchived ) , draftReportAction ?. reportActionID , draftMessageHTML ] ,
795814 [ draftMessageHTML , draftReportAction ?. reportActionID , unreadMarkerReportActionID , shouldUseNarrowLayout , report , isReportArchived ] ,
0 commit comments