From f58d560fe14378927207391702db5d1c5ca67fca Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Fri, 13 Dec 2024 15:41:54 +0300 Subject: [PATCH 1/3] added isFocused condition --- src/pages/home/report/ReportActionsList.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 3fcdc35ae300..2c1f4dd57750 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -420,7 +420,7 @@ function ReportActionsList({ if (!isFromCurrentUser) { return; } - if (!hasNewestReportActionRef.current) { + if (!hasNewestReportActionRef.current && isFocused) { if (isInNarrowPaneModal) { return; } @@ -429,7 +429,7 @@ function ReportActionsList({ } InteractionManager.runAfterInteractions(() => reportScrollManager.scrollToBottom()); }, - [isInNarrowPaneModal, reportScrollManager, report.reportID], + [isInNarrowPaneModal, reportScrollManager, report.reportID, isFocused], ); useEffect(() => { // Why are we doing this, when in the cleanup of the useEffect we are already calling the unsubscribe function? From 834f32fa7f67fd6d44c79bb0d673acd56e711b00 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Fri, 13 Dec 2024 17:14:08 +0300 Subject: [PATCH 2/3] changed condition to isReportScreenTopmostCentralPane --- .../isReportScreenTopmostCentralPane.ts | 17 +++++++++++++++++ src/pages/home/report/ReportActionsList.tsx | 10 ++++------ 2 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 src/libs/Navigation/isReportScreenTopmostCentralPane.ts 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 2c1f4dd57750..160a1198602b 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'; @@ -417,19 +418,16 @@ function ReportActionsList({ (isFromCurrentUser: boolean) => { // 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 && isFocused) { - if (isInNarrowPaneModal) { - return; - } + if (!hasNewestReportActionRef.current) { Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.reportID)); return; } InteractionManager.runAfterInteractions(() => reportScrollManager.scrollToBottom()); }, - [isInNarrowPaneModal, reportScrollManager, report.reportID, isFocused], + [reportScrollManager, report.reportID], ); useEffect(() => { // Why are we doing this, when in the cleanup of the useEffect we are already calling the unsubscribe function? From 557ea1985da86f99e55ddc519e0599d4b1762563 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Fri, 13 Dec 2024 17:16:10 +0300 Subject: [PATCH 3/3] minor fix --- src/pages/home/report/ReportActionsList.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 160a1198602b..d8771a9085f8 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -158,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();