@react-native-menu/menu 1.1.6 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -1
- package/android/src/main/java/com/reactnativemenu/MenuView.kt +4 -0
- package/android/src/main/java/com/reactnativemenu/MenuViewManagerBase.kt +11 -0
- package/ios/NewArch/FabricViewImplementationProtocol.swift +3 -0
- package/ios/NewArch/MenuView.mm +20 -0
- package/ios/Shared/ActionSheetView.swift +2 -2
- package/ios/Shared/MenuViewImplementation.swift +3 -3
- package/lib/commonjs/NativeModuleSpecs/UIMenuNativeComponent.js +1 -1
- package/lib/commonjs/NativeModuleSpecs/UIMenuNativeComponent.js.map +1 -1
- package/lib/commonjs/UIMenuView.android.js +19 -1
- package/lib/commonjs/UIMenuView.android.js.map +1 -1
- package/lib/commonjs/UIMenuView.js +0 -3
- package/lib/commonjs/UIMenuView.js.map +1 -1
- package/lib/commonjs/index.js +6 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils.js +1 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/module/NativeModuleSpecs/UIMenuNativeComponent.js +2 -2
- package/lib/module/NativeModuleSpecs/UIMenuNativeComponent.js.map +1 -1
- package/lib/module/UIMenuView.android.js +20 -2
- package/lib/module/UIMenuView.android.js.map +1 -1
- package/lib/module/UIMenuView.ios.js +1 -1
- package/lib/module/UIMenuView.js +1 -2
- package/lib/module/UIMenuView.js.map +1 -1
- package/lib/module/index.js +9 -8
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils.js +1 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/typescript/src/NativeModuleSpecs/UIMenuNativeComponent.d.ts +10 -2
- package/lib/typescript/src/NativeModuleSpecs/UIMenuNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/UIMenuView.android.d.ts +2 -3
- package/lib/typescript/src/UIMenuView.android.d.ts.map +1 -1
- package/lib/typescript/src/UIMenuView.d.ts +2 -2
- package/lib/typescript/src/UIMenuView.d.ts.map +1 -1
- package/lib/typescript/src/UIMenuView.ios.d.ts +1 -1
- package/lib/typescript/src/index.d.ts +20 -4
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +10 -6
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts +1 -1
- package/lib/typescript/src/utils.d.ts.map +1 -1
- package/package.json +10 -44
- package/src/NativeModuleSpecs/UIMenuNativeComponent.ts +45 -37
- package/src/UIMenuView.android.tsx +34 -4
- package/src/UIMenuView.ios.tsx +1 -1
- package/src/UIMenuView.tsx +11 -11
- package/src/index.tsx +32 -26
- package/src/types.ts +158 -153
- package/src/utils.ts +17 -17
package/src/types.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from
|
|
7
|
-
import type * as React from
|
|
2
|
+
ColorValue,
|
|
3
|
+
processColor,
|
|
4
|
+
StyleProp,
|
|
5
|
+
ViewStyle,
|
|
6
|
+
} from "react-native";
|
|
7
|
+
import type * as React from "react";
|
|
8
8
|
|
|
9
9
|
export type NativeActionEvent = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
nativeEvent: {
|
|
11
|
+
event: string;
|
|
12
|
+
};
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
type MenuAttributes = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
/**
|
|
17
|
+
* An attribute indicating the destructive style.
|
|
18
|
+
*/
|
|
19
|
+
destructive?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* An attribute indicating the disabled style.
|
|
22
|
+
*/
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* An attribute indicating the hidden style.
|
|
26
|
+
*/
|
|
27
|
+
hidden?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* (iOS16+ only)
|
|
30
|
+
* @platform iOS
|
|
31
|
+
* An attribute indicating that the menu should remain presented after firing.
|
|
32
|
+
*/
|
|
33
|
+
keepsMenuPresented?: boolean;
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
/**
|
|
@@ -39,145 +39,150 @@ type MenuAttributes = {
|
|
|
39
39
|
* - on: A constant indicating the menu element is in the “on” state.
|
|
40
40
|
* - mixed: A constant indicating the menu element is in the “mixed” state.
|
|
41
41
|
*/
|
|
42
|
-
type MenuState =
|
|
42
|
+
type MenuState = "off" | "on" | "mixed";
|
|
43
43
|
|
|
44
44
|
export type MenuAction = {
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Identifier of the menu action.
|
|
47
|
+
* The value set in this id will be returned when menu is selected.
|
|
48
|
+
*/
|
|
49
|
+
id?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The action's title.
|
|
52
|
+
*/
|
|
53
|
+
title: string;
|
|
54
|
+
/**
|
|
55
|
+
* (Android only)
|
|
56
|
+
* The action's title color.
|
|
57
|
+
* @platform Android
|
|
58
|
+
*/
|
|
59
|
+
titleColor?: number | ColorValue;
|
|
60
|
+
/**
|
|
61
|
+
* (iOS14+ only)
|
|
62
|
+
* An elaborated title that explains the purpose of the action.
|
|
63
|
+
* @platform iOS
|
|
64
|
+
*/
|
|
65
|
+
subtitle?: string;
|
|
66
|
+
/**
|
|
67
|
+
* The attributes indicating the style of the action.
|
|
68
|
+
*/
|
|
69
|
+
attributes?: MenuAttributes;
|
|
70
|
+
/**
|
|
71
|
+
* (iOS14+ only)
|
|
72
|
+
* The state of the action.
|
|
73
|
+
* @platform iOS
|
|
74
|
+
*/
|
|
75
|
+
state?: MenuState;
|
|
76
|
+
/**
|
|
77
|
+
* (Android and iOS13+ only)
|
|
78
|
+
* - The action's image.
|
|
79
|
+
* - Allows icon name included in project or system (Android) resources drawables and
|
|
80
|
+
* in SF Symbol (iOS)
|
|
81
|
+
* @example // (iOS)
|
|
82
|
+
* image="plus"
|
|
83
|
+
* @example // (Android)
|
|
84
|
+
* image="ic_menu_add"
|
|
85
|
+
* - TODO: Allow images other than those included in SF Symbol and resources drawables
|
|
86
|
+
*/
|
|
87
|
+
image?: string;
|
|
88
|
+
/**
|
|
89
|
+
* (Android and iOS13+ only)
|
|
90
|
+
* - The action's image color.
|
|
91
|
+
*/
|
|
92
|
+
imageColor?: number | ColorValue;
|
|
93
|
+
/**
|
|
94
|
+
* (Android and iOS14+ only)
|
|
95
|
+
* - Actions to be displayed in the sub menu
|
|
96
|
+
* - On Android it does not support nesting next sub menus in sub menu item
|
|
97
|
+
*/
|
|
98
|
+
subactions?: MenuAction[];
|
|
99
|
+
/**
|
|
100
|
+
* Whether subactions should be inline (separated by divider) or nested (sub menu)
|
|
101
|
+
*/
|
|
102
|
+
displayInline?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* (iOS 16+ only)
|
|
105
|
+
* The preferred size of this menu's child elements.
|
|
106
|
+
* @platform iOS
|
|
107
|
+
*/
|
|
108
|
+
preferredElementSize?: "small" | "medium" | "large";
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
type MenuComponentPropsBase = {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
112
|
+
style?: StyleProp<ViewStyle>;
|
|
113
|
+
/**
|
|
114
|
+
* Callback function that will be called when selecting a menu item.
|
|
115
|
+
* It will contain id of the given action.
|
|
116
|
+
*/
|
|
117
|
+
onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;
|
|
118
|
+
/**
|
|
119
|
+
* Actions to be displayed in the menu.
|
|
120
|
+
*/
|
|
121
|
+
actions: MenuAction[];
|
|
122
|
+
/**
|
|
123
|
+
* The title of the menu.
|
|
124
|
+
*/
|
|
125
|
+
title?: string;
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
127
|
+
/**
|
|
128
|
+
* (Android API 23+)
|
|
129
|
+
* Boolean value determines whether popup menu should be anchored
|
|
130
|
+
* to right corner of parent view - default value is `false`
|
|
131
|
+
* @platform Android
|
|
132
|
+
*/
|
|
133
|
+
isAnchoredToRight?: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Determines if menu should open after long press or on normal press
|
|
136
|
+
*
|
|
137
|
+
* @default false
|
|
138
|
+
*/
|
|
139
|
+
shouldOpenOnLongPress?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Overrides theme variant of menu to light mode, dark mode or system theme
|
|
142
|
+
* (Only support iOS for now)
|
|
143
|
+
*
|
|
144
|
+
* @platform iOS
|
|
145
|
+
*/
|
|
146
|
+
themeVariant?: string;
|
|
147
|
+
/**
|
|
148
|
+
* Custom OpenSpace hitSlop prop. Works like touchable hitslop.
|
|
149
|
+
* @platform iOS
|
|
150
|
+
*/
|
|
151
|
+
hitSlop?: {
|
|
152
|
+
top: number;
|
|
153
|
+
bottom: number;
|
|
154
|
+
left: number;
|
|
155
|
+
right: number;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Test ID for testing purposes
|
|
159
|
+
*/
|
|
160
|
+
testID?: string;
|
|
161
161
|
};
|
|
162
162
|
|
|
163
163
|
export type MenuComponentProps =
|
|
164
|
-
|
|
164
|
+
React.PropsWithChildren<MenuComponentPropsBase>;
|
|
165
|
+
|
|
166
|
+
export type MenuComponentRef = {
|
|
167
|
+
show: () => void;
|
|
168
|
+
};
|
|
165
169
|
|
|
166
170
|
export type ProcessedMenuAction = Omit<
|
|
167
|
-
|
|
168
|
-
|
|
171
|
+
MenuAction,
|
|
172
|
+
"imageColor" | "titleColor" | "subactions"
|
|
169
173
|
> & {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
174
|
+
imageColor: ReturnType<typeof processColor>;
|
|
175
|
+
titleColor: ReturnType<typeof processColor>;
|
|
176
|
+
subactions?: ProcessedMenuAction[];
|
|
173
177
|
};
|
|
174
178
|
|
|
175
179
|
export type NativeMenuComponentProps = {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
style?: StyleProp<ViewStyle>;
|
|
181
|
+
onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;
|
|
182
|
+
actions: ProcessedMenuAction[];
|
|
183
|
+
actionsHash: string;
|
|
184
|
+
title?: string;
|
|
185
|
+
hitSlop?: MenuComponentProps["hitSlop"];
|
|
186
|
+
testID?: string;
|
|
187
|
+
ref?: React.ForwardedRef<MenuComponentRef>;
|
|
183
188
|
};
|
package/src/utils.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
// Function to calculate a simple hash code for a string
|
|
2
2
|
function hashCode(str: string): number {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
let hash = 0;
|
|
4
|
+
for (let i = 0; i < str.length; i++) {
|
|
5
|
+
const char = str.charCodeAt(i);
|
|
6
|
+
// eslint-disable-next-line no-bitwise
|
|
7
|
+
hash = (hash << 5) - hash + char;
|
|
8
|
+
}
|
|
9
|
+
return hash;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
// Function to create a string hash from a TypeScript object
|
|
13
|
-
export function objectHash(obj: Record<string,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
export function objectHash(obj: Record<string, unknown>[]): string {
|
|
14
|
+
if (!obj) {
|
|
15
|
+
return "";
|
|
16
|
+
}
|
|
17
|
+
// Convert the object to a JSON string
|
|
18
|
+
const jsonString = JSON.stringify(obj);
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
// Calculate the hash code of the JSON string
|
|
21
|
+
const hash = hashCode(jsonString);
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
// Convert the hash code to a string (optional)
|
|
24
|
+
return String(hash);
|
|
25
25
|
}
|