diff --git a/src/pages/home/report/ReportActionsList.js b/src/pages/home/report/ReportActionsList.js index 8d79e7af8dd44..245aa2d413805 100644 --- a/src/pages/home/report/ReportActionsList.js +++ b/src/pages/home/report/ReportActionsList.js @@ -9,6 +9,7 @@ import InvertedFlatList from '@components/InvertedFlatList'; import {withPersonalDetails} from '@components/OnyxProvider'; import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from '@components/withCurrentUserPersonalDetails'; import withWindowDimensions, {windowDimensionsPropTypes} from '@components/withWindowDimensions'; +import useAppFocusEvent from '@hooks/useAppFocusEvent'; import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import useReportScrollManager from '@hooks/useReportScrollManager'; @@ -202,29 +203,30 @@ function ReportActionsList({ prevReportID = report.reportID; }, [report.reportID]); - useEffect(() => { + const readNewestReportAction = () => { if (!userActiveSince.current || report.reportID !== prevReportID) { return; } - - if (ReportUtils.isUnread(report)) { - if (Visibility.isVisible() && scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD) { - Report.readNewestAction(report.reportID); - } else { - readActionSkipped.current = true; - } + if (ReportUtils.isUnread(report) && Visibility.isVisible() && scrollingVerticalOffset.current < MSG_VISIBLE_THRESHOLD) { + Report.readNewestAction(report.reportID); + } else { + readActionSkipped.current = true; } + }; + useEffect(() => { + readNewestReportAction(); if (currentUnreadMarker || lastVisibleActionCreatedRef.current === report.lastVisibleActionCreated) { return; } - cacheUnreadMarkers.delete(report.reportID); lastVisibleActionCreatedRef.current = report.lastVisibleActionCreated; setCurrentUnreadMarker(null); // eslint-disable-next-line react-hooks/exhaustive-deps }, [report.lastVisibleActionCreated, report.reportID]); + useAppFocusEvent(readNewestReportAction); + useEffect(() => { if (!userActiveSince.current || report.reportID !== prevReportID) { return;