forked from BlueWallet/BlueWallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TooltipMenu.ios.js
102 lines (98 loc) · 3.09 KB
/
TooltipMenu.ios.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import React, { forwardRef } from 'react';
import { ContextMenuView, ContextMenuButton } from 'react-native-ios-context-menu';
import PropTypes from 'prop-types';
import QRCodeComponent from './QRCodeComponent';
import { TouchableOpacity } from 'react-native';
const ToolTipMenu = (props, ref) => {
const menuItemMapped = ({ action, menuOptions }) => {
const item = {
actionKey: action.id,
actionTitle: action.text,
icon: action.icon,
menuOptions,
menuTitle: action.menuTitle,
};
item.menuState = action.menuStateOn ? 'on' : 'off';
if (action.disabled) {
item.menuAttributes = ['disabled'];
}
return item;
};
const menuItems = props.actions.map(action => {
if (Array.isArray(action)) {
const mapped = [];
for (const actionToMap of action) {
mapped.push(menuItemMapped({ action: actionToMap }));
}
const submenu = {
menuOptions: ['displayInline'],
menuItems: mapped,
menuTitle: '',
};
return submenu;
} else {
return menuItemMapped({ action });
}
});
const menuTitle = props.title ?? '';
const isButton = !!props.isButton;
const isMenuPrimaryAction = props.isMenuPrimaryAction ? props.isMenuPrimaryAction : false;
const previewQRCode = props.previewQRCode ?? false;
const previewValue = props.previewValue;
const disabled = props.disabled ?? false;
// eslint-disable-next-line react/prop-types
const buttonStyle = props.buttonStyle;
return isButton ? (
<ContextMenuButton
ref={ref}
disabled={disabled}
onPressMenuItem={({ nativeEvent }) => {
props.onPressMenuItem(nativeEvent.actionKey);
}}
isMenuPrimaryAction={isMenuPrimaryAction}
menuConfig={{
menuTitle,
menuItems,
}}
style={buttonStyle}
>
{props.onPress ? <TouchableOpacity accessibilityRole="button" onPress={props.onPress}>{props.children}</TouchableOpacity> : props.children}
</ContextMenuButton>
) : (
<ContextMenuView
ref={ref}
internalCleanupMode="viewController"
onPressMenuItem={({ nativeEvent }) => {
props.onPressMenuItem(nativeEvent.actionKey);
}}
menuConfig={{
menuTitle,
menuItems,
}}
{...(previewQRCode
? {
previewConfig: {
previewType: 'CUSTOM',
backgroundColor: 'white',
},
renderPreview: () => <QRCodeComponent value={previewValue} isMenuAvailable={false} />,
}
: {})}
>
{props.onPress ? <TouchableOpacity accessibilityRole="button" onPress={props.onPress}>{props.children}</TouchableOpacity> : props.children}
</ContextMenuView>
);
};
export default forwardRef(ToolTipMenu);
ToolTipMenu.propTypes = {
actions: PropTypes.object.isRequired,
title: PropTypes.string,
children: PropTypes.node.isRequired,
onPressMenuItem: PropTypes.func.isRequired,
isMenuPrimaryAction: PropTypes.bool,
isButton: PropTypes.bool,
previewQRCode: PropTypes.bool,
onPress: PropTypes.func,
previewValue: PropTypes.string,
disabled: PropTypes.bool,
};