diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index c7d8195b8803..8d078389e0b0 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1838,8 +1838,9 @@ function getCurrentUserAccountID() { * Leave a report by setting the state to submitted and closed * * @param {String} reportID + * @param {Boolean} shouldNavigate should navigate after leaving room or not */ -function leaveRoom(reportID) { +function leaveRoom(reportID, shouldNavigate = true) { const report = lodashGet(allReports, [reportID], {}); const reportKeys = _.keys(report); @@ -1886,6 +1887,9 @@ function leaveRoom(reportID) { }, ); Navigation.dismissModal(); + if (!shouldNavigate) { + return; + } if (Navigation.getTopmostReportId() === reportID) { Navigation.goBack(ROUTES.HOME); } diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 15bf25695fd3..7f62cdf333d1 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -1,6 +1,6 @@ import React, {useRef, useState, useEffect, useMemo, useCallback} from 'react'; import {withOnyx} from 'react-native-onyx'; -import {useFocusEffect} from '@react-navigation/native'; +import {useFocusEffect, useIsFocused} from '@react-navigation/native'; import PropTypes from 'prop-types'; import {View} from 'react-native'; import lodashGet from 'lodash/get'; @@ -153,6 +153,7 @@ function ReportScreen({ const reactionListRef = useRef(); const prevReport = usePrevious(report); const prevUserLeavingStatus = usePrevious(userLeavingStatus); + const isFocused = useIsFocused(); const [skeletonViewContainerHeight, setSkeletonViewContainerHeight] = useState(0); const [isBannerVisible, setIsBannerVisible] = useState(true); @@ -180,6 +181,8 @@ function ReportScreen({ const didSubscribeToReportLeavingEvents = useRef(false); const isDefaultReport = checkDefaultReport(report); + const isThread = ReportUtils.isThread(report); + const isNotificationPreferenceHidden = report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; let headerView = ( { + if (isFocused || !isThread || !isNotificationPreferenceHidden) { + return; + } + Report.leaveRoom(reportID, false); + }, [isFocused, isThread, isNotificationPreferenceHidden, reportID]); + return (