Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix go back from flag comment page to report #30289

Merged
14 changes: 13 additions & 1 deletion src/pages/FlagCommentPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -161,7 +162,18 @@ function FlagCommentPage(props) {
>
{({safeAreaPaddingBottomStyle}) => (
<FullPageNotFoundView shouldShow={!ReportUtils.shouldShowFlagComment(getActionToFlag(), props.report)}>
<HeaderWithBackButton title={props.translate('reportActionContextMenu.flagAsOffensive')} />
<HeaderWithBackButton
title={props.translate('reportActionContextMenu.flagAsOffensive')}
onBackButtonPress={() => {
const topMostReportID = Navigation.getTopmostReportId();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@suneox I can see this is exactly same as ReportDetailsPage. Why not move this to a util? so that we can use it again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add props link shouldAwareTopMostReport default is false into HeaderWithBackButton and move logic

        const topMostReportID = Navigation.getTopmostReportId();
        if (topMostReportID) {
            Navigation.goBack(ROUTES.HOME);
            return;
        }

before onBackButtonPress callback
Change current to

      <PressableWithoutFeedback
        onPress={() => {
            if (isKeyboardShown) {
                Keyboard.dismiss();
            }
            const topMostReportID = Navigation.getTopmostReportId();
            if (shouldAwareTopMostReport && topMostReportID) {
                Navigation.goBack(ROUTES.HOME);
            } else {
                onBackButtonPress();
            }
        }}

Then add props shouldAwareTopMostReport to ReportDetailsPage and FlagCommentPage
@mananjadhav What do you think about this change?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we modify the condition so that topMostReportID is fetched only if shouldAwareTopMostReport is set true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes so the condition look like this if (shouldAwareTopMostReport && Navigation.getTopmostReportId())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the condition and synced it with the latest main

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mananjadhav i have updated condition before get topMostReportID

if (topMostReportID) {
Navigation.goBack(ROUTES.HOME);
return;
}
Navigation.goBack();
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(props.report.reportID));
}}
/>
<ScrollView
contentContainerStyle={safeAreaPaddingBottomStyle}
style={styles.settingsPageBackground}
Expand Down