-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
ShowContextMenuContext.ts
65 lines (59 loc) · 2.06 KB
/
ShowContextMenuContext.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {createContext} from 'react';
// eslint-disable-next-line no-restricted-imports
import type {GestureResponderEvent} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import * as ReportUtils from '@libs/ReportUtils';
import * as ReportActionContextMenu from '@pages/home/report/ContextMenu/ReportActionContextMenu';
import type {ContextMenuAnchor} from '@pages/home/report/ContextMenu/ReportActionContextMenu';
import CONST from '@src/CONST';
import type {Report, ReportAction} from '@src/types/onyx';
type ShowContextMenuContextProps = {
anchor: ContextMenuAnchor;
report: OnyxEntry<Report>;
action: OnyxEntry<ReportAction>;
checkIfContextMenuActive: () => void;
};
const ShowContextMenuContext = createContext<ShowContextMenuContextProps>({
anchor: null,
report: null,
action: null,
checkIfContextMenuActive: () => {},
});
ShowContextMenuContext.displayName = 'ShowContextMenuContext';
/**
* Show the report action context menu.
*
* @param event - Press event object
* @param anchor - Context menu anchor
* @param reportID - Active Report ID
* @param action - ReportAction for ContextMenu
* @param checkIfContextMenuActive Callback to update context menu active state
* @param isArchivedRoom - Is the report an archived room
*/
function showContextMenuForReport(
event: GestureResponderEvent | MouseEvent,
anchor: ContextMenuAnchor,
reportID: string,
action: OnyxEntry<ReportAction>,
checkIfContextMenuActive: () => void,
isArchivedRoom = false,
) {
if (!DeviceCapabilities.canUseTouchScreen()) {
return;
}
ReportActionContextMenu.showContextMenu(
CONST.CONTEXT_MENU_TYPES.REPORT_ACTION,
event,
'',
anchor,
reportID,
action?.reportActionID,
ReportUtils.getOriginalReportID(reportID, action),
undefined,
checkIfContextMenuActive,
checkIfContextMenuActive,
isArchivedRoom,
);
}
export {ShowContextMenuContext, showContextMenuForReport};