@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.
Files changed (49) hide show
  1. package/README.md +15 -1
  2. package/android/src/main/java/com/reactnativemenu/MenuView.kt +4 -0
  3. package/android/src/main/java/com/reactnativemenu/MenuViewManagerBase.kt +11 -0
  4. package/ios/NewArch/FabricViewImplementationProtocol.swift +3 -0
  5. package/ios/NewArch/MenuView.mm +20 -0
  6. package/ios/Shared/ActionSheetView.swift +2 -2
  7. package/ios/Shared/MenuViewImplementation.swift +3 -3
  8. package/lib/commonjs/NativeModuleSpecs/UIMenuNativeComponent.js +1 -1
  9. package/lib/commonjs/NativeModuleSpecs/UIMenuNativeComponent.js.map +1 -1
  10. package/lib/commonjs/UIMenuView.android.js +19 -1
  11. package/lib/commonjs/UIMenuView.android.js.map +1 -1
  12. package/lib/commonjs/UIMenuView.js +0 -3
  13. package/lib/commonjs/UIMenuView.js.map +1 -1
  14. package/lib/commonjs/index.js +6 -8
  15. package/lib/commonjs/index.js.map +1 -1
  16. package/lib/commonjs/utils.js +1 -1
  17. package/lib/commonjs/utils.js.map +1 -1
  18. package/lib/module/NativeModuleSpecs/UIMenuNativeComponent.js +2 -2
  19. package/lib/module/NativeModuleSpecs/UIMenuNativeComponent.js.map +1 -1
  20. package/lib/module/UIMenuView.android.js +20 -2
  21. package/lib/module/UIMenuView.android.js.map +1 -1
  22. package/lib/module/UIMenuView.ios.js +1 -1
  23. package/lib/module/UIMenuView.js +1 -2
  24. package/lib/module/UIMenuView.js.map +1 -1
  25. package/lib/module/index.js +9 -8
  26. package/lib/module/index.js.map +1 -1
  27. package/lib/module/utils.js +1 -1
  28. package/lib/module/utils.js.map +1 -1
  29. package/lib/typescript/src/NativeModuleSpecs/UIMenuNativeComponent.d.ts +10 -2
  30. package/lib/typescript/src/NativeModuleSpecs/UIMenuNativeComponent.d.ts.map +1 -1
  31. package/lib/typescript/src/UIMenuView.android.d.ts +2 -3
  32. package/lib/typescript/src/UIMenuView.android.d.ts.map +1 -1
  33. package/lib/typescript/src/UIMenuView.d.ts +2 -2
  34. package/lib/typescript/src/UIMenuView.d.ts.map +1 -1
  35. package/lib/typescript/src/UIMenuView.ios.d.ts +1 -1
  36. package/lib/typescript/src/index.d.ts +20 -4
  37. package/lib/typescript/src/index.d.ts.map +1 -1
  38. package/lib/typescript/src/types.d.ts +10 -6
  39. package/lib/typescript/src/types.d.ts.map +1 -1
  40. package/lib/typescript/src/utils.d.ts +1 -1
  41. package/lib/typescript/src/utils.d.ts.map +1 -1
  42. package/package.json +10 -44
  43. package/src/NativeModuleSpecs/UIMenuNativeComponent.ts +45 -37
  44. package/src/UIMenuView.android.tsx +34 -4
  45. package/src/UIMenuView.ios.tsx +1 -1
  46. package/src/UIMenuView.tsx +11 -11
  47. package/src/index.tsx +32 -26
  48. package/src/types.ts +158 -153
  49. package/src/utils.ts +17 -17
package/src/types.ts CHANGED
@@ -1,36 +1,36 @@
1
1
  import type {
2
- ColorValue,
3
- processColor,
4
- StyleProp,
5
- ViewStyle,
6
- } from 'react-native';
7
- import type * as React from 'react';
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
- nativeEvent: {
11
- event: string;
12
- };
10
+ nativeEvent: {
11
+ event: string;
12
+ };
13
13
  };
14
14
 
15
15
  type MenuAttributes = {
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;
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 = 'off' | 'on' | 'mixed';
42
+ type MenuState = "off" | "on" | "mixed";
43
43
 
44
44
  export type MenuAction = {
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';
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
- 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;
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
- * (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;
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
- React.PropsWithChildren<MenuComponentPropsBase>;
164
+ React.PropsWithChildren<MenuComponentPropsBase>;
165
+
166
+ export type MenuComponentRef = {
167
+ show: () => void;
168
+ };
165
169
 
166
170
  export type ProcessedMenuAction = Omit<
167
- MenuAction,
168
- 'imageColor' | 'titleColor' | 'subactions'
171
+ MenuAction,
172
+ "imageColor" | "titleColor" | "subactions"
169
173
  > & {
170
- imageColor: ReturnType<typeof processColor>;
171
- titleColor: ReturnType<typeof processColor>;
172
- subactions?: ProcessedMenuAction[];
174
+ imageColor: ReturnType<typeof processColor>;
175
+ titleColor: ReturnType<typeof processColor>;
176
+ subactions?: ProcessedMenuAction[];
173
177
  };
174
178
 
175
179
  export type NativeMenuComponentProps = {
176
- style?: StyleProp<ViewStyle>;
177
- onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;
178
- actions: ProcessedMenuAction[];
179
- actionsHash: string;
180
- title?: string;
181
- hitSlop?: MenuComponentProps['hitSlop'];
182
- testID?: string;
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
- 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;
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, any>): string {
14
- if (!obj) {
15
- return '';
16
- }
17
- // Convert the object to a JSON string
18
- const jsonString = JSON.stringify(obj);
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
- // Calculate the hash code of the JSON string
21
- const hash = hashCode(jsonString);
20
+ // Calculate the hash code of the JSON string
21
+ const hash = hashCode(jsonString);
22
22
 
23
- // Convert the hash code to a string (optional)
24
- return String(hash);
23
+ // Convert the hash code to a string (optional)
24
+ return String(hash);
25
25
  }