@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
@@ -1,2 +1,2 @@
1
- export declare function objectHash(obj: Record<string, any>): string;
1
+ export declare function objectHash(obj: Record<string, unknown>[]): string;
2
2
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAYA,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAY3D"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAYA,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,MAAM,CAYjE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-menu/menu",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "UIMenu component for react-native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -22,9 +22,9 @@
22
22
  "scripts": {
23
23
  "android": "react-native run-android",
24
24
  "bootstrap": "yarn && yarn pods",
25
- "format": "prettier --write \"**/*.{js,ts,tsx}\"",
25
+ "format": "biome format --write .",
26
26
  "ios": "react-native run-ios",
27
- "lint": "eslint \"**/*.{js,ts,tsx}\"",
27
+ "lint": "biome lint --write .",
28
28
  "pods": "cd example && pod-install --quiet",
29
29
  "prepare": "bob build",
30
30
  "release": "release-it",
@@ -45,28 +45,23 @@
45
45
  },
46
46
  "homepage": "https://github.com/react-native-menu/menu#readme",
47
47
  "devDependencies": {
48
+ "@biomejs/biome": "1.9.4",
48
49
  "@callstack/react-native-visionos": "^0.73.0",
49
- "@react-native/babel-preset": "^0.74.79",
50
- "@react-native/eslint-config": "^0.74.0",
51
- "@react-native/metro-config": "0.74.85",
50
+ "@react-native/babel-preset": "^0.76.1",
51
+ "@react-native/metro-config": "0.76.3",
52
52
  "@release-it/conventional-changelog": "^9.0.1",
53
53
  "@rnx-kit/metro-config": "^2.0.0",
54
54
  "@types/jest": "^29.1.2",
55
55
  "@types/react": "^18.2.2",
56
56
  "@types/react-native": "0.73.0",
57
- "eslint": "8.57.0",
58
- "eslint-config-prettier": "^9.1.0",
59
- "eslint-plugin-ft-flow": "^3.0.0",
60
- "eslint-plugin-prettier": "^5.1.2",
61
57
  "jest": "^29.2.1",
62
- "pod-install": "^0.2.0",
63
- "prettier": "^3.1.1",
58
+ "pod-install": "^0.3.2",
64
59
  "react": "18.2.0",
65
60
  "react-native": "^0.73.0",
66
- "react-native-builder-bob": "^0.30.2",
67
- "react-native-test-app": "^3.8.1",
61
+ "react-native-builder-bob": "^0.33.2",
62
+ "react-native-test-app": "^4.0.4",
68
63
  "release-it": "^17.2.0",
69
- "typescript": "5.6.3"
64
+ "typescript": "5.7.2"
70
65
  },
71
66
  "peerDependencies": {
72
67
  "react": "*",
@@ -96,35 +91,6 @@
96
91
  }
97
92
  }
98
93
  },
99
- "eslintConfig": {
100
- "extends": [
101
- "@react-native",
102
- "prettier"
103
- ],
104
- "rules": {
105
- "prettier/prettier": [
106
- "error",
107
- {
108
- "quoteProps": "consistent",
109
- "singleQuote": true,
110
- "tabWidth": 2,
111
- "trailingComma": "es5",
112
- "useTabs": false
113
- }
114
- ]
115
- }
116
- },
117
- "eslintIgnore": [
118
- "node_modules/",
119
- "lib/"
120
- ],
121
- "prettier": {
122
- "quoteProps": "consistent",
123
- "singleQuote": true,
124
- "tabWidth": 2,
125
- "trailingComma": "es5",
126
- "useTabs": false
127
- },
128
94
  "react-native-builder-bob": {
129
95
  "source": "src",
130
96
  "output": "lib",
@@ -1,9 +1,9 @@
1
1
  import type {
2
- DirectEventHandler,
3
- Int32,
4
- } from 'react-native/Libraries/Types/CodegenTypes';
5
- import type { HostComponent, ViewProps } from 'react-native';
6
- import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
2
+ DirectEventHandler,
3
+ Int32,
4
+ } from "react-native/Libraries/Types/CodegenTypes";
5
+ import type { HostComponent, ViewProps } from "react-native";
6
+ import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent";
7
7
  /*
8
8
  Caution, those below are not just typescript types.
9
9
  Codegen is using them to create the corresponding C++ data types.
@@ -13,43 +13,51 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNati
13
13
  types here, to avoid issues while `pod install` takes place.
14
14
  */
