diff --git a/src/components/HeaderWithBackButton/headerWithBackButtonPropTypes.js b/src/components/HeaderWithBackButton/headerWithBackButtonPropTypes.js index 1ad1f0961e38..109e60adf672 100644 --- a/src/components/HeaderWithBackButton/headerWithBackButtonPropTypes.js +++ b/src/components/HeaderWithBackButton/headerWithBackButtonPropTypes.js @@ -93,6 +93,9 @@ const propTypes = { /** Single execution function to prevent concurrent navigation actions */ singleExecution: PropTypes.func, + + /** Whether we should navigate to report page when the route have a topMostReport */ + shouldNavigateToTopMostReport: PropTypes.bool, }; export default propTypes; diff --git a/src/components/HeaderWithBackButton/index.js b/src/components/HeaderWithBackButton/index.js index edb3b8d26831..051e18ed675e 100755 --- a/src/components/HeaderWithBackButton/index.js +++ b/src/components/HeaderWithBackButton/index.js @@ -53,6 +53,7 @@ function HeaderWithBackButton({ children = null, shouldOverlay = false, singleExecution = (func) => func, + shouldNavigateToTopMostReport = false, }) { const styles = useThemeStyles(); const [isDownloadButtonActive, temporarilyDisableDownloadButton] = useThrottledButtonState(); @@ -74,7 +75,12 @@ function HeaderWithBackButton({ if (isKeyboardShown) { Keyboard.dismiss(); } - onBackButtonPress(); + const topmostReportId = Navigation.getTopmostReportId(); + if (shouldNavigateToTopMostReport && topmostReportId) { + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(topmostReportId)); + } else { + onBackButtonPress(); + } }} style={[styles.touchableButtonImage]} role="button" diff --git a/src/pages/FlagCommentPage.js b/src/pages/FlagCommentPage.js index 721bc6742c4b..3695896ea473 100644 --- a/src/pages/FlagCommentPage.js +++ b/src/pages/FlagCommentPage.js @@ -19,6 +19,7 @@ import * as Report from '@userActions/Report'; import * as Session from '@userActions/Session'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import ROUTES from '@src/ROUTES'; import reportActionPropTypes from './home/report/reportActionPropTypes'; import withReportAndReportActionOrNotFound from './home/report/withReportAndReportActionOrNotFound'; import reportPropTypes from './reportPropTypes'; @@ -161,7 +162,14 @@ function FlagCommentPage(props) { > {({safeAreaPaddingBottomStyle}) => ( - + { + Navigation.goBack(); + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(props.report.reportID)); + }} + /> { - const topMostReportID = Navigation.getTopmostReportId(); - if (topMostReportID) { - Navigation.goBack(ROUTES.HOME); - return; - } Navigation.goBack(); Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(props.report.reportID)); }}