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: prevent open context menu on money request #48375

Merged
merged 8 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/components/HTMLEngineProvider/HTMLRenderers/PreRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ function PreRenderer({TDefaultRenderer, onPressIn, onPressOut, onLongPress, ...d
return (
<View style={isLast ? styles.mt2 : styles.mv2}>
<ShowContextMenuContext.Consumer>
{({anchor, report, reportNameValuePairs, action, checkIfContextMenuActive}) => (
{({anchor, report, reportNameValuePairs, action, checkIfContextMenuActive, canOpenContextMenu}) => (
<PressableWithoutFeedback
onPress={onPressIn ?? (() => {})}
onPressIn={onPressIn}
onPressOut={onPressOut}
onLongPress={(event) =>
showContextMenuForReport(event, anchor, report?.reportID ?? '-1', action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(report, reportNameValuePairs))
}
onLongPress={(event) => {
if (!canOpenContextMenu) {
return;
}
showContextMenuForReport(event, anchor, report?.reportID ?? '-1', action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(report, reportNameValuePairs));
}}
shouldUseHapticsOnLongPress
role={CONST.ROLE.PRESENTATION}
accessibilityLabel={translate('accessibilityHints.prestyledText')}
Expand Down
56 changes: 36 additions & 20 deletions src/components/MoneyRequestConfirmationListFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import PDFThumbnail from './PDFThumbnail';
import PressableWithoutFocus from './Pressable/PressableWithoutFocus';
import ReceiptEmptyState from './ReceiptEmptyState';
import ReceiptImage from './ReceiptImage';
import {ShowContextMenuContext} from './ShowContextMenuContext';
import ShowMoreButton from './ShowMoreButton';

type MoneyRequestConfirmationListFooterProps = {
Expand Down Expand Up @@ -268,6 +269,19 @@ function MoneyRequestConfirmationListFooter({
const resolvedThumbnail = isLocalFile ? receiptThumbnail : tryResolveUrlFromApiRoot(receiptThumbnail ?? '');
const resolvedReceiptImage = isLocalFile ? receiptImage : tryResolveUrlFromApiRoot(receiptImage ?? '');

const contextValue = useMemo(
() => ({
anchor: null,
report: undefined,
reportNameValuePairs: undefined,
action: undefined,
transactionThreadReport: undefined,
checkIfContextMenuActive: () => {},
canOpenContextMenu: false,
}),
[],
);

const mentionReportContextValue = useMemo(() => ({currentReportID: reportID}), [reportID]);

// An intermediate structure that helps us classify the fields as "primary" and "supplementary".
Expand Down Expand Up @@ -300,26 +314,28 @@ function MoneyRequestConfirmationListFooter({
},
{
item: (
<MentionReportContext.Provider value={mentionReportContextValue}>
<MenuItemWithTopDescription
key={translate('common.description')}
shouldShowRightIcon={!isReadOnly}
shouldParseTitle
excludedMarkdownRules={!policy ? ['reportMentions'] : []}
title={iouComment}
description={translate('common.description')}
onPress={() => {
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_DESCRIPTION.getRoute(action, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams(), reportActionID),
);
}}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
disabled={didConfirm}
interactive={!isReadOnly}
numberOfLinesTitle={2}
/>
</MentionReportContext.Provider>
<ShowContextMenuContext.Provider value={contextValue}>
<MentionReportContext.Provider value={mentionReportContextValue}>
<MenuItemWithTopDescription
key={translate('common.description')}
shouldShowRightIcon={!isReadOnly}
shouldParseTitle
excludedMarkdownRules={!policy ? ['reportMentions'] : []}
title={iouComment}
description={translate('common.description')}
onPress={() => {
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_DESCRIPTION.getRoute(action, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams(), reportActionID),
);
}}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
disabled={didConfirm}
interactive={!isReadOnly}
numberOfLinesTitle={2}
/>
</MentionReportContext.Provider>
</ShowContextMenuContext.Provider>
),
shouldShow: true,
isSupplementary: false,
Expand Down
2 changes: 2 additions & 0 deletions src/components/ShowContextMenuContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type ShowContextMenuContextProps = {
action: OnyxEntry<ReportAction>;
transactionThreadReport?: OnyxEntry<Report>;
checkIfContextMenuActive: () => void;
canOpenContextMenu?: boolean;
};

const ShowContextMenuContext = createContext<ShowContextMenuContextProps>({
Expand All @@ -25,6 +26,7 @@ const ShowContextMenuContext = createContext<ShowContextMenuContextProps>({
action: undefined,
transactionThreadReport: undefined,
checkIfContextMenuActive: () => {},
canOpenContextMenu: true,
daledah marked this conversation as resolved.
Show resolved Hide resolved
});

ShowContextMenuContext.displayName = 'ShowContextMenuContext';
Expand Down
1 change: 1 addition & 0 deletions src/pages/TransactionDuplicate/Confirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function Confirmation() {
checkIfContextMenuActive: () => {},
reportNameValuePairs: undefined,
anchor: null,
canOpenContextMenu: false,
}),
[report, reportAction],
);
Expand Down
6 changes: 4 additions & 2 deletions src/pages/home/report/ReportActionItemContentCreated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ function ReportActionItemContentCreated({contextValue, parentReportAction, trans
[shouldHideThreadDividerLine, report.reportID, styles.reportHorizontalRule],
);

const contextMenuValue = useMemo(() => ({...contextValue, canOpenContextMenu: false}), [contextValue]);

if (ReportActionsUtils.isTransactionThread(parentReportAction)) {
const isReversedTransaction = ReportActionsUtils.isReversedTransaction(parentReportAction);

Expand Down Expand Up @@ -104,7 +106,7 @@ function ReportActionItemContentCreated({contextValue, parentReportAction, trans
}

return (
<ShowContextMenuContext.Provider value={contextValue}>
<ShowContextMenuContext.Provider value={contextMenuValue}>
<View>
<MoneyRequestView
report={report}
Expand Down Expand Up @@ -158,7 +160,7 @@ function ReportActionItemContentCreated({contextValue, parentReportAction, trans
shouldShowTotal={transaction ? transactionCurrency !== report.currency : false}
shouldHideThreadDividerLine={shouldHideThreadDividerLine}
/>
<ShowContextMenuContext.Provider value={contextValue}>
<ShowContextMenuContext.Provider value={contextMenuValue}>
<View>
<MoneyRequestView
report={transactionThreadReport}
Expand Down
Loading