15
15
  type SubAction = {
16
- id?: string;
17
- title: string;
18
- titleColor?: Int32;
19
- subtitle?: string;
20
- state?: string;
21
- image?: string;
22
- imageColor?: Int32;
23
- displayInline?: boolean;
24
- attributes?: {
25
- destructive?: boolean;
26
- disabled?: boolean;
27
- hidden?: boolean;
28
- };
16
+ id?: string;
17
+ title: string;
18
+ titleColor?: Int32;
19
+ subtitle?: string;
20
+ state?: string;
21
+ image?: string;
22
+ imageColor?: Int32;
23
+ displayInline?: boolean;
24
+ attributes?: {
25
+ destructive?: boolean;
26
+ disabled?: boolean;
27
+ hidden?: boolean;
28
+ };
29
29
  };
30
30
  type MenuAction = {
31
- id?: string;
32
- title: string;
33
- titleColor?: Int32;
34
- subtitle?: string;
35
- state?: string;
36
- image?: string;
37
- imageColor?: Int32;
38
- displayInline?: boolean;
39
- attributes?: {
40
- destructive?: boolean;
41
- disabled?: boolean;
42
- hidden?: boolean;
43
- };
44
- subactions?: Array<SubAction>;
31
+ id?: string;
32
+ title: string;
33
+ titleColor?: Int32;
34
+ subtitle?: string;
35
+ state?: string;
36
+ image?: string;
37
+ imageColor?: Int32;
38
+ displayInline?: boolean;
39
+ attributes?: {
40
+ destructive?: boolean;
41
+ disabled?: boolean;
42
+ hidden?: boolean;
43
+ };
44
+ subactions?: Array<SubAction>;
45
45
  };
46
46
  export interface NativeProps extends ViewProps {
47
- onPressAction?: DirectEventHandler<{ event: string }>;
48
- actions: Array<MenuAction>;
49
- actionsHash: string; // just a workaround to make sure we don't have to manually compare MenuActions manually in C++ (since it's a struct and that's a pain)
50
- title?: string;
47
+ onPressAction?: DirectEventHandler<{ event: string }>;
48
+ actions: Array<MenuAction>;
49
+ actionsHash: string; // just a workaround to make sure we don't have to manually compare MenuActions manually in C++ (since it's a struct and that's a pain)
50
+ title?: string;
51
+ themeVariant?: string;
52
+ shouldOpenOnLongPress?: boolean;
53
+ hitSlop: {
54
+ top: Int32;
55
+ bottom: Int32;
56
+ left: Int32;
57
+ right: Int32;
58
+ }
51
59
  }
52
60
 
53
61
  export default codegenNativeComponent<NativeProps>(
54
- 'MenuView'
62
+ "MenuView",
55
63
  ) as HostComponent<NativeProps>;
@@ -1,8 +1,38 @@
1
- import { HostComponent, requireNativeComponent } from 'react-native';
2
- import type { NativeMenuComponentProps } from './types';
1
+ import {
2
+ findNodeHandle,
3
+ type HostComponent,
4
+ requireNativeComponent,
5
+ UIManager,
6
+ } from "react-native";
7
+ import type { MenuComponentRef, NativeMenuComponentProps } from "./types";
8
+ import { forwardRef, useImperativeHandle, useRef } from "react";
3
9
 
