@react-native-menu/menu 1.2.3 → 2.0.0

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 CHANGED
@@ -325,6 +325,40 @@ Example usage:
325
325
  </View>
326
326
  </MenuView>
327
327
  ```
328
+
329
+ ### Custom icons (Android)
330
+
331
+ You might want to use custom icons in the MenuAction `image` attribute. To do so, follow these steps.
332
+
333
+ 1. Search for your icon on e.g. [Material Icons](https://fonts.google.com/icons), customize the fill, weight, grade etc.
334
+ to your liking and then press the `Android` tab and click `Download`. This wil download an xml file, e.g.
335
+ `search_24px.xml`. You can create your own icon or get it somewhere else, as long as it is in a format that Android
336
+ understands.
337
+ 2. If using bare react-native, copy the downloaded xml file to your `android/app/src/main/res/drawable` folder.
338
+ If you are using Expo, add a dependency
339
+ on [@expo/config-plugins,](https://www.npmjs.com/package/@expo/config-plugins) and then you can use
340
+ an [expo config plugin](./plugin/withAndroidDrawables.js) to copy the file from your `assets` folder to the drawable
341
+ folder. Copy the config plugin to your app and reference it in your `app.json` or `app.config.js` in the `plugins`
342
+ section like this:
343
+
344
+ ```json
345
+ {
346
+ "expo": {
347
+ "plugins": [
348
+ [
349
+ "./plugin/withAndroidDrawables",
350
+ {
351
+ "drawableFiles": [ "./assets/my_icon.xml" ]
352
+ }
353
+ ]
354
+ ]
355
+ }
356
+ }
357
+ ```
358
+ 3. In your `MenuAction` you can now reference the icon using its file name, without the `.xml` extension. For example,
359
+ `image: 'my_icon'` will use the `my_icon.xml` file you copied to the drawable folder.
360
+ 4. Remember to run a new build to see changes to these icons.
361
+
328
362
  ## Testing with Jest
329
363
 
330
364
  In some cases, you might want to mock the package to test your components. You can do this by using the `jest.mock` function.
@@ -24,6 +24,11 @@ class MenuView(private val mContext: ReactContext) : ReactViewGroup(mContext) {
24
24
  private var mIsOnLongPress = false
25
25
  private var mGestureDetector: GestureDetector
26
26
  private var mHitSlopRect: Rect? = null
27
+ set(value) {
28
+ super.hitSlopRect = value
29
+ mHitSlopRect = value
30
+ updateTouchDelegate()
31
+ }
27
32
 
28
33
  init {
29
34
  mGestureDetector = GestureDetector(mContext, object : GestureDetector.SimpleOnGestureListener() {
@@ -47,12 +52,6 @@ class MenuView(private val mContext: ReactContext) : ReactViewGroup(mContext) {
47
52
  prepareMenu()
48
53
  }
49
54
 
50
- override fun setHitSlopRect(rect: Rect?) {
51
- super.setHitSlopRect(rect)
52
- mHitSlopRect = rect
53
- updateTouchDelegate()
54
- }
55
-
56
55
  override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
57
56
  return true
58
57
  }
@@ -123,9 +123,9 @@ abstract class MenuViewManagerBase : ReactClippingViewManager<MenuView>() {
123
123
  fun setHitSlop(view: ReactViewGroup, @Nullable hitSlop: ReadableMap?) {
124
124
  if (hitSlop == null) {
125
125
  // We should keep using setters as `Val cannot be reassigned`
126
- view.setHitSlopRect(null)
126
+ view.hitSlopRect = null
127
127
  } else {
128
- view.setHitSlopRect(
128
+ view.hitSlopRect = (
129
129
  Rect(
130
130
  if (hitSlop.hasKey("left"))
131
131
  PixelUtil.toPixelFromDIP(hitSlop.getDouble("left")).toInt()
@@ -206,7 +206,7 @@ abstract class MenuViewManagerBase : ReactClippingViewManager<MenuView>() {
206
206
 
207
207
  @ReactProp(name = ViewProps.OVERFLOW)
208
208
  fun setOverflow(view: ReactViewGroup, overflow: String?) {
209
- view.setOverflow(overflow)
209
+ view.overflow = overflow
210
210
  }
211
211
 
212
212
  @ReactProp(name = "backfaceVisibility")
@@ -41,6 +41,11 @@ using namespace facebook::react;
41
41
  _view.onPressAction = ^(NSString *eventString) {
42
42
  [self onPressAction:eventString];
43
43
  };
44
+
45
+ _view.onOpenMenu = ^{
46
+ [self onOpenMenu];
47
+ };
48
+
44
49
  _view.onCloseMenu = ^{
45
50
  [self onCloseMenu];
46
51
  };
File without changes
@@ -0,0 +1,66 @@
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";
7
+ /*
8
+ Caution, those below are not just typescript types.
9
+ Codegen is using them to create the corresponding C++ data types.
10
+
11
+ Codegen doesn't play very well with reusing the same type within a type,
12
+ OR with extending types in an interface, so for now we'll just keep some duplicate
13
+ types here, to avoid issues while `pod install` takes place.
14
+ */
15
+
16
+ type SubAction = {
17
+ id?: string;
18
+ title: string;
19
+ titleColor?: Int32;
20
+ subtitle?: string;
21
+ state?: string;
22
+ image?: string;
23
+ imageColor?: Int32;
24
+ displayInline?: boolean;
25
+ attributes?: {
26
+ destructive?: boolean;
27
+ disabled?: boolean;
28
+ hidden?: boolean;
29
+ };
30
+ };
31
+ type MenuAction = {
32
+ id?: string;
33
+ title: string;
34
+ titleColor?: Int32;
35
+ subtitle?: string;
36
+ state?: string;
37
+ image?: string;
38
+ imageColor?: Int32;
39
+ displayInline?: boolean;
40
+ attributes?: {
41
+ destructive?: boolean;
42
+ disabled?: boolean;
43
+ hidden?: boolean;
44
+ };
45
+ subactions?: Array<SubAction>;
46
+ };
47
+ export interface NativeProps extends ViewProps {
48
+ onPressAction?: DirectEventHandler<{ event: string }>;
49
+ onCloseMenu?: DirectEventHandler<{ event: string }>;
50
+ onOpenMenu?: DirectEventHandler<{ event: string }>;
51
+ actions: Array<MenuAction>;
52
+ 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)
53
+ title?: string;
54
+ themeVariant?: string;
55
+ shouldOpenOnLongPress?: boolean;
56
+ hitSlop: {
57
+ top: Int32;
58
+ bottom: Int32;
59
+ left: Int32;
60
+ right: Int32;
61
+ };
62
+ }
63
+
64
+ export default codegenNativeComponent<NativeProps>(
65
+ "MenuView",
66
+ ) as HostComponent<NativeProps>;
@@ -0,0 +1,66 @@
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";
7
+ /*
8
+ Caution, those below are not just typescript types.
9
+ Codegen is using them to create the corresponding C++ data types.
10
+
11
+ Codegen doesn't play very well with reusing the same type within a type,
12
+ OR with extending types in an interface, so for now we'll just keep some duplicate
13
+ types here, to avoid issues while `pod install` takes place.
14
+ */
15
+
16
+ type SubAction = {
17
+ id?: string;
18
+ title: string;
19
+ titleColor?: Int32;
20
+ subtitle?: string;
21
+ state?: string;
22
+ image?: string;
23
+ imageColor?: Int32;
24
+ displayInline?: boolean;
25
+ attributes?: {
26
+ destructive?: boolean;
27
+ disabled?: boolean;
28
+ hidden?: boolean;
29
+ };
30
+ };
31
+ type MenuAction = {
32
+ id?: string;
33
+ title: string;
34
+ titleColor?: Int32;
35
+ subtitle?: string;
36
+ state?: string;
37
+ image?: string;
38
+ imageColor?: Int32;
39
+ displayInline?: boolean;
40
+ attributes?: {
41
+ destructive?: boolean;
42
+ disabled?: boolean;
43
+ hidden?: boolean;
44
+ };
45
+ subactions?: Array<SubAction>;
46
+ };
47
+ export interface NativeProps extends ViewProps {
48
+ onPressAction?: DirectEventHandler<{ event: string }>;
49
+ onCloseMenu?: DirectEventHandler<{ event: string }>;
50
+ onOpenMenu?: DirectEventHandler<{ event: string }>;
51
+ actions: Array<MenuAction>;
52
+ 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)
53
+ title?: string;
54
+ themeVariant?: string;
55
+ shouldOpenOnLongPress?: boolean;
56
+ hitSlop: {
57
+ top: Int32;
58
+ bottom: Int32;
59
+ left: Int32;
60
+ right: Int32;
61
+ };
62
+ }
63
+
64
+ export default codegenNativeComponent<NativeProps>(
65
+ "MenuView",
66
+ ) as HostComponent<NativeProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-menu/menu",
3
- "version": "1.2.3",
3
+ "version": "2.0.0",
4
4
  "description": "UIMenu component for react-native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -21,7 +21,7 @@
21
21
  ],
22
22
  "scripts": {
23
23
  "android": "react-native run-android",
24
- "bootstrap": "yarn && yarn pods",
24
+ "bootstrap": "yarn && yarn generateRntaManifest",
25
25
  "format": "biome format --write .",
26
26
  "ios": "react-native run-ios",
27
27
  "lint": "biome lint --write .",
@@ -30,7 +30,8 @@
30
30
  "release": "release-it",
31
31
  "start": "react-native start",
32
32
  "test": "jest",
33
- "typescript": "tsc --noEmit"
33
+ "typescript": "tsc --noEmit",
34
+ "generateRntaManifest": "node node_modules/react-native-test-app/android/android-manifest.js example/app.json example/android/app/build/generated/rnta/src/main/AndroidManifest.xml"
34
35
  },
35
36
  "keywords": [
36
37
  "react-native",
@@ -46,22 +47,23 @@
46
47
  "homepage": "https://github.com/react-native-menu/menu#readme",
47
48
  "devDependencies": {
48
49
  "@biomejs/biome": "1.9.4",
49
- "@callstack/react-native-visionos": "^0.73.0",
50
- "@react-native/babel-preset": "^0.77.0",
51
- "@react-native/metro-config": "0.78.1",
50
+ "@callstack/react-native-visionos": "^0.79.6",
51
+ "@react-native-community/cli": "^20.0.2",
52
+ "@react-native/babel-preset": "^0.81.1",
53
+ "@react-native/metro-config": "0.81.1",
52
54
  "@release-it/conventional-changelog": "^10.0.0",
53
- "@rnx-kit/metro-config": "^2.0.0",
55
+ "@rnx-kit/metro-config": "^2.1.1",
54
56
  "@types/jest": "^29.1.2",
55
- "@types/react": "^18.2.2",
57
+ "@types/react": "^19.1.12",
56
58
  "@types/react-native": "0.73.0",
57
59
  "jest": "^29.2.1",
58
- "pod-install": "^0.3.2",
59
- "react": "18.2.0",
60
- "react-native": "^0.73.0",
60
+ "pod-install": "1.0.1",
61
+ "react": "19.1.0",
62
+ "react-native": "^0.81.1",
61
63
  "react-native-builder-bob": "^0.38.0",
62
- "react-native-test-app": "^4.0.4",
64
+ "react-native-test-app": "^4.4.9",
63
65
  "release-it": "^18.1.1",
64
- "typescript": "5.8.2"
66
+ "typescript": "5.8.3"
65
67
  },
66
68
  "peerDependencies": {
67
69
  "react": "*",
@@ -104,13 +106,17 @@
104
106
  "access": "public"
105
107
  },
106
108
  "volta": {
107
- "node": "20.10.0",
108
- "yarn": "1.22.21"
109
+ "node": "22.11.0"
109
110
  },
110
111
  "codegenConfig": {
111
112
  "name": "RNMenuViewSpec",
112
113
  "type": "components",
113
- "jsSrcsDir": "src"
114
+ "jsSrcsDir": "src",
115
+ "ios": {
116
+ "componentProvider": {
117
+ "MenuView": "MenuView"
118
+ }
119
+ }
114
120
  },
115
121
  "packageManager": "yarn@4.1.1"
116
122
  }
@@ -1,7 +1,6 @@
1
1
  require "json"
2
2
 
3
3
  package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
- folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
4
 
6
5
  Pod::Spec.new do |s|
7
6
  s.name = "react-native-menu"
@@ -16,28 +15,5 @@ Pod::Spec.new do |s|
16
15
 
17
16
  s.source_files = "ios/**/*.{h,m,mm,swift}"
18
17
 
19
- if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then # new architecture
20
- # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
21
- # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
22
- if respond_to?(:install_modules_dependencies, true)
23
- install_modules_dependencies(s)
24
- else
25
- s.dependency "React-Core"
26
- # Don't install the dependencies when we run `pod install` in the old architecture.
27
- s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
28
- s.pod_target_xcconfig = {
29
- "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
30
- "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
31
- "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
32
- }
33
- s.dependency "React-RCTFabric"
34
- s.dependency "React-Codegen"
35
- s.dependency "RCT-Folly"
36
- s.dependency "RCTRequired"
37
- s.dependency "RCTTypeSafety"
38
- s.dependency "ReactCommon/turbomodule/core"
39
- end
40
- else # old arch
41
- s.dependency "React"
42
- end
18
+ install_modules_dependencies(s)
43
19
  end
@@ -1,13 +0,0 @@
1
- arguments=
2
- auto.sync=false
3
- build.scans.enabled=false
4
- connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
5
- connection.project.dir=
6
- eclipse.preferences.version=1
7
- gradle.user.home=
8
- java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
9
- jvm.arguments=
10
- offline.mode=false
11
- override.workspace.settings=true
12
- show.console.view=true
13
- show.executions.view=true
@@ -1,6 +0,0 @@
1
- #Sun Mar 21 12:53:47 CET 2021
2
- distributionBase=GRADLE_USER_HOME
3
- distributionPath=wrapper/dists
4
- zipStoreBase=GRADLE_USER_HOME
5
- zipStorePath=wrapper/dists
6
- distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _codegenNativeComponent = _interopRequireDefault(require("react-native/Libraries/Utilities/codegenNativeComponent"));
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
- /*
10
- Caution, those below are not just typescript types.
11
- Codegen is using them to create the corresponding C++ data types.
12
-
13
- Codegen doesn't play very well with reusing the same type within a type,
14
- OR with extending types in an interface, so for now we'll just keep some duplicate
15
- types here, to avoid issues while `pod install` takes place.
16
- */
17
- var _default = exports.default = (0, _codegenNativeComponent.default)("MenuView");
18
- //# sourceMappingURL=UIMenuNativeComponent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_codegenNativeComponent","_interopRequireDefault","require","e","__esModule","default","_default","exports","codegenNativeComponent"],"sourceRoot":"../../../src","sources":["NativeModuleSpecs/UIMenuNativeComponent.ts"],"mappings":";;;;;;AAKA,IAAAA,uBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA6F,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAC7F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAPA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GAyDe,IAAAG,+BAAsB,EACpC,UACD,CAAC","ignoreList":[]}
@@ -1,14 +0,0 @@
1
- "use strict";
2
-
3
- import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent";
4
- /*
5
- Caution, those below are not just typescript types.
6
- Codegen is using them to create the corresponding C++ data types.
7
-
8
- Codegen doesn't play very well with reusing the same type within a type,
9
- OR with extending types in an interface, so for now we'll just keep some duplicate
10
- types here, to avoid issues while `pod install` takes place.
11
- */
12
-
13
- export default codegenNativeComponent("MenuView");
14
- //# sourceMappingURL=UIMenuNativeComponent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["codegenNativeComponent"],"sourceRoot":"../../../src","sources":["NativeModuleSpecs/UIMenuNativeComponent.ts"],"mappings":";;AAKA,OAAOA,sBAAsB,MAAM,yDAAyD;AAC5F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAkDA,eAAeA,sBAAsB,CACpC,UACD,CAAC","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"type":"module"}