diff --git a/src/libs/Navigation/isReportScreenTopmostCentralPane.ts b/src/libs/Navigation/isReportScreenTopmostCentralPane.ts new file mode 100644 index 000000000000..6cfc13886a56 --- /dev/null +++ b/src/libs/Navigation/isReportScreenTopmostCentralPane.ts @@ -0,0 +1,17 @@ +import SCREENS from '@src/SCREENS'; +import getTopmostCentralPaneRoute from './getTopmostCentralPaneRoute'; +import {navigationRef} from './Navigation'; +import type {RootStackParamList, State} from './types'; + +const isReportScreenTopmostCentralPane = (): boolean => { + const rootState = navigationRef.getRootState() as State; + + if (!rootState) { + return false; + } + + const topmostCentralPaneRoute = getTopmostCentralPaneRoute(rootState); + return topmostCentralPaneRoute?.name === SCREENS.REPORT; +}; + +export default isReportScreenTopmostCentralPane; diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 6364095d81c8..e5bb2d4e608d 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -19,6 +19,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import DateUtils from '@libs/DateUtils'; +import isReportScreenTopmostCentralPane from '@libs/Navigation/isReportScreenTopmostCentralPane'; import isSearchTopmostCentralPane from '@libs/Navigation/isSearchTopmostCentralPane'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; @@ -157,7 +158,7 @@ function ReportActionsList({ const styles = useThemeStyles(); const {translate} = useLocalize(); const {windowHeight} = useWindowDimensions(); - const {isInNarrowPaneModal, shouldUseNarrowLayout} = useResponsiveLayout(); + const {shouldUseNarrowLayout} = useResponsiveLayout(); const {preferredLocale} = useLocalize(); const {isOffline, lastOfflineAt, lastOnlineAt} = useNetworkWithOfflineStatus(); @@ -418,20 +419,17 @@ function ReportActionsList({ InteractionManager.runAfterInteractions(() => { // If a new comment is added and it's from the current user scroll to the bottom otherwise leave the user positioned where // they are now in the list. - if (!isFromCurrentUser) { + if (!isFromCurrentUser || !isReportScreenTopmostCentralPane()) { return; } if (!hasNewestReportActionRef.current) { - if (isInNarrowPaneModal) { - return; - } Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.reportID)); return; } reportScrollManager.scrollToBottom(); }); }, - [isInNarrowPaneModal, reportScrollManager, report.reportID], + [reportScrollManager, report.reportID], ); useEffect(() => { // Why are we doing this, when in the cleanup of the useEffect we are already calling the unsubscribe function?