4
- const MenuComponent = requireNativeComponent(
5
- 'MenuView'
10
+ const NativeMenuComponent = requireNativeComponent(
11
+ "MenuView",
6
12
  ) as HostComponent<NativeMenuComponentProps>;
7
13
 
14
+ const MenuComponent = forwardRef<MenuComponentRef, NativeMenuComponentProps>(
15
+ (props, ref) => {
16
+ const nativeRef = useRef(null);
17
+
18
+ useImperativeHandle(
19
+ ref,
20
+ () => ({
21
+ show: () => {
22
+ if (nativeRef.current) {
23
+ const node = findNodeHandle(nativeRef.current);
24
+ const command =
25
+ UIManager.getViewManagerConfig("MenuView").Commands.show;
26
+
27
+ UIManager.dispatchViewManagerCommand(node, command, undefined);
28
+ }
29
+ },
30
+ }),
31
+ [],
32
+ );
33
+
34
+ return <NativeMenuComponent {...props} ref={nativeRef} />;
35
+ },
36
+ );
37
+
8
38
  export default MenuComponent;
@@ -1,3 +1,3 @@
1
- import UIMenuNativeComponent from './NativeModuleSpecs/UIMenuNativeComponent';
1
+ import UIMenuNativeComponent from "./NativeModuleSpecs/UIMenuNativeComponent";
2
2
 
3
3
  export default UIMenuNativeComponent;
@@ -1,20 +1,20 @@
1
- import * as React from 'react';
2
- import { View } from 'react-native';
3
- import type { NativeMenuComponentProps } from './types';
1
+ import type * as React from "react";
2
+ import { View } from "react-native";
3
+ import type { NativeMenuComponentProps } from "./types";
4
4
 
5
5
  /**
6
6
  * TODO: implement for Web
7
7
  */
8
8
  const MenuView: React.FC<React.PropsWithChildren<NativeMenuComponentProps>> = ({
9
- style,
10
- children,
11
- testID,
9
+ style,
10
+ children,
11
+ testID,
12
12
  }) => {
13
- return (
14
- <View style={style} testID={testID}>
15
- {children}
16
- </View>
17
- );
13
+ return (
14
+ <View style={style} testID={testID}>
15
+ {children}
16
+ </View>
17
+ );
18
18
  };
19
19
 
20
20
  export default MenuView;
package/src/index.tsx CHANGED
@@ -1,14 +1,15 @@
1
- import React, { useMemo } from 'react';
2
- import { processColor } from 'react-native';
1
+ import { forwardRef, useMemo } from "react";
2
+ import { processColor } from "react-native";
3
3
 
4
- import UIMenuView from './UIMenuView';
4
+ import UIMenuView from "./UIMenuView";
5
5
  import type {
6
6
  MenuComponentProps,
7
7
  MenuAction,
8
8
  ProcessedMenuAction,
9
9
  NativeActionEvent,
10
- } from './types';
11
- import { objectHash } from './utils';
10
+ MenuComponentRef,
11
+ } from "./types";
12
+ import { objectHash } from "./utils";
12
13
 
13
14
  function processAction(action: MenuAction): ProcessedMenuAction {
14
15
  return {
@@ -21,26 +22,31 @@ function processAction(action: MenuAction): ProcessedMenuAction {
21
22
 
22
23
  const defaultHitslop = { top: 0, left: 0, bottom: 0, right: 0 };
23
24
 
24
- const MenuView: React.FC<MenuComponentProps> = ({
25
- actions,
26
- hitSlop = defaultHitslop,
27
- ...props
28
- }) => {
29
- const processedActions = actions.map<ProcessedMenuAction>((action) =>
30
- processAction(action)
31
- );
32
- const hash = useMemo(() => {
33
- return objectHash(processedActions);
34
- }, [processedActions]);
35
- return (
36
- <UIMenuView
37
- {...props}
38
- hitSlop={hitSlop}
39
- actions={processedActions}
40
- actionsHash={hash}
41
- />
42
- );
43
- };
25
+ const MenuView = forwardRef<MenuComponentRef, MenuComponentProps>(
26
+ ({ actions, hitSlop = defaultHitslop, ...props }, ref) => {
27
+ const processedActions = actions.map<ProcessedMenuAction>((action) =>
28
+ processAction(action),
29
+ );
30
+ const hash = useMemo(() => {
31
+ return objectHash(processedActions);
32
+ }, [processedActions]);
33
+
34
+ return (
35
+ <UIMenuView
36
+ {...props}
37
+ hitSlop={hitSlop}
38
+ actions={processedActions}
39
+ actionsHash={hash}
40
+ ref={ref}
41
+ />
42
+ );
43
+ },
44
+ );
44
45
 
45
46
  export { MenuView };
46
- export type { MenuComponentProps, MenuAction, NativeActionEvent };
47
+ export type {
48
+ MenuComponentProps,
49
+ MenuComponentRef,
50
+ MenuAction,
51
+ NativeActionEvent,
52
+ };