@react-native-menu/menu 2.0.0 → 2.1.1

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
@@ -23,12 +23,6 @@ via yarn:
23
23
  yarn add @react-native-menu/menu
24
24
  ```
25
25
 
26
- ### Installing on iOS with React Native 0.63 and above
27
-
28
- There is an issue(https://github.com/facebook/react-native/issues/29246) causing projects with this module to fail on build on React Native 0.63 and above.
29
- This issue may be fixed in future versions of react native.
30
- As a work around, look for lines in `[YourPrject].xcodeproj` under `LIBRARY_SEARCH_PATHS` with `"\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",` and change `swift-5.0` to `swift-5.3`.
31
-
32
26
  ## Linking
33
27
 
34
28
  The package is [automatically linked](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md) when building the app. All you need to do is:
@@ -15,6 +15,9 @@ buildscript {
15
15
  }
16
16
 
17
17
  def isNewArchitectureEnabled() {
18
+ if (getReactNativeMinorVersion() >= 82) {
19
+ return true
20
+ }
18
21
  return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
19
22
  }
20
23
 
@@ -25,8 +25,7 @@ class MenuView(private val mContext: ReactContext) : ReactViewGroup(mContext) {
25
25
  private var mGestureDetector: GestureDetector
26
26
  private var mHitSlopRect: Rect? = null
27
27
  set(value) {
28
- super.hitSlopRect = value
29
- mHitSlopRect = value
28
+ field = value
30
29
  updateTouchDelegate()
31
30
  }
32
31
 
@@ -233,8 +233,15 @@ abstract class MenuViewManagerBase : ReactClippingViewManager<MenuView>() {
233
233
  }
234
234
  }
235
235
 
236
+ override fun receiveCommand(root: MenuView, commandId: String, args: ReadableArray?) {
237
+ when (commandId) {
238
+ NEW_ARCH_COMMAND_SHOW -> root.show()
239
+ }
240
+ }
241
+
236
242
  companion object {
237
- val COMMAND_SHOW = 1
243
+ const val COMMAND_SHOW = 1
244
+ const val NEW_ARCH_COMMAND_SHOW = "show"
238
245
  val SPACING_TYPES =
239
246
  arrayOf(
240
247
  Spacing.ALL,
@@ -14,12 +14,16 @@
14
14
 
15
15
  using namespace facebook::react;
16
16
 
17
- @interface MenuView () <RCTMenuViewViewProtocol>
17
+ @interface MenuView () <RCTMenuViewViewProtocol, UIContextMenuInteractionDelegate>
18
18
 
19
19
  @end
20
20
 
21
21
  @implementation MenuView {
22
22
  UIView <FabricViewImplementationProtocol> * _view;
23
+ // Set while the menu opens on a long press: the context menu interaction lives on this view
24
+ // instead of the button, see setOpensOnLongPress:
25
+ id<UIInteraction> _longPressInteraction;
26
+ NSString *_themeVariant;
23
27
  }
24
28
 
25
29
  + (ComponentDescriptorProvider)componentDescriptorProvider
@@ -134,6 +138,7 @@ using namespace facebook::react;
134
138
  @"image": [NSString stringWithUTF8String:action.image.c_str()],
135
139
  @"imageColor": @(action.imageColor),
136
140
  @"displayInline": @(action.displayInline),
141
+ @"preferredElementSize": [NSString stringWithUTF8String:action.preferredElementSize.c_str()],
137
142
  @"attributes": @{
138
143
  @"destructive": @(action.attributes.destructive),
139
144
  @"disabled": @(action.attributes.disabled),
@@ -162,11 +167,14 @@ using namespace facebook::react;
162
167
  }
163
168
 
164
169
  if (oldViewProps.themeVariant != newViewProps.themeVariant) {
165
- _view.themeVariant = [NSString stringWithUTF8String:newViewProps.themeVariant.c_str()];
170
+ _themeVariant = [NSString stringWithUTF8String:newViewProps.themeVariant.c_str()];
171
+ _view.themeVariant = _themeVariant;
172
+ [self applyLongPressThemeVariant];
166
173
  }
167
-
174
+
168
175
  if (oldViewProps.shouldOpenOnLongPress != newViewProps.shouldOpenOnLongPress) {
169
176
  _view.shouldOpenOnLongPress = newViewProps.shouldOpenOnLongPress;
177
+ [self setOpensOnLongPress:newViewProps.shouldOpenOnLongPress];
170
178
  }
171
179
 
172
180
  if (oldViewProps.hitSlop.top != newViewProps.hitSlop.top ||
@@ -184,6 +192,104 @@ using namespace facebook::react;
184
192
  [super updateProps:props oldProps:oldProps];
185
193
  }
186
194
 
195
+ #pragma mark - Opening on a long press
196
+
197
+ // The button is this view's contentView, which React Native keeps above the children, so it takes
198
+ // every touch: with the menu opening on a long press, a child never received a tap, and VoiceOver
199
+ // read the whole view as one element (the view takes isAccessibilityElement from its contentView).
200
+ // In that mode the context menu interaction lives on this view instead and the button steps out of
201
+ // touches and accessibility: a tap reaches the child under the finger, a long press opens the
202
+ // button's menu, and VoiceOver reaches each child. A menu that opens on a tap is unchanged.
203
+ //
204
+ // This runs only when shouldOpenOnLongPress changes, so it relies on prepareForRecycle keeping
205
+ // _props, as the button's own showsMenuAsPrimaryAction already does: if a recycled view were reset
206
+ // to default props while still in this mode, a reused tap-to-open menu would stop opening.
207
+ - (void)setOpensOnLongPress:(BOOL)longPress
208
+ {
209
+ if (longPress == (_longPressInteraction != nil) || ![_view isKindOfClass:[UIControl class]]) {
210
+ return;
211
+ }
212
+ if (@available(iOS 14.0, *)) {
213
+ if (longPress) {
214
+ _longPressInteraction = [[UIContextMenuInteraction alloc] initWithDelegate:self];
215
+ [self addInteraction:_longPressInteraction];
216
+ } else {
217
+ [self removeInteraction:_longPressInteraction];
218
+ _longPressInteraction = nil;
219
+ }
220
+ _view.userInteractionEnabled = !longPress;
221
+ _view.isAccessibilityElement = !longPress;
222
+ _view.accessibilityElementsHidden = longPress;
223
+ [self applyLongPressThemeVariant];
224
+ }
225
+ }
226
+
227
+ // The button applies themeVariant to its own menu. In long press mode the menu is presented from
228
+ // this view, so the variant goes here, as it does on the old architecture, where the button is the
229
+ // view that holds the children.
230
+ - (void)applyLongPressThemeVariant
231
+ {
232
+ if (@available(iOS 13.0, *)) {
233
+ UIUserInterfaceStyle style = UIUserInterfaceStyleUnspecified;
234
+ if (_longPressInteraction != nil && [_themeVariant isEqualToString:@"dark"]) {
235
+ style = UIUserInterfaceStyleDark;
236
+ } else if (_longPressInteraction != nil && [_themeVariant isEqualToString:@"light"]) {
237
+ style = UIUserInterfaceStyleLight;
238
+ }
239
+ self.overrideUserInterfaceStyle = style;
240
+ }
241
+ }
242
+
243
+ // The menu, its title and the open and close events stay the button's own
244
+ - (UIContextMenuConfiguration *)contextMenuInteraction:(UIContextMenuInteraction *)interaction
245
+ configurationForMenuAtLocation:(CGPoint)location API_AVAILABLE(ios(14.0))
246
+ {
247
+ return [(id<UIContextMenuInteractionDelegate>)_view contextMenuInteraction:interaction
248
+ configurationForMenuAtLocation:location];
249
+ }
250
+
251
+ - (void)contextMenuInteraction:(UIContextMenuInteraction *)interaction
252
+ willEndForConfiguration:(UIContextMenuConfiguration *)configuration
253
+ animator:(id<UIContextMenuInteractionAnimating>)animator API_AVAILABLE(ios(14.0))
254
+ {
255
+ [(id<UIContextMenuInteractionDelegate>)_view contextMenuInteraction:interaction
256
+ willEndForConfiguration:configuration
257
+ animator:animator];
258
+ }
259
+
260
+ // The preview is this view as it is drawn. One taken off screen while its menu is up just fades.
261
+ - (UITargetedPreview *)longPressPreview API_AVAILABLE(ios(14.0))
262
+ {
263
+ return self.window != nil ? [[UITargetedPreview alloc] initWithView:self] : nil;
264
+ }
265
+
266
+ - (UITargetedPreview *)contextMenuInteraction:(UIContextMenuInteraction *)interaction
267
+ configuration:(UIContextMenuConfiguration *)configuration
268
+ highlightPreviewForItemWithIdentifier:(id<NSCopying>)identifier API_AVAILABLE(ios(16.0))
269
+ {
270
+ return [self longPressPreview];
271
+ }
272
+
273
+ - (UITargetedPreview *)contextMenuInteraction:(UIContextMenuInteraction *)interaction
274
+ configuration:(UIContextMenuConfiguration *)configuration
275
+ dismissalPreviewForItemWithIdentifier:(id<NSCopying>)identifier API_AVAILABLE(ios(16.0))
276
+ {
277
+ return [self longPressPreview];
278
+ }
279
+
280
+ // The same preview before iOS 16, which asks these instead
281
+ - (UITargetedPreview *)contextMenuInteraction:(UIContextMenuInteraction *)interaction
282
+ previewForHighlightingMenuWithConfiguration:(UIContextMenuConfiguration *)configuration API_AVAILABLE(ios(14.0))
283
+ {
284
+ return [self longPressPreview];
285
+ }
286
+
287
+ - (UITargetedPreview *)contextMenuInteraction:(UIContextMenuInteraction *)interaction
288
+ previewForDismissingMenuWithConfiguration:(UIContextMenuConfiguration *)configuration API_AVAILABLE(ios(14.0))
289
+ {
290
+ return [self longPressPreview];
291
+ }
292
+
187
293
  Class<RCTComponentViewProtocol> MenuViewCls(void)
188
294
  {
189
295
  return MenuView.class;
@@ -28,7 +28,9 @@ class RCTAlertAction {
28
28
  self.title = "";
29
29
  }
30
30
 
31
- if let image = details["image"] as? NSString {
31
+ // The new architecture sends an unset image as an empty string, and
32
+ // UIImage(named: "") logs "Invalid asset name supplied" each time the menu is built.
33
+ if let image = details["image"] as? NSString, image.length > 0 {
32
34
  if #available(iOS 13.0, *) {
33
35
  self.image = UIImage(systemName: image as String)
34
36
  if let imageColor = details["imageColor"] {
@@ -27,7 +27,9 @@ class RCTMenuAction {
27
27
  self.identifier = UIAction.Identifier(rawValue: identifier as String);
28
28
  }
29
29
 
30
- if let image = details["image"] as? NSString {
30
+ // The new architecture sends an unset image as an empty string, and
31
+ // UIImage(named: "") logs "Invalid asset name supplied" each time the menu is built.
32
+ if let image = details["image"] as? NSString, image.length > 0 {
31
33
  self.image = UIImage(systemName: image as String);
32
34
  if self.image === nil {
33
35
  self.image = UIImage(named: image as String)
@@ -1,9 +1,11 @@
1
1
  import type {
2
2
  DirectEventHandler,
3
3
  Int32,
4
+ WithDefault
4
5
  } from "react-native/Libraries/Types/CodegenTypes";
5
6
  import type { HostComponent, ViewProps } from "react-native";
6
7
  import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent";
8
+
7
9
  /*
8
10
  Caution, those below are not just typescript types.
9
11
  Codegen is using them to create the corresponding C++ data types.
@@ -37,6 +39,7 @@ type MenuAction = {
37
39
  image?: string;
38
40
  imageColor?: Int32;
39
41
  displayInline?: boolean;
42
+ preferredElementSize?: WithDefault<string, 'large'>;
40
43
  attributes?: {
41
44
  destructive?: boolean;
42
45
  disabled?: boolean;
@@ -52,6 +55,7 @@ export interface NativeProps extends ViewProps {
52
55
  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
56
  title?: string;
54
57
  themeVariant?: string;
58
+ isAnchoredToRight?: boolean;
55
59
  shouldOpenOnLongPress?: boolean;
56
60
  hitSlop: {
57
61
  top: Int32;
@@ -6,16 +6,27 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _reactNative = require("react-native");
8
8
  var _react = require("react");
9
+ var _codegenNativeCommands = _interopRequireDefault(require("react-native/Libraries/Utilities/codegenNativeCommands"));
9
10
  var _jsxRuntime = require("react/jsx-runtime");
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
12
  const NativeMenuComponent = (0, _reactNative.requireNativeComponent)("MenuView");
13
+ const Commands = (0, _codegenNativeCommands.default)({
14
+ supportedCommands: ["show"]
15
+ });
11
16
  const MenuComponent = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
12
17
  const nativeRef = (0, _react.useRef)(null);
13
18
  (0, _react.useImperativeHandle)(ref, () => ({
14
19
  show: () => {
15
20
  if (nativeRef.current) {
16
- const node = (0, _reactNative.findNodeHandle)(nativeRef.current);
17
- const command = _reactNative.UIManager.getViewManagerConfig("MenuView").Commands.show;
18
- _reactNative.UIManager.dispatchViewManagerCommand(node, command, undefined);
21
+ // biome-ignore lint/suspicious/noExplicitAny: React Native runtime flags like nativeFabricUIManager are not in TypeScript types. Using `any` here is intentional and safe.
22
+ const isFabric = !!global.nativeFabricUIManager;
23
+ if (isFabric) {
24
+ Commands.show(nativeRef.current);
25
+ } else {
26
+ const node = (0, _reactNative.findNodeHandle)(nativeRef.current);
27
+ const command = _reactNative.UIManager.getViewManagerConfig("MenuView").Commands.show;
28
+ _reactNative.UIManager.dispatchViewManagerCommand(node, command, undefined);
29
+ }
19
30
  }
20
31
  }
21
32
  }), []);
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","_react","_jsxRuntime","NativeMenuComponent","requireNativeComponent","MenuComponent","forwardRef","props","ref","nativeRef","useRef","useImperativeHandle","show","current","node","findNodeHandle","command","UIManager","getViewManagerConfig","Commands","dispatchViewManagerCommand","undefined","jsx","_default","exports","default"],"sourceRoot":"../../src","sources":["UIMenuView.android.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAOA,IAAAC,MAAA,GAAAD,OAAA;AAAgE,IAAAE,WAAA,GAAAF,OAAA;AAEhE,MAAMG,mBAAmB,GAAG,IAAAC,mCAAsB,EACjD,UACD,CAA4C;AAE5C,MAAMC,aAAa,gBAAG,IAAAC,iBAAU,EAC/B,CAACC,KAAK,EAAEC,GAAG,KAAK;EACf,MAAMC,SAAS,GAAG,IAAAC,aAAM,EAAC,IAAI,CAAC;EAE9B,IAAAC,0BAAmB,EAClBH,GAAG,EACH,OAAO;IACNI,IAAI,EAAEA,CAAA,KAAM;MACX,IAAIH,SAAS,CAACI,OAAO,EAAE;QACtB,MAAMC,IAAI,GAAG,IAAAC,2BAAc,EAACN,SAAS,CAACI,OAAO,CAAC;QAC9C,MAAMG,OAAO,GACZC,sBAAS,CAACC,oBAAoB,CAAC,UAAU,CAAC,CAACC,QAAQ,CAACP,IAAI;QAEzDK,sBAAS,CAACG,0BAA0B,CAACN,IAAI,EAAEE,OAAO,EAAEK,SAAS,CAAC;MAC/D;IACD;EACD,CAAC,CAAC,EACF,EACD,CAAC;EAED,oBAAO,IAAAnB,WAAA,CAAAoB,GAAA,EAACnB,mBAAmB;IAAA,GAAKI,KAAK;IAAEC,GAAG,EAAEC;EAAU,CAAE,CAAC;AAC1D,CACD,CAAC;AAAC,IAAAc,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEapB,aAAa","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","_react","_codegenNativeCommands","_interopRequireDefault","_jsxRuntime","e","__esModule","default","NativeMenuComponent","requireNativeComponent","Commands","codegenNativeCommands","supportedCommands","MenuComponent","forwardRef","props","ref","nativeRef","useRef","useImperativeHandle","show","current","isFabric","global","nativeFabricUIManager","node","findNodeHandle","command","UIManager","getViewManagerConfig","dispatchViewManagerCommand","undefined","jsx","_default","exports"],"sourceRoot":"../../src","sources":["UIMenuView.android.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAOA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAA2F,IAAAI,WAAA,GAAAJ,OAAA;AAAA,SAAAG,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE3F,MAAMG,mBAAmB,GAAG,IAAAC,mCAAsB,EACjD,UACD,CAA4C;AAI5C,MAAMC,QAAQ,GAAG,IAAAC,8BAAqB,EAEnC;EACFC,iBAAiB,EAAE,CAAC,MAAM;AAC3B,CAAC,CAAC;AAEF,MAAMC,aAAa,gBAAG,IAAAC,iBAAU,EAC/B,CAACC,KAAK,EAAEC,GAAG,KAAK;EACf,MAAMC,SAAS,GAAG,IAAAC,aAAM,EAAC,IAAI,CAAC;EAE9B,IAAAC,0BAAmB,EAClBH,GAAG,EACH,OAAO;IACNI,IAAI,EAAEA,CAAA,KAAM;MACX,IAAIH,SAAS,CAACI,OAAO,EAAE;QACtB;QACA,MAAMC,QAAQ,GAAG,CAAC,CAAEC,MAAM,CAASC,qBAAqB;QAExD,IAAIF,QAAQ,EAAE;UACbZ,QAAQ,CAACU,IAAI,CAACH,SAAS,CAACI,OAAO,CAAC;QACjC,CAAC,MAAM;UACN,MAAMI,IAAI,GAAG,IAAAC,2BAAc,EAACT,SAAS,CAACI,OAAO,CAAC;UAC9C,MAAMM,OAAO,GACZC,sBAAS,CAACC,oBAAoB,CAAC,UAAU,CAAC,CAACnB,QAAQ,CAACU,IAAI;UAEzDQ,sBAAS,CAACE,0BAA0B,CAACL,IAAI,EAAEE,OAAO,EAAEI,SAAS,CAAC;QAC/D;MACD;IACD;EACD,CAAC,CAAC,EACF,EACD,CAAC;EAED,oBAAO,IAAA3B,WAAA,CAAA4B,GAAA,EAACxB,mBAAmB;IAAA,GAAKO,KAAK;IAAEC,GAAG,EAAEC;EAAU,CAAE,CAAC;AAC1D,CACD,CAAC;AAAC,IAAAgB,QAAA,GAAAC,OAAA,CAAA3B,OAAA,GAEaM,aAAa","ignoreList":[]}
@@ -1,9 +1,11 @@
1
1
  import type {
2
2
  DirectEventHandler,
3
3
  Int32,
4
+ WithDefault
4
5
  } from "react-native/Libraries/Types/CodegenTypes";
5
6
  import type { HostComponent, ViewProps } from "react-native";
6
7
  import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent";
8
+
7
9
  /*
8
10
  Caution, those below are not just typescript types.
9
11
  Codegen is using them to create the corresponding C++ data types.
@@ -37,6 +39,7 @@ type MenuAction = {
37
39
  image?: string;
38
40
  imageColor?: Int32;
39
41
  displayInline?: boolean;
42
+ preferredElementSize?: WithDefault<string, 'large'>;
40
43
  attributes?: {
41
44
  destructive?: boolean;
42
45
  disabled?: boolean;
@@ -52,6 +55,7 @@ export interface NativeProps extends ViewProps {
52
55
  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
56
  title?: string;
54
57
  themeVariant?: string;
58
+ isAnchoredToRight?: boolean;
55
59
  shouldOpenOnLongPress?: boolean;
56
60
  hitSlop: {
57
61
  top: Int32;
@@ -2,16 +2,26 @@
2
2
 
3
3
  import { findNodeHandle, requireNativeComponent, UIManager } from "react-native";
4
4
  import { forwardRef, useImperativeHandle, useRef } from "react";
5
+ import codegenNativeCommands from "react-native/Libraries/Utilities/codegenNativeCommands";
5
6
  import { jsx as _jsx } from "react/jsx-runtime";
6
7
  const NativeMenuComponent = requireNativeComponent("MenuView");
8
+ const Commands = codegenNativeCommands({
9
+ supportedCommands: ["show"]
10
+ });
7
11
  const MenuComponent = /*#__PURE__*/forwardRef((props, ref) => {
8
12
  const nativeRef = useRef(null);
9
13
  useImperativeHandle(ref, () => ({
10
14
  show: () => {
11
15
  if (nativeRef.current) {
12
- const node = findNodeHandle(nativeRef.current);
13
- const command = UIManager.getViewManagerConfig("MenuView").Commands.show;
14
- UIManager.dispatchViewManagerCommand(node, command, undefined);
16
+ // biome-ignore lint/suspicious/noExplicitAny: React Native runtime flags like nativeFabricUIManager are not in TypeScript types. Using `any` here is intentional and safe.
17
+ const isFabric = !!global.nativeFabricUIManager;
18
+ if (isFabric) {
19
+ Commands.show(nativeRef.current);
20
+ } else {
21
+ const node = findNodeHandle(nativeRef.current);
22
+ const command = UIManager.getViewManagerConfig("MenuView").Commands.show;
23
+ UIManager.dispatchViewManagerCommand(node, command, undefined);
24
+ }
15
25
  }
16
26
  }
17
27
  }), []);
@@ -1 +1 @@
1
- {"version":3,"names":["findNodeHandle","requireNativeComponent","UIManager","forwardRef","useImperativeHandle","useRef","jsx","_jsx","NativeMenuComponent","MenuComponent","props","ref","nativeRef","show","current","node","command","getViewManagerConfig","Commands","dispatchViewManagerCommand","undefined"],"sourceRoot":"../../src","sources":["UIMenuView.android.tsx"],"mappings":";;AAAA,SACCA,cAAc,EAEdC,sBAAsB,EACtBC,SAAS,QACH,cAAc;AAErB,SAASC,UAAU,EAAEC,mBAAmB,EAAEC,MAAM,QAAQ,OAAO;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAEhE,MAAMC,mBAAmB,GAAGP,sBAAsB,CACjD,UACD,CAA4C;AAE5C,MAAMQ,aAAa,gBAAGN,UAAU,CAC/B,CAACO,KAAK,EAAEC,GAAG,KAAK;EACf,MAAMC,SAAS,GAAGP,MAAM,CAAC,IAAI,CAAC;EAE9BD,mBAAmB,CAClBO,GAAG,EACH,OAAO;IACNE,IAAI,EAAEA,CAAA,KAAM;MACX,IAAID,SAAS,CAACE,OAAO,EAAE;QACtB,MAAMC,IAAI,GAAGf,cAAc,CAACY,SAAS,CAACE,OAAO,CAAC;QAC9C,MAAME,OAAO,GACZd,SAAS,CAACe,oBAAoB,CAAC,UAAU,CAAC,CAACC,QAAQ,CAACL,IAAI;QAEzDX,SAAS,CAACiB,0BAA0B,CAACJ,IAAI,EAAEC,OAAO,EAAEI,SAAS,CAAC;MAC/D;IACD;EACD,CAAC,CAAC,EACF,EACD,CAAC;EAED,oBAAOb,IAAA,CAACC,mBAAmB;IAAA,GAAKE,KAAK;IAAEC,GAAG,EAAEC;EAAU,CAAE,CAAC;AAC1D,CACD,CAAC;AAED,eAAeH,aAAa","ignoreList":[]}
1
+ {"version":3,"names":["findNodeHandle","requireNativeComponent","UIManager","forwardRef","useImperativeHandle","useRef","codegenNativeCommands","jsx","_jsx","NativeMenuComponent","Commands","supportedCommands","MenuComponent","props","ref","nativeRef","show","current","isFabric","global","nativeFabricUIManager","node","command","getViewManagerConfig","dispatchViewManagerCommand","undefined"],"sourceRoot":"../../src","sources":["UIMenuView.android.tsx"],"mappings":";;AAAA,SACCA,cAAc,EAEdC,sBAAsB,EACtBC,SAAS,QACH,cAAc;AAErB,SAASC,UAAU,EAAEC,mBAAmB,EAAEC,MAAM,QAAQ,OAAO;AAC/D,OAAOC,qBAAqB,MAAM,wDAAwD;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAE3F,MAAMC,mBAAmB,GAAGR,sBAAsB,CACjD,UACD,CAA4C;AAI5C,MAAMS,QAAQ,GAAGJ,qBAAqB,CAEnC;EACFK,iBAAiB,EAAE,CAAC,MAAM;AAC3B,CAAC,CAAC;AAEF,MAAMC,aAAa,gBAAGT,UAAU,CAC/B,CAACU,KAAK,EAAEC,GAAG,KAAK;EACf,MAAMC,SAAS,GAAGV,MAAM,CAAC,IAAI,CAAC;EAE9BD,mBAAmB,CAClBU,GAAG,EACH,OAAO;IACNE,IAAI,EAAEA,CAAA,KAAM;MACX,IAAID,SAAS,CAACE,OAAO,EAAE;QACtB;QACA,MAAMC,QAAQ,GAAG,CAAC,CAAEC,MAAM,CAASC,qBAAqB;QAExD,IAAIF,QAAQ,EAAE;UACbR,QAAQ,CAACM,IAAI,CAACD,SAAS,CAACE,OAAO,CAAC;QACjC,CAAC,MAAM;UACN,MAAMI,IAAI,GAAGrB,cAAc,CAACe,SAAS,CAACE,OAAO,CAAC;UAC9C,MAAMK,OAAO,GACZpB,SAAS,CAACqB,oBAAoB,CAAC,UAAU,CAAC,CAACb,QAAQ,CAACM,IAAI;UAEzDd,SAAS,CAACsB,0BAA0B,CAACH,IAAI,EAAEC,OAAO,EAAEG,SAAS,CAAC;QAC/D;MACD;IACD;EACD,CAAC,CAAC,EACF,EACD,CAAC;EAED,oBAAOjB,IAAA,CAACC,mBAAmB;IAAA,GAAKI,KAAK;IAAEC,GAAG,EAAEC;EAAU,CAAE,CAAC;AAC1D,CACD,CAAC;AAED,eAAeH,aAAa","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import type { DirectEventHandler, Int32 } from "react-native/Libraries/Types/CodegenTypes";
1
+ import type { DirectEventHandler, Int32, WithDefault } from "react-native/Libraries/Types/CodegenTypes";
2
2
  import type { HostComponent, ViewProps } from "react-native";
3
3
  type SubAction = {
4
4
  id?: string;
@@ -24,6 +24,7 @@ type MenuAction = {
24
24
  image?: string;
25
25
  imageColor?: Int32;
26
26
  displayInline?: boolean;
27
+ preferredElementSize?: WithDefault<string, 'large'>;
27
28
  attributes?: {
28
29
  destructive?: boolean;
29
30
  disabled?: boolean;
@@ -45,6 +46,7 @@ export interface NativeProps extends ViewProps {
45
46
  actionsHash: string;
46
47
  title?: string;
47
48
  themeVariant?: string;
49
+ isAnchoredToRight?: boolean;
48
50
  shouldOpenOnLongPress?: boolean;
49
51
  hitSlop: {
50
52
  top: Int32;
@@ -1 +1 @@
1
- {"version":3,"file":"UIMenuNativeComponent.d.ts","sourceRoot":"","sources":["../../../../src/NativeModuleSpecs/UIMenuNativeComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,kBAAkB,EAClB,KAAK,EACL,MAAM,2CAA2C,CAAC;AACnD,OAAO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AAC,CAAC;IACpD,UAAU,CAAC,EAAE,kBAAkB,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnD,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,OAAO,EAAE;QACR,GAAG,EAAE,KAAK,CAAC;QACX,MAAM,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,KAAK,CAAC;QACZ,KAAK,EAAE,KAAK,CAAC;KACb,CAAC;CACF;wBAII,aAAa,CAAC,WAAW,CAAC;AAF/B,wBAEgC"}
1
+ {"version":3,"file":"UIMenuNativeComponent.d.ts","sourceRoot":"","sources":["../../../../src/NativeModuleSpecs/UIMenuNativeComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,kBAAkB,EAClB,KAAK,EACL,WAAW,EACX,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAY7D,KAAK,SAAS,GAAG;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,CAAC,EAAE;QACZ,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,MAAM,CAAC,EAAE,OAAO,CAAC;KACjB,CAAC;CACF,CAAC;AACF,KAAK,UAAU,GAAG;IACjB,EAAE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aAAa,CAAC,WAAW,CAAC;AAF/B,wBAEgC"}
@@ -1 +1 @@
1
- {"version":3,"file":"UIMenuView.android.d.ts","sourceRoot":"","sources":["../../../src/UIMenuView.android.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAO1E,QAAA,MAAM,aAAa,oIAsBlB,CAAC;AAEF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"UIMenuView.android.d.ts","sourceRoot":"","sources":["../../../src/UIMenuView.android.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAgB1E,QAAA,MAAM,aAAa,oIA6BlB,CAAC;AAEF,eAAe,aAAa,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-menu/menu",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "UIMenu component for react-native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -38,7 +38,10 @@
38
38
  "ios",
39
39
  "android"
40
40
  ],
41
- "repository": "https://github.com/react-native-menu/menu",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/react-native-menu/menu.git"
44
+ },
42
45
  "author": "Jesse Katsumata <jesse.katsumata@gmail.com> (https://github.com/Naturalclar)",
43
46
  "license": "MIT",
44
47
  "bugs": {
@@ -51,19 +54,19 @@
51
54
  "@react-native-community/cli": "^20.0.2",
52
55
  "@react-native/babel-preset": "^0.81.1",
53
56
  "@react-native/metro-config": "0.81.1",
54
- "@release-it/conventional-changelog": "^10.0.0",
57
+ "@release-it/conventional-changelog": "^11.0.1",
55
58
  "@rnx-kit/metro-config": "^2.1.1",
56
59
  "@types/jest": "^29.1.2",
57
60
  "@types/react": "^19.1.12",
58
61
  "@types/react-native": "0.73.0",
59
62
  "jest": "^29.2.1",
60
- "pod-install": "1.0.1",
63
+ "pod-install": "1.2.1",
61
64
  "react": "19.1.0",
62
65
  "react-native": "^0.81.1",
63
- "react-native-builder-bob": "^0.38.0",
66
+ "react-native-builder-bob": "^0.43.0",
64
67
  "react-native-test-app": "^4.4.9",
65
68
  "release-it": "^18.1.1",
66
- "typescript": "5.8.3"
69
+ "typescript": "5.9.3"
67
70
  },
68
71
  "peerDependencies": {
69
72
  "react": "*",
@@ -82,14 +85,15 @@
82
85
  "tagName": "v${version}"
83
86
  },
84
87
  "npm": {
85
- "publish": true
88
+ "publish": true,
89
+ "skipChecks": true
86
90
  },
87
91
  "github": {
88
92
  "release": true
89
93
  },
90
94
  "plugins": {
91
95
  "@release-it/conventional-changelog": {
92
- "preset": "angular"
96
+ "preset": "conventionalcommits"
93
97
  }
94
98
  }
95
99
  },
@@ -1,9 +1,11 @@
1
1
  import type {
2
2
  DirectEventHandler,
3
3
  Int32,
4
+ WithDefault
4
5
  } from "react-native/Libraries/Types/CodegenTypes";
5
6
  import type { HostComponent, ViewProps } from "react-native";
6
7
  import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent";
8
+
7
9
  /*
8
10
  Caution, those below are not just typescript types.
9
11
  Codegen is using them to create the corresponding C++ data types.
@@ -37,6 +39,7 @@ type MenuAction = {
37
39
  image?: string;
38
40
  imageColor?: Int32;
39
41
  displayInline?: boolean;
42
+ preferredElementSize?: WithDefault<string, 'large'>;
40
43
  attributes?: {
41
44
  destructive?: boolean;
42
45
  disabled?: boolean;
@@ -52,6 +55,7 @@ export interface NativeProps extends ViewProps {
52
55
  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
56
  title?: string;
54
57
  themeVariant?: string;
58
+ isAnchoredToRight?: boolean;
55
59
  shouldOpenOnLongPress?: boolean;
56
60
  hitSlop: {
57
61
  top: Int32;
@@ -6,11 +6,20 @@ import {
6
6
  } from "react-native";
7
7
  import type { MenuComponentRef, NativeMenuComponentProps } from "./types";
8
8
  import { forwardRef, useImperativeHandle, useRef } from "react";
9
+ import codegenNativeCommands from "react-native/Libraries/Utilities/codegenNativeCommands";
9
10
 
10
11
  const NativeMenuComponent = requireNativeComponent(
11
12
  "MenuView",
12
13
  ) as HostComponent<NativeMenuComponentProps>;
13
14
 
15
+ type RefT = React.ElementRef<typeof NativeMenuComponent>;
16
+
17
+ const Commands = codegenNativeCommands<{
18
+ show: (viewRef: RefT) => void;
19
+ }>({
20
+ supportedCommands: ["show"],
21
+ });
22
+
14
23
  const MenuComponent = forwardRef<MenuComponentRef, NativeMenuComponentProps>(
15
24
  (props, ref) => {
16
25
  const nativeRef = useRef(null);
@@ -20,11 +29,18 @@ const MenuComponent = forwardRef<MenuComponentRef, NativeMenuComponentProps>(
20
29
  () => ({
21
30
  show: () => {
22
31
  if (nativeRef.current) {
23
- const node = findNodeHandle(nativeRef.current);
24
- const command =
25
- UIManager.getViewManagerConfig("MenuView").Commands.show;
32
+ // biome-ignore lint/suspicious/noExplicitAny: React Native runtime flags like nativeFabricUIManager are not in TypeScript types. Using `any` here is intentional and safe.
33
+ const isFabric = !!(global as any).nativeFabricUIManager;
34
+
35
+ if (isFabric) {
36
+ Commands.show(nativeRef.current);
37
+ } else {
38
+ const node = findNodeHandle(nativeRef.current);
39
+ const command =
40
+ UIManager.getViewManagerConfig("MenuView").Commands.show;
26
41
 
27
- UIManager.dispatchViewManagerCommand(node, command, undefined);
42
+ UIManager.dispatchViewManagerCommand(node, command, undefined);
43
+ }
28
44
  }
29
45
  },
30
46
  }),