diff --git a/src/pages/home/report/ReportActionsList.js b/src/pages/home/report/ReportActionsList.js index 2c8362268ef8..2009dc9a102d 100644 --- a/src/pages/home/report/ReportActionsList.js +++ b/src/pages/home/report/ReportActionsList.js @@ -159,6 +159,12 @@ function ReportActionsList({ const lastVisibleActionCreatedRef = useRef(report.lastVisibleActionCreated); const lastReadTimeRef = useRef(report.lastReadTime); + const sortedVisibleReportActions = _.filter(sortedReportActions, (s) => isOffline || s.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || s.errors); + const lastActionIndex = lodashGet(sortedVisibleReportActions, [0, 'reportActionID']); + const reportActionSize = useRef(sortedVisibleReportActions.length); + + const previousLastIndex = useRef(lastActionIndex); + const linkedReportActionID = lodashGet(route, 'params.reportActionID', ''); // This state is used to force a re-render when the user manually marks a message as unread @@ -173,6 +179,14 @@ function ReportActionsList({ opacity.value = withTiming(1, {duration: 100}); }, [opacity]); + useEffect(() => { + if (previousLastIndex.current !== lastActionIndex && reportActionSize.current > sortedVisibleReportActions.length) { + reportScrollManager.scrollToBottom(); + } + previousLastIndex.current = lastActionIndex; + reportActionSize.current = sortedVisibleReportActions.length; + }, [lastActionIndex, sortedVisibleReportActions.length, reportScrollManager]); + useEffect(() => { // If the reportID changes, we reset the userActiveSince to null, we need to do it because // the parent component is sending the previous reportID even when the user isn't active