@@ -22,6 +22,7 @@ import useWindowDimensions from '@hooks/useWindowDimensions';
2222import { isSafari } from '@libs/Browser' ;
2323import DateUtils from '@libs/DateUtils' ;
2424import { getChatFSAttributes , parseFSAttributes } from '@libs/Fullstory' ;
25+ import durationHighlightItem from '@libs/Navigation/helpers/getDurationHighlightItem' ;
2526import isReportTopmostSplitNavigator from '@libs/Navigation/helpers/isReportTopmostSplitNavigator' ;
2627import isSearchTopmostFullScreenRoute from '@libs/Navigation/helpers/isSearchTopmostFullScreenRoute' ;
2728import Navigation from '@libs/Navigation/Navigation' ;
@@ -173,6 +174,7 @@ function ReportActionsList({
173174 const isReportArchived = useReportIsArchived ( report ?. reportID ) ;
174175
175176 const [ isScrollToBottomEnabled , setIsScrollToBottomEnabled ] = useState ( false ) ;
177+ const [ actionIdToHighlight , setActionIdToHighlight ] = useState ( '' ) ;
176178
177179 useEffect ( ( ) => {
178180 const unsubscribe = Visibility . onVisibilityChange ( ( ) => {
@@ -409,7 +411,7 @@ function ReportActionsList({
409411 } , [ lastAction , prevSortedVisibleReportActionsObjects , reportScrollManager ] ) ;
410412
411413 const scrollToBottomForCurrentUserAction = useCallback (
412- ( isFromCurrentUser : boolean ) => {
414+ ( isFromCurrentUser : boolean , action ?: OnyxTypes . ReportAction ) => {
413415 InteractionManager . runAfterInteractions ( ( ) => {
414416 // If a new comment is added and it's from the current user scroll to the bottom otherwise leave the user positioned where
415417 // they are now in the list.
@@ -425,14 +427,42 @@ function ReportActionsList({
425427 } ) ;
426428 return ;
427429 }
430+ const index = sortedVisibleReportActions . findIndex ( ( item ) => keyExtractor ( item ) === action ?. reportActionID ) ;
431+ if ( action ?. actionName === CONST . REPORT . ACTIONS . TYPE . REPORT_PREVIEW ) {
432+ if ( index > 0 ) {
433+ setTimeout ( ( ) => {
434+ reportScrollManager . scrollToIndex ( index ) ;
435+ } , 100 ) ;
436+ } else {
437+ setIsFloatingMessageCounterVisible ( false ) ;
438+ reportScrollManager . scrollToBottom ( ) ;
439+ }
440+ if ( action ?. reportActionID ) {
441+ setActionIdToHighlight ( action . reportActionID ) ;
442+ }
443+ } else {
444+ setIsFloatingMessageCounterVisible ( false ) ;
445+ reportScrollManager . scrollToBottom ( ) ;
446+ }
428447
429- setIsFloatingMessageCounterVisible ( false ) ;
430- reportScrollManager . scrollToBottom ( ) ;
431448 setIsScrollToBottomEnabled ( true ) ;
432449 } ) ;
433450 } ,
434- [ report . reportID , reportScrollManager , setIsFloatingMessageCounterVisible ] ,
451+ [ report . reportID , reportScrollManager , setIsFloatingMessageCounterVisible , sortedVisibleReportActions , reportScrollManager ] ,
435452 ) ;
453+
454+ // Clear the highlighted report action after scrolling and highlighting
455+ useEffect ( ( ) => {
456+ if ( actionIdToHighlight === '' ) {
457+ return ;
458+ }
459+ // Time highlight is the same as SearchPage
460+ const timer = setTimeout ( ( ) => {
461+ setActionIdToHighlight ( '' ) ;
462+ } , durationHighlightItem ) ;
463+ return ( ) => clearTimeout ( timer ) ;
464+ } , [ actionIdToHighlight ] ) ;
465+
436466 useEffect ( ( ) => {
437467 // Why are we doing this, when in the cleanup of the useEffect we are already calling the unsubscribe function?
438468 // Answer: On web, when navigating to another report screen, the previous report screen doesn't get unmounted,
@@ -608,6 +638,7 @@ function ReportActionsList({
608638 isFirstVisibleReportAction = { firstVisibleReportActionID === reportAction . reportActionID }
609639 shouldUseThreadDividerLine = { shouldUseThreadDividerLine }
610640 transactions = { Object . values ( transactions ?? { } ) }
641+ shouldHighlight = { actionIdToHighlight === reportAction . reportActionID }
611642 />
612643 ) ;
613644 } ,
@@ -627,6 +658,7 @@ function ReportActionsList({
627658 shouldUseThreadDividerLine ,
628659 firstVisibleReportActionID ,
629660 unreadMarkerReportActionID ,
661+ actionIdToHighlight ,
630662 ] ,
631663 ) ;
632664
0 commit comments