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 6 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, shouldOpenContextMenu}) => (
<PressableWithoutFeedback
onPress={onPressIn ?? (() => {})}
onPressIn={onPressIn}
onPressOut={onPressOut}
onLongPress={(event) =>
showContextMenuForReport(event, anchor, report?.reportID ?? '-1', action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(report, reportNameValuePairs))
}
onLongPress={(event) => {
if (!shouldOpenContextMenu) {
return;
}
showContextMenuForReport(event, anchor, report?.reportID ?? '-1', action, checkIfContextMenuActive, ReportUtils.isArchivedRoom(report, reportNameValuePairs));
}}
shouldUseHapticsOnLongPress
role={CONST.ROLE.PRESENTATION}
accessibilityLabel={translate('accessibilityHints.prestyledText')}
Expand Down
55 changes: 35 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,18 @@ function MoneyRequestConfirmationListFooter({
const resolvedThumbnail = isLocalFile ? receiptThumbnail : tryResolveUrlFromApiRoot(receiptThumbnail ?? '');
const resolvedReceiptImage = isLocalFile ? receiptImage : tryResolveUrlFromApiRoot(receiptImage ?? '');

const contextMenuContextValue = useMemo(
() => ({
anchor: null,
report: undefined,
reportNameValuePairs: undefined,
action: undefined,
transactionThreadReport: undefined,
checkIfContextMenuActive: () => {},
}),
[],
);
daledah marked this conversation as resolved.
Show resolved Hide resolved

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 +313,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={contextMenuContextValue}>
<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;
shouldOpenContextMenu?: boolean;
};

const ShowContextMenuContext = createContext<ShowContextMenuContextProps>({
Expand All @@ -25,6 +26,7 @@ const ShowContextMenuContext = createContext<ShowContextMenuContextProps>({
action: undefined,
transactionThreadReport: undefined,
checkIfContextMenuActive: () => {},
shouldOpenContextMenu: false,
});

ShowContextMenuContext.displayName = 'ShowContextMenuContext';
Expand Down
1 change: 1 addition & 0 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ function ReportActionItem({
action,
transactionThreadReport,
checkIfContextMenuActive: toggleContextMenuFromActiveReportAction,
shouldOpenContextMenu: true,
}),
[report, action, toggleContextMenuFromActiveReportAction, transactionThreadReport, reportNameValuePairs],
);
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, shouldOpenContextMenu: 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