one 2.0.0-beta.148.1 → 2.0.0-beta.150.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.
@@ -12,6 +12,7 @@ import dev.onejs.onenative.OneNativeComposeNodeManager
12
12
  import dev.onejs.onenative.OneNativeEdgeFadeManager
13
13
  import dev.onejs.onenative.OneNativeMaskManager
14
14
  import dev.onejs.onenative.OneNativeMenuPopupModule
15
+ import dev.onejs.onenative.OneNativeMenuTriggerManager
15
16
  import dev.onejs.onenative.OneNativePictureInPictureManager
16
17
  import dev.onejs.onenative.OneNativeSafeAreaModule
17
18
  import dev.onejs.onenative.OneNativeReservedRegionsProviderManager
@@ -72,6 +73,7 @@ class OnePackage : BaseReactPackage() {
72
73
  ): List<ViewManager<*, *>> =
73
74
  listOf(
74
75
  OneNativeComposeNodeManager(),
76
+ OneNativeMenuTriggerManager(),
75
77
  OneNativeSafeAreaProviderManager(),
76
78
  OneNativeReservedRegionsProviderManager(),
77
79
  OneNativeEdgeFadeManager(),
@@ -0,0 +1,102 @@
1
+ package dev.onejs.onenative
2
+
3
+ import android.os.SystemClock
4
+ import android.view.GestureDetector
5
+ import android.view.MotionEvent
6
+ import com.facebook.react.bridge.Arguments
7
+ import com.facebook.react.bridge.WritableMap
8
+ import com.facebook.react.uimanager.ThemedReactContext
9
+ import com.facebook.react.uimanager.UIManagerHelper
10
+ import com.facebook.react.uimanager.annotations.ReactProp
11
+ import com.facebook.react.uimanager.events.Event
12
+ import com.facebook.react.uimanager.events.NativeGestureUtil
13
+ import com.facebook.react.views.view.ReactViewGroup
14
+ import com.facebook.react.views.view.ReactViewManager
15
+
16
+ class OneNativeMenuTriggerManager : ReactViewManager() {
17
+ override fun getName(): String = "OneNativeMenuTrigger"
18
+
19
+ override fun createViewInstance(context: ThemedReactContext): ReactViewGroup =
20
+ OneNativeMenuTriggerView(context)
21
+
22
+ @ReactProp(name = "contextMenuEnabled", defaultBoolean = true)
23
+ fun setContextMenuEnabled(view: ReactViewGroup, enabled: Boolean) {
24
+ (view as OneNativeMenuTriggerView).contextMenuEnabled = enabled
25
+ }
26
+
27
+ override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any> =
28
+ (super.getExportedCustomDirectEventTypeConstants()?.toMutableMap() ?: mutableMapOf()).apply {
29
+ put("topNativeMenuLongPress", mapOf("registrationName" to "onNativeMenuLongPress"))
30
+ }
31
+ }
32
+
33
+ private class OneNativeMenuTriggerView(private val reactContext: ThemedReactContext) :
34
+ ReactViewGroup(reactContext) {
35
+ var contextMenuEnabled = true
36
+ set(value) {
37
+ field = value
38
+ isLongClickable = value
39
+ if (!value) cancelGesture()
40
+ }
41
+ private var ownsGesture = false
42
+ private val detector = GestureDetector(reactContext, object : GestureDetector.SimpleOnGestureListener() {
43
+ override fun onDown(event: MotionEvent): Boolean = true
44
+ override fun onLongPress(event: MotionEvent) {
45
+ if (!contextMenuEnabled || !isAttachedToWindow) return
46
+ ownsGesture = true
47
+ NativeGestureUtil.notifyNativeGestureStarted(this@OneNativeMenuTriggerView, event)
48
+ emitLongPress()
49
+ }
50
+ })
51
+
52
+ init {
53
+ setOnLongClickListener {
54
+ if (!contextMenuEnabled) false else {
55
+ emitLongPress()
56
+ true
57
+ }
58
+ }
59
+ }
60
+
61
+ private fun emitLongPress() {
62
+ UIManagerHelper.getEventDispatcherForReactTag(reactContext, id)?.dispatchEvent(
63
+ OneNativeMenuLongPressEvent(UIManagerHelper.getSurfaceId(this), id))
64
+ }
65
+
66
+ private fun cancelGesture() {
67
+ val now = SystemClock.uptimeMillis()
68
+ val cancel = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0f, 0f, 0)
69
+ detector.onTouchEvent(cancel)
70
+ if (ownsGesture) NativeGestureUtil.notifyNativeGestureEnded(this, cancel)
71
+ ownsGesture = false
72
+ cancel.recycle()
73
+ }
74
+
75
+ override fun onDetachedFromWindow() {
76
+ cancelGesture()
77
+ super.onDetachedFromWindow()
78
+ }
79
+
80
+ override fun dispatchTouchEvent(event: MotionEvent): Boolean {
81
+ if (contextMenuEnabled) detector.onTouchEvent(event)
82
+ val result = super.dispatchTouchEvent(event)
83
+ if (event.actionMasked == MotionEvent.ACTION_UP || event.actionMasked == MotionEvent.ACTION_CANCEL) {
84
+ if (ownsGesture) NativeGestureUtil.notifyNativeGestureEnded(this, event)
85
+ ownsGesture = false
86
+ }
87
+ return result
88
+ }
89
+
90
+ // the detector owns touch long press; the listener owns accessibility activation.
91
+ override fun onTouchEvent(event: MotionEvent): Boolean = true
92
+
93
+ override fun onInterceptTouchEvent(event: MotionEvent): Boolean =
94
+ ownsGesture || super.onInterceptTouchEvent(event)
95
+ }
96
+
97
+ private class OneNativeMenuLongPressEvent(surfaceId: Int, viewTag: Int) :
98
+ Event<OneNativeMenuLongPressEvent>(surfaceId, viewTag) {
99
+ override fun getEventName(): String = "topNativeMenuLongPress"
100
+ override fun canCoalesce(): Boolean = false
101
+ override fun getEventData(): WritableMap = Arguments.createMap()
102
+ }
@@ -28,6 +28,7 @@ var import_react = require("react");
28
28
  var import_react_native = require("react-native-web");
29
29
  var import_menuItems = require("./menuItems.cjs");
30
30
  var import_jsx_runtime = require("react/jsx-runtime");
31
+ const NativeContextTrigger = (0, import_react_native.requireNativeComponent)("OneNativeMenuTrigger");
31
32
  let popupModule;
32
33
  function popup() {
33
34
  if (popupModule === void 0) {
@@ -40,13 +41,14 @@ function popup() {
40
41
  }
41
42
  function MenuPresentation({ items, onAction, onValueChange, primaryAction: _primaryAction, children, disabled = false, revision: _revision, menuOrder: _menuOrder, menuActionDismissBehavior: _menuActionDismissBehavior, presentation, ...viewProps }) {
42
43
  const anchor = (0, import_react.useRef)(null);
44
+ const contextAnchor = (0, import_react.useRef)(null);
43
45
  const nativeItems = (0, import_menuItems.flattenMenuItems)(items);
44
46
  if (!onValueChange && nativeItems.some((item) => item.type === "toggle")) {
45
47
  throw new Error("Menu with toggles requires onValueChange");
46
48
  }
47
49
  const open = async () => {
48
50
  if (disabled) return;
49
- const anchorTag = (0, import_react_native.findNodeHandle)(anchor.current);
51
+ const anchorTag = (0, import_react_native.findNodeHandle)(presentation === "contextMenu" ? contextAnchor.current : anchor.current);
50
52
  if (anchorTag == null) throw new Error("Menu trigger has no native view");
51
53
  const selection = await popup().show(anchorTag, nativeItems);
52
54
  if (selection?.type === "action") onAction(selection.id);
@@ -54,10 +56,19 @@ function MenuPresentation({ items, onAction, onValueChange, primaryAction: _prim
54
56
  onValueChange?.(selection.id, selection.value, selection.sourceIndex);
55
57
  }
56
58
  };
59
+ if (presentation === "contextMenu") {
60
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NativeContextTrigger, {
61
+ ref: contextAnchor,
62
+ collapsable: false,
63
+ ...viewProps,
64
+ contextMenuEnabled: !disabled,
65
+ onNativeMenuLongPress: open,
66
+ children
67
+ });
68
+ }
57
69
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Pressable, {
58
70
  disabled,
59
- onPress: presentation === "menu" ? open : void 0,
60
- onLongPress: presentation === "contextMenu" ? open : void 0,
71
+ onPress: open,
61
72
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, {
62
73
  ref: anchor,
63
74
  collapsable: false,
@@ -30,6 +30,7 @@ var import_jsx_runtime = require("react/jsx-runtime");
30
30
  var import_react = require("react");
31
31
  var import_react_native = require("react-native");
32
32
  var import_menuItems = require("./menuItems.native.js");
33
+ var NativeContextTrigger = (0, import_react_native.requireNativeComponent)("OneNativeMenuTrigger");
33
34
  var popupModule;
34
35
  function popup() {
35
36
  if (popupModule === void 0) {
@@ -43,6 +44,7 @@ function popup() {
43
44
  function MenuPresentation(param) {
44
45
  var { items, onAction, onValueChange, primaryAction: _primaryAction, children, disabled = false, revision: _revision, menuOrder: _menuOrder, menuActionDismissBehavior: _menuActionDismissBehavior, presentation, ...viewProps } = param;
45
46
  var anchor = (0, import_react.useRef)(null);
47
+ var contextAnchor = (0, import_react.useRef)(null);
46
48
  var nativeItems = (0, import_menuItems.flattenMenuItems)(items);
47
49
  if (!onValueChange && nativeItems.some(function(item) {
48
50
  return item.type === "toggle";
@@ -51,7 +53,7 @@ function MenuPresentation(param) {
51
53
  }
52
54
  var open = async function() {
53
55
  if (disabled) return;
54
- var anchorTag = (0, import_react_native.findNodeHandle)(anchor.current);
56
+ var anchorTag = (0, import_react_native.findNodeHandle)(presentation === "contextMenu" ? contextAnchor.current : anchor.current);
55
57
  if (anchorTag == null) throw new Error("Menu trigger has no native view");
56
58
  var selection = await popup().show(anchorTag, nativeItems);
57
59
  if ((selection === null || selection === void 0 ? void 0 : selection.type) === "action") onAction(selection.id);
@@ -59,10 +61,19 @@ function MenuPresentation(param) {
59
61
  onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(selection.id, selection.value, selection.sourceIndex);
60
62
  }
61
63
  };
64
+ if (presentation === "contextMenu") {
65
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NativeContextTrigger, {
66
+ ref: contextAnchor,
67
+ collapsable: false,
68
+ ...viewProps,
69
+ contextMenuEnabled: !disabled,
70
+ onNativeMenuLongPress: open,
71
+ children
72
+ });
73
+ }
62
74
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Pressable, {
63
75
  disabled,
64
- onPress: presentation === "menu" ? open : void 0,
65
- onLongPress: presentation === "contextMenu" ? open : void 0,
76
+ onPress: open,
66
77
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, {
67
78
  ref: anchor,
68
79
  collapsable: false,
@@ -30,6 +30,7 @@ var import_jsx_runtime = require("react/jsx-runtime");
30
30
  var import_react = require("react");
31
31
  var import_react_native = require("react-native");
32
32
  var import_menuItems = require("./menuItems.native.js");
33
+ var NativeContextTrigger = (0, import_react_native.requireNativeComponent)("OneNativeMenuTrigger");
33
34
  var popupModule;
34
35
  function popup() {
35
36
  if (popupModule === void 0) {
@@ -43,6 +44,7 @@ function popup() {
43
44
  function MenuPresentation(param) {
44
45
  var { items, onAction, onValueChange, primaryAction: _primaryAction, children, disabled = false, revision: _revision, menuOrder: _menuOrder, menuActionDismissBehavior: _menuActionDismissBehavior, presentation, ...viewProps } = param;
45
46
  var anchor = (0, import_react.useRef)(null);
47
+ var contextAnchor = (0, import_react.useRef)(null);
46
48
  var nativeItems = (0, import_menuItems.flattenMenuItems)(items);
47
49
  if (!onValueChange && nativeItems.some(function(item) {
48
50
  return item.type === "toggle";
@@ -51,7 +53,7 @@ function MenuPresentation(param) {
51
53
  }
52
54
  var open = async function() {
53
55
  if (disabled) return;
54
- var anchorTag = (0, import_react_native.findNodeHandle)(anchor.current);
56
+ var anchorTag = (0, import_react_native.findNodeHandle)(presentation === "contextMenu" ? contextAnchor.current : anchor.current);
55
57
  if (anchorTag == null) throw new Error("Menu trigger has no native view");
56
58
  var selection = await popup().show(anchorTag, nativeItems);
57
59
  if ((selection === null || selection === void 0 ? void 0 : selection.type) === "action") onAction(selection.id);
@@ -59,10 +61,19 @@ function MenuPresentation(param) {
59
61
  onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(selection.id, selection.value, selection.sourceIndex);
60
62
  }
61
63
  };
64
+ if (presentation === "contextMenu") {
65
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NativeContextTrigger, {
66
+ ref: contextAnchor,
67
+ collapsable: false,
68
+ ...viewProps,
69
+ contextMenuEnabled: !disabled,
70
+ onNativeMenuLongPress: open,
71
+ children
72
+ });
73
+ }
62
74
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Pressable, {
63
75
  disabled,
64
- onPress: presentation === "menu" ? open : void 0,
65
- onLongPress: presentation === "contextMenu" ? open : void 0,
76
+ onPress: open,
66
77
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, {
67
78
  ref: anchor,
68
79
  collapsable: false,
@@ -1 +1 @@
1
- {"version":3,"file":"AndroidMenu.native.js","names":[],"sources":["cjs/platform/AndroidMenu.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar AndroidMenu_exports = {};\n__export(AndroidMenu_exports, {\n ContextMenu: () => ContextMenu,\n Menu: () => Menu\n});\nmodule.exports = __toCommonJS(AndroidMenu_exports);\nvar import_jsx_runtime = require(\"react/jsx-runtime\");\nvar import_react = require(\"react\");\nvar import_react_native = require(\"react-native\");\nvar import_menuItems = require(\"./menuItems\");\nvar popupModule;\nfunction popup() {\n if (popupModule === void 0) {\n popupModule = import_react_native.TurboModuleRegistry.get(\"OneNativeMenuPopup\");\n }\n if (!popupModule) {\n throw new Error(\"Menu needs an Android build\");\n }\n return popupModule;\n}\nfunction MenuPresentation(param) {\n var { items, onAction, onValueChange, primaryAction: _primaryAction, children, disabled = false, revision: _revision, menuOrder: _menuOrder, menuActionDismissBehavior: _menuActionDismissBehavior, presentation, ...viewProps } = param;\n var anchor = (0, import_react.useRef)(null);\n var nativeItems = (0, import_menuItems.flattenMenuItems)(items);\n if (!onValueChange && nativeItems.some(function(item) {\n return item.type === \"toggle\";\n })) {\n throw new Error(\"Menu with toggles requires onValueChange\");\n }\n var open = async function() {\n if (disabled) return;\n var anchorTag = (0, import_react_native.findNodeHandle)(anchor.current);\n if (anchorTag == null) throw new Error(\"Menu trigger has no native view\");\n var selection = await popup().show(anchorTag, nativeItems);\n if ((selection === null || selection === void 0 ? void 0 : selection.type) === \"action\") onAction(selection.id);\n if ((selection === null || selection === void 0 ? void 0 : selection.type) === \"toggle\") {\n onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(selection.id, selection.value, selection.sourceIndex);\n }\n };\n return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Pressable, {\n disabled,\n onPress: presentation === \"menu\" ? open : void 0,\n onLongPress: presentation === \"contextMenu\" ? open : void 0,\n children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, {\n ref: anchor,\n collapsable: false,\n ...viewProps,\n children\n })\n });\n}\nfunction Menu(props) {\n return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPresentation, {\n ...props,\n presentation: \"menu\"\n });\n}\nfunction ContextMenu(props) {\n var _props_accessibilityLabel;\n return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPresentation, {\n ...props,\n accessibilityLabel: (_props_accessibilityLabel = props.accessibilityLabel) !== null && _props_accessibilityLabel !== void 0 ? _props_accessibilityLabel : \"\",\n presentation: \"contextMenu\"\n });\n}\n//# sourceMappingURL=AndroidMenu.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,M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IAAI,KAAK,IAAI,UAAU,UAAU,UAAU,SAAS,UAAU,EAAE;EAC9G,KAAK,cAAc,QAAQ,cAAc,KAAK,IAAI,KAAK,IAAI,UAAU,UAAU,UAAU;GACvF,kBAAkB,QAAQ,kBAAkB,KAAK,IAAI,KAAK,IAAI,cAAc,UAAU,IAAI,UAAU,OAAO,UAAU,WAAW;EAClI;CACF;CACA,OAAuB,iBAAC,GAAG,mBAAmB,IAAG,CAAE,oBAAoB,WAAW;EAChF;EACA,SAAS,iBAAiB,SAAS,OAAO,KAAK;EAC/C,aAAa,iBAAiB,gBAAgB,OAAO,KAAK;EAC1D,UAA0B,iBAAC,GAAG,mBAAmB,IAAG,CAAE,oBAAoB,MAAM;GAC9E,KAAK;GACL,aAAa;GACb,GAAG;GACH;EACF,CAAC;CACH,CAAC;AACH;AACA,SAAS,KAAK,OAAO;CACnB,OAAuB,iBAAC,GAAG,mBAAmB,IAAG,CAAE,kBAAkB;EACnE,GAAG;EACH,cAAc;CAChB,CAAC;AACH;AACA,SAAS,YAAY,OAAO;CAC1B,IAAI;CACJ,OAAuB,iBAAC,GAAG,mBAAmB,IAAG,CAAE,kBAAkB;EACnE,GAAG;EACH,qBAAqB,4BAA4B,MAAM,wBAAwB,QAAQ,8BAA8B,KAAK,IAAI,4BAA4B;EAC1J,cAAc;CAChB,CAAC;AACH"}
1
+ {"version":3,"file":"AndroidMenu.native.js","names":[],"sources":["cjs/platform/AndroidMenu.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar AndroidMenu_exports = {};\n__export(AndroidMenu_exports, {\n ContextMenu: () => ContextMenu,\n Menu: () => Menu\n});\nmodule.exports = __toCommonJS(AndroidMenu_exports);\nvar import_jsx_runtime = require(\"react/jsx-runtime\");\nvar import_react = require(\"react\");\nvar import_react_native = require(\"react-native\");\nvar import_menuItems = require(\"./menuItems\");\nvar NativeContextTrigger = (0, import_react_native.requireNativeComponent)(\"OneNativeMenuTrigger\");\nvar popupModule;\nfunction popup() {\n if (popupModule === void 0) {\n popupModule = import_react_native.TurboModuleRegistry.get(\"OneNativeMenuPopup\");\n }\n if (!popupModule) {\n throw new Error(\"Menu needs an Android build\");\n }\n return popupModule;\n}\nfunction MenuPresentation(param) {\n var { items, onAction, onValueChange, primaryAction: _primaryAction, children, disabled = false, revision: _revision, menuOrder: _menuOrder, menuActionDismissBehavior: _menuActionDismissBehavior, presentation, ...viewProps } = param;\n var anchor = (0, import_react.useRef)(null);\n var contextAnchor = (0, import_react.useRef)(null);\n var nativeItems = (0, import_menuItems.flattenMenuItems)(items);\n if (!onValueChange && nativeItems.some(function(item) {\n return item.type === \"toggle\";\n })) {\n throw new Error(\"Menu with toggles requires onValueChange\");\n }\n var open = async function() {\n if (disabled) return;\n var anchorTag = (0, import_react_native.findNodeHandle)(presentation === \"contextMenu\" ? contextAnchor.current : anchor.current);\n if (anchorTag == null) throw new Error(\"Menu trigger has no native view\");\n var selection = await popup().show(anchorTag, nativeItems);\n if ((selection === null || selection === void 0 ? void 0 : selection.type) === \"action\") onAction(selection.id);\n if ((selection === null || selection === void 0 ? void 0 : selection.type) === \"toggle\") {\n onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(selection.id, selection.value, selection.sourceIndex);\n }\n };\n if (presentation === \"contextMenu\") {\n return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NativeContextTrigger, {\n ref: contextAnchor,\n collapsable: false,\n ...viewProps,\n contextMenuEnabled: !disabled,\n onNativeMenuLongPress: open,\n children\n });\n }\n return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Pressable, {\n disabled,\n onPress: open,\n children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, {\n ref: anchor,\n collapsable: false,\n ...viewProps,\n children\n })\n });\n}\nfunction Menu(props) {\n return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPresentation, {\n ...props,\n presentation: \"menu\"\n });\n}\nfunction ContextMenu(props) {\n var _props_accessibilityLabel;\n return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MenuPresentation, {\n ...props,\n accessibilityLabel: (_props_accessibilityLabel = props.accessibilityLabel) !== null && _props_accessibilityLabel !== void 0 ? _props_accessibilityLabel : \"\",\n presentation: \"contextMenu\"\n });\n}\n//# sourceMappingURL=AndroidMenu.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU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,WAAW;EACzD,KAAK,cAAc,QAAQ,cAAc,KAAK,IAAI,KAAK,IAAI,UAAU,UAAU,UAAU,SAAS,UAAU,EAAE;EAC9G,KAAK,cAAc,QAAQ,cAAc,KAAK,IAAI,KAAK,IAAI,UAAU,UAAU,UAAU;GACvF,kBAAkB,QAAQ,kBAAkB,KAAK,IAAI,KAAK,IAAI,cAAc,UAAU,IAAI,UAAU,OAAO,UAAU,WAAW;EAClI;CACF;CACA,IAAI,iBAAiB,eAAe;EAClC,OAAuB,iBAAC,GAAG,mBAAmB,IAAG,CAAE,sBAAsB;GACvE,KAAK;GACL,aAAa;GACb,GAAG;GACH,oBAAoB,CAAC;GACrB,uBAAuB;GACvB;EACF,CAAC;CACH;CACA,OAAuB,iBAAC,GAAG,mBAAmB,IAAG,CAAE,oBAAoB,WAAW;EAChF;EACA,SAAS;EACT,UAA0B,iBAAC,GAAG,mBAAmB,IAAG,CAAE,oBAAoB,MAAM;GAC9E,KAAK;GACL,aAAa;GACb,GAAG;GACH;EACF,CAAC;CACH,CAAC;AACH;AACA,SAAS,KAAK,OAAO;CACnB,OAAuB,iBAAC,GAAG,mBAAmB,IAAG,CAAE,kBAAkB;EACnE,GAAG;EACH,cAAc;CAChB,CAAC;AACH;AACA,SAAS,YAAY,OAAO;CAC1B,IAAI;CACJ,OAAuB,iBAAC,GAAG,mBAAmB,IAAG,CAAE,kBAAkB;EACnE,GAAG;EACH,qBAAqB,4BAA4B,MAAM,wBAAwB,QAAQ,8BAA8B,KAAK,IAAI,4BAA4B;EAC1J,cAAc;CAChB,CAAC;AACH"}
@@ -1,8 +1,9 @@
1
1
  import { useRef } from "react";
2
- import { Pressable, TurboModuleRegistry, View, findNodeHandle } from "react-native-web";
2
+ import { Pressable, TurboModuleRegistry, View, findNodeHandle, requireNativeComponent } from "react-native-web";
3
3
  import { flattenMenuItems } from "./menuItems.mjs";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
 
6
+ const NativeContextTrigger = requireNativeComponent("OneNativeMenuTrigger");
6
7
  let popupModule;
7
8
  function popup() {
8
9
  if (popupModule === void 0) {
@@ -15,13 +16,14 @@ function popup() {
15
16
  }
16
17
  function MenuPresentation({ items, onAction, onValueChange, primaryAction: _primaryAction, children, disabled = false, revision: _revision, menuOrder: _menuOrder, menuActionDismissBehavior: _menuActionDismissBehavior, presentation, ...viewProps }) {
17
18
  const anchor = useRef(null);
19
+ const contextAnchor = useRef(null);
18
20
  const nativeItems = flattenMenuItems(items);
19
21
  if (!onValueChange && nativeItems.some((item) => item.type === "toggle")) {
20
22
  throw new Error("Menu with toggles requires onValueChange");
21
23
  }
22
24
  const open = async () => {
23
25
  if (disabled) return;
24
- const anchorTag = findNodeHandle(anchor.current);
26
+ const anchorTag = findNodeHandle(presentation === "contextMenu" ? contextAnchor.current : anchor.current);
25
27
  if (anchorTag == null) throw new Error("Menu trigger has no native view");
26
28
  const selection = await popup().show(anchorTag, nativeItems);
27
29
  if (selection?.type === "action") onAction(selection.id);
@@ -29,10 +31,19 @@ function MenuPresentation({ items, onAction, onValueChange, primaryAction: _prim
29
31
  onValueChange?.(selection.id, selection.value, selection.sourceIndex);
30
32
  }
31
33
  };
34
+ if (presentation === "contextMenu") {
35
+ return /* @__PURE__ */ jsx(NativeContextTrigger, {
36
+ ref: contextAnchor,
37
+ collapsable: false,
38
+ ...viewProps,
39
+ contextMenuEnabled: !disabled,
40
+ onNativeMenuLongPress: open,
41
+ children
42
+ });
43
+ }
32
44
  return /* @__PURE__ */ jsx(Pressable, {
33
45
  disabled,
34
- onPress: presentation === "menu" ? open : void 0,
35
- onLongPress: presentation === "contextMenu" ? open : void 0,
46
+ onPress: open,
36
47
  children: /* @__PURE__ */ jsx(View, {
37
48
  ref: anchor,
38
49
  collapsable: false,
@@ -1 +1 @@
1
- {"version":3,"file":"AndroidMenu.js","names":[],"sources":["esm/platform/AndroidMenu.js"],"sourcesContent":["import { useRef } from \"react\";\nimport { findNodeHandle, Pressable, TurboModuleRegistry, View } from \"react-native-web\";\nimport { flattenMenuItems } from \"./menuItems\";\nimport { jsx } from \"react/jsx-runtime\";\nlet popupModule;\nfunction popup() {\n if (popupModule === void 0) {\n popupModule = TurboModuleRegistry.get(\"OneNativeMenuPopup\");\n }\n if (!popupModule) {\n throw new Error(\"Menu needs an Android build\");\n }\n return popupModule;\n}\nfunction MenuPresentation({\n items,\n onAction,\n onValueChange,\n primaryAction: _primaryAction,\n children,\n disabled = false,\n revision: _revision,\n menuOrder: _menuOrder,\n menuActionDismissBehavior: _menuActionDismissBehavior,\n presentation,\n ...viewProps\n}) {\n const anchor = useRef(null);\n const nativeItems = flattenMenuItems(items);\n if (!onValueChange && nativeItems.some((item) => item.type === \"toggle\")) {\n throw new Error(\"Menu with toggles requires onValueChange\");\n }\n const open = async () => {\n if (disabled) return;\n const anchorTag = findNodeHandle(anchor.current);\n if (anchorTag == null) throw new Error(\"Menu trigger has no native view\");\n const selection = await popup().show(anchorTag, nativeItems);\n if (selection?.type === \"action\") onAction(selection.id);\n if (selection?.type === \"toggle\") {\n onValueChange?.(selection.id, selection.value, selection.sourceIndex);\n }\n };\n return /* @__PURE__ */ jsx(\n Pressable,\n {\n disabled,\n onPress: presentation === \"menu\" ? open : void 0,\n onLongPress: presentation === \"contextMenu\" ? open : void 0,\n children: /* @__PURE__ */ jsx(View, { ref: anchor, collapsable: false, ...viewProps, children })\n }\n );\n}\nfunction Menu(props) {\n return /* @__PURE__ */ jsx(MenuPresentation, { ...props, presentation: \"menu\" });\n}\nfunction ContextMenu(props) {\n return /* @__PURE__ */ jsx(\n MenuPresentation,\n {\n ...props,\n accessibilityLabel: props.accessibilityLabel ?? \"\",\n presentation: \"contextMenu\"\n }\n );\n}\nexport {\n ContextMenu,\n Menu\n};\n//# sourceMappingURL=AndroidMenu.js.map\n"],"mappings":";;;;;;AAIA,IAAI;AACJ,SAAS,QAAQ;CACf,IAAI,gBAAgB,KAAK,GAAG;EAC1B,cAAc,oBAAoB,IAAI,oBAAoB;CAC5D;CACA,IAAI,CAAC,aAAa;EAChB,MAAM,IAAI,MAAM,6BAA6B;CAC/C;CACA,OAAO;AACT;AACA,SAAS,iBAAiB,EACxB,OACA,UACA,eACA,eAAe,gBACf,UACA,WAAW,OACX,UAAU,WACV,WAAW,YACX,2BAA2B,4BAC3B,cACA,GAAG,aACF;CACD,MAAM,SAAS,OAAO,IAAI;CAC1B,MAAM,cAAc,iBAAiB,KAAK;CAC1C,IAAI,CAAC,iBAAiB,YAAY,MAAM,SAAS,KAAK,SAAS,QAAQ,GAAG;EACxE,MAAM,IAAI,MAAM,0CAA0C;CAC5D;CACA,MAAM,OAAO,YAAY;EACvB,IAAI,UAAU;EACd,MAAM,YAAY,eAAe,OAAO,OAAO;EAC/C,IAAI,aAAa,MAAM,MAAM,IAAI,MAAM,iCAAiC;EACxE,MAAM,YAAY,MAAM,MAAM,CAAC,CAAC,KAAK,WAAW,WAAW;EAC3D,IAAI,WAAW,SAAS,UAAU,SAAS,UAAU,EAAE;EACvD,IAAI,WAAW,SAAS,UAAU;GAChC,gBAAgB,UAAU,IAAI,UAAU,OAAO,UAAU,WAAW;EACtE;CACF;CACA,OAAuB,oBACrB,WACA;EACE;EACA,SAAS,iBAAiB,SAAS,OAAO,KAAK;EAC/C,aAAa,iBAAiB,gBAAgB,OAAO,KAAK;EAC1D,UAA0B,oBAAI,MAAM;GAAE,KAAK;GAAQ,aAAa;GAAO,GAAG;GAAW;EAAS,CAAC;CACjG,CACF;AACF;AACA,SAAS,KAAK,OAAO;CACnB,OAAuB,oBAAI,kBAAkB;EAAE,GAAG;EAAO,cAAc;CAAO,CAAC;AACjF;AACA,SAAS,YAAY,OAAO;CAC1B,OAAuB,oBACrB,kBACA;EACE,GAAG;EACH,oBAAoB,MAAM,sBAAsB;EAChD,cAAc;CAChB,CACF;AACF"}
1
+ {"version":3,"file":"AndroidMenu.js","names":[],"sources":["esm/platform/AndroidMenu.js"],"sourcesContent":["import { useRef } from \"react\";\nimport {\n findNodeHandle,\n Pressable,\n requireNativeComponent,\n TurboModuleRegistry,\n View\n} from \"react-native-web\";\nimport { flattenMenuItems } from \"./menuItems\";\nimport { jsx } from \"react/jsx-runtime\";\nconst NativeContextTrigger = requireNativeComponent(\"OneNativeMenuTrigger\");\nlet popupModule;\nfunction popup() {\n if (popupModule === void 0) {\n popupModule = TurboModuleRegistry.get(\"OneNativeMenuPopup\");\n }\n if (!popupModule) {\n throw new Error(\"Menu needs an Android build\");\n }\n return popupModule;\n}\nfunction MenuPresentation({\n items,\n onAction,\n onValueChange,\n primaryAction: _primaryAction,\n children,\n disabled = false,\n revision: _revision,\n menuOrder: _menuOrder,\n menuActionDismissBehavior: _menuActionDismissBehavior,\n presentation,\n ...viewProps\n}) {\n const anchor = useRef(null);\n const contextAnchor = useRef(null);\n const nativeItems = flattenMenuItems(items);\n if (!onValueChange && nativeItems.some((item) => item.type === \"toggle\")) {\n throw new Error(\"Menu with toggles requires onValueChange\");\n }\n const open = async () => {\n if (disabled) return;\n const anchorTag = findNodeHandle(\n presentation === \"contextMenu\" ? contextAnchor.current : anchor.current\n );\n if (anchorTag == null) throw new Error(\"Menu trigger has no native view\");\n const selection = await popup().show(anchorTag, nativeItems);\n if (selection?.type === \"action\") onAction(selection.id);\n if (selection?.type === \"toggle\") {\n onValueChange?.(selection.id, selection.value, selection.sourceIndex);\n }\n };\n if (presentation === \"contextMenu\") {\n return /* @__PURE__ */ jsx(\n NativeContextTrigger,\n {\n ref: contextAnchor,\n collapsable: false,\n ...viewProps,\n contextMenuEnabled: !disabled,\n onNativeMenuLongPress: open,\n children\n }\n );\n }\n return /* @__PURE__ */ jsx(Pressable, { disabled, onPress: open, children: /* @__PURE__ */ jsx(View, { ref: anchor, collapsable: false, ...viewProps, children }) });\n}\nfunction Menu(props) {\n return /* @__PURE__ */ jsx(MenuPresentation, { ...props, presentation: \"menu\" });\n}\nfunction ContextMenu(props) {\n return /* @__PURE__ */ jsx(\n MenuPresentation,\n {\n ...props,\n accessibilityLabel: props.accessibilityLabel ?? \"\",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,aAAa;GAAO,GAAG;GAAW;EAAS,CAAC;CAAE,CAAC;AACrK;AACA,SAAS,KAAK,OAAO;CACnB,OAAuB,oBAAI,kBAAkB;EAAE,GAAG;EAAO,cAAc;CAAO,CAAC;AACjF;AACA,SAAS,YAAY,OAAO;CAC1B,OAAuB,oBACrB,kBACA;EACE,GAAG;EACH,oBAAoB,MAAM,sBAAsB;EAChD,cAAc;CAChB,CACF;AACF"}
@@ -1,8 +1,9 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { useRef } from "react";
3
- import { Pressable, TurboModuleRegistry, View, findNodeHandle } from "react-native";
3
+ import { Pressable, TurboModuleRegistry, View, findNodeHandle, requireNativeComponent } from "react-native";
4
4
  import { flattenMenuItems } from "./menuItems.native.js";
5
5
 
6
+ var NativeContextTrigger = requireNativeComponent("OneNativeMenuTrigger");
6
7
  var popupModule;
7
8
  function popup() {
8
9
  if (popupModule === void 0) {
@@ -16,6 +17,7 @@ function popup() {
16
17
  function MenuPresentation(param) {
17
18
  var { items, onAction, onValueChange, primaryAction: _primaryAction, children, disabled = false, revision: _revision, menuOrder: _menuOrder, menuActionDismissBehavior: _menuActionDismissBehavior, presentation, ...viewProps } = param;
18
19
  var anchor = useRef(null);
20
+ var contextAnchor = useRef(null);
19
21
  var nativeItems = flattenMenuItems(items);
20
22
  if (!onValueChange && nativeItems.some(function(item) {
21
23
  return item.type === "toggle";
@@ -24,7 +26,7 @@ function MenuPresentation(param) {
24
26
  }
25
27
  var open = async function() {
26
28
  if (disabled) return;
27
- var anchorTag = findNodeHandle(anchor.current);
29
+ var anchorTag = findNodeHandle(presentation === "contextMenu" ? contextAnchor.current : anchor.current);
28
30
  if (anchorTag == null) throw new Error("Menu trigger has no native view");
29
31
  var selection = await popup().show(anchorTag, nativeItems);
30
32
  if ((selection === null || selection === void 0 ? void 0 : selection.type) === "action") onAction(selection.id);
@@ -32,10 +34,19 @@ function MenuPresentation(param) {
32
34
  onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(selection.id, selection.value, selection.sourceIndex);
33
35
  }
34
36
  };
37
+ if (presentation === "contextMenu") {
38
+ return /* @__PURE__ */ jsx(NativeContextTrigger, {
39
+ ref: contextAnchor,
40
+ collapsable: false,
41
+ ...viewProps,
42
+ contextMenuEnabled: !disabled,
43
+ onNativeMenuLongPress: open,
44
+ children
45
+ });
46
+ }
35
47
  return /* @__PURE__ */ jsx(Pressable, {
36
48
  disabled,
37
- onPress: presentation === "menu" ? open : void 0,
38
- onLongPress: presentation === "contextMenu" ? open : void 0,
49
+ onPress: open,
39
50
  children: /* @__PURE__ */ jsx(View, {
40
51
  ref: anchor,
41
52
  collapsable: false,
@@ -1 +1 @@
1
- {"version":3,"file":"AndroidMenu.native.js","names":[],"sources":["esm/platform/AndroidMenu.native.js"],"sourcesContent":["import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useRef } from \"react\";\nimport { findNodeHandle, Pressable, TurboModuleRegistry, View } from \"react-native\";\nimport { flattenMenuItems } from \"./menuItems\";\nvar popupModule;\nfunction popup() {\n if (popupModule === void 0) {\n popupModule = TurboModuleRegistry.get(\"OneNativeMenuPopup\");\n }\n if (!popupModule) {\n throw new Error(\"Menu needs an Android build\");\n }\n return popupModule;\n}\nfunction MenuPresentation(param) {\n var { items, onAction, onValueChange, primaryAction: _primaryAction, children, disabled = false, revision: _revision, menuOrder: _menuOrder, menuActionDismissBehavior: _menuActionDismissBehavior, presentation, ...viewProps } = param;\n var anchor = useRef(null);\n var nativeItems = flattenMenuItems(items);\n if (!onValueChange && nativeItems.some(function(item) {\n return item.type === \"toggle\";\n })) {\n throw new Error(\"Menu with toggles requires onValueChange\");\n }\n var open = async function() {\n if (disabled) return;\n var anchorTag = findNodeHandle(anchor.current);\n if (anchorTag == null) throw new Error(\"Menu trigger has no native view\");\n var selection = await popup().show(anchorTag, nativeItems);\n if ((selection === null || selection === void 0 ? void 0 : selection.type) === \"action\") onAction(selection.id);\n if ((selection === null || selection === void 0 ? void 0 : selection.type) === \"toggle\") {\n onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(selection.id, selection.value, selection.sourceIndex);\n }\n };\n return /* @__PURE__ */ _jsx(Pressable, {\n disabled,\n onPress: presentation === \"menu\" ? open : void 0,\n onLongPress: presentation === \"contextMenu\" ? open : void 0,\n children: /* @__PURE__ */ _jsx(View, {\n ref: anchor,\n collapsable: false,\n ...viewProps,\n children\n })\n });\n}\nfunction Menu(props) {\n return /* @__PURE__ */ _jsx(MenuPresentation, {\n ...props,\n presentation: \"menu\"\n });\n}\nfunction ContextMenu(props) {\n var _props_accessibilityLabel;\n return /* @__PURE__ */ _jsx(MenuPresentation, {\n ...props,\n accessibilityLabel: (_props_accessibilityLabel = props.accessibilityLabel) !== null && _props_accessibilityLabel !== void 0 ? _props_accessibilityLabel : \"\",\n presentation: \"contextMenu\"\n });\n}\nexport {\n ContextMenu,\n Menu\n};\n//# sourceMappingURL=AndroidMenu.js.map\n"],"mappings":";;;;;;AAIA,IAAI;AACJ,SAAS,QAAQ;CACf,IAAI,gBAAgB,KAAK,GAAG;EAC1B,cAAc,oBAAoB,IAAI,oBAAoB;CAC5D;CACA,IAAI,CAAC,aAAa;EAChB,MAAM,IAAI,MAAM,6BAA6B;CAC/C;CACA,OAAO;AACT;AACA,SAAS,iBAAiB,OAAO;CAC/B,IAAI,EAAE,OAAO,UAAU,eAAe,eAAe,gBAAgB,UAAU,WAAW,OAAO,UAAU,WAAW,WAAW,YAAY,2BAA2B,4BAA4B,cAAc,GAAG,cAAc;CACnO,IAAI,SAAS,OAAO,IAAI;CACxB,IAAI,cAAc,iBAAiB,KAAK;CACxC,IAAI,CAAC,iBAAiB,YAAY,KAAK,SAAS,MAAM;EACpD,OAAO,KAAK,SAAS;CACvB,CAAC,GAAG;EACF,MAAM,IAAI,MAAM,0CAA0C;CAC5D;CACA,IAAI,OAAO,iBAAiB;EAC1B,IAAI,UAAU;EACd,IAAI,YAAY,eAAe,OAAO,OAAO;EAC7C,IAAI,aAAa,MAAM,MAAM,IAAI,MAAM,iCAAiC;EACxE,IAAI,YAAY,MAAM,MAAM,CAAC,CAAC,KAAK,WAAW,WAAW;EACzD,KAAK,cAAc,QAAQ,cAAc,KAAK,IAAI,KAAK,IAAI,UAAU,UAAU,UAAU,SAAS,UAAU,EAAE;EAC9G,KAAK,cAAc,QAAQ,cAAc,KAAK,IAAI,KAAK,IAAI,UAAU,UAAU,UAAU;GACvF,kBAAkB,QAAQ,kBAAkB,KAAK,IAAI,KAAK,IAAI,cAAc,UAAU,IAAI,UAAU,OAAO,UAAU,WAAW;EAClI;CACF;CACA,OAAuB,oBAAK,WAAW;EACrC;EACA,SAAS,iBAAiB,SAAS,OAAO,KAAK;EAC/C,aAAa,iBAAiB,gBAAgB,OAAO,KAAK;EAC1D,UAA0B,oBAAK,MAAM;GACnC,KAAK;GACL,aAAa;GACb,GAAG;GACH;EACF,CAAC;CACH,CAAC;AACH;AACA,SAAS,KAAK,OAAO;CACnB,OAAuB,oBAAK,kBAAkB;EAC5C,GAAG;EACH,cAAc;CAChB,CAAC;AACH;AACA,SAAS,YAAY,OAAO;CAC1B,IAAI;CACJ,OAAuB,oBAAK,kBAAkB;EAC5C,GAAG;EACH,qBAAqB,4BAA4B,MAAM,wBAAwB,QAAQ,8BAA8B,KAAK,IAAI,4BAA4B;EAC1J,cAAc;CAChB,CAAC;AACH"}
1
+ {"version":3,"file":"AndroidMenu.native.js","names":[],"sources":["esm/platform/AndroidMenu.native.js"],"sourcesContent":["import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useRef } from \"react\";\nimport { findNodeHandle, Pressable, requireNativeComponent, TurboModuleRegistry, View } from \"react-native\";\nimport { flattenMenuItems } from \"./menuItems\";\nvar NativeContextTrigger = requireNativeComponent(\"OneNativeMenuTrigger\");\nvar popupModule;\nfunction popup() {\n if (popupModule === void 0) {\n popupModule = TurboModuleRegistry.get(\"OneNativeMenuPopup\");\n }\n if (!popupModule) {\n throw new Error(\"Menu needs an Android build\");\n }\n return popupModule;\n}\nfunction MenuPresentation(param) {\n var { items, onAction, onValueChange, primaryAction: _primaryAction, children, disabled = false, revision: _revision, menuOrder: _menuOrder, menuActionDismissBehavior: _menuActionDismissBehavior, presentation, ...viewProps } = param;\n var anchor = useRef(null);\n var contextAnchor = useRef(null);\n var nativeItems = flattenMenuItems(items);\n if (!onValueChange && nativeItems.some(function(item) {\n return item.type === \"toggle\";\n })) {\n throw new Error(\"Menu with toggles requires onValueChange\");\n }\n var open = async function() {\n if (disabled) return;\n var anchorTag = findNodeHandle(presentation === \"contextMenu\" ? contextAnchor.current : anchor.current);\n if (anchorTag == null) throw new Error(\"Menu trigger has no native view\");\n var selection = await popup().show(anchorTag, nativeItems);\n if ((selection === null || selection === void 0 ? void 0 : selection.type) === \"action\") onAction(selection.id);\n if ((selection === null || selection === void 0 ? void 0 : selection.type) === \"toggle\") {\n onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(selection.id, selection.value, selection.sourceIndex);\n }\n };\n if (presentation === \"contextMenu\") {\n return /* @__PURE__ */ _jsx(NativeContextTrigger, {\n ref: contextAnchor,\n collapsable: false,\n ...viewProps,\n contextMenuEnabled: !disabled,\n onNativeMenuLongPress: open,\n children\n });\n }\n return /* @__PURE__ */ _jsx(Pressable, {\n disabled,\n onPress: open,\n children: /* @__PURE__ */ _jsx(View, {\n ref: anchor,\n collapsable: false,\n ...viewProps,\n children\n })\n });\n}\nfunction Menu(props) {\n return /* @__PURE__ */ _jsx(MenuPresentation, {\n ...props,\n presentation: \"menu\"\n });\n}\nfunction ContextMenu(props) {\n var _props_accessibilityLabel;\n return /* @__PURE__ */ _jsx(MenuPresentation, {\n ...props,\n accessibilityLabel: (_props_accessibilityLabel = props.accessibilityLabel) !== null && _props_accessibilityLabel !== void 0 ? _props_accessibilityLabel : \"\",\n presentation: \"contextMenu\"\n });\n}\nexport {\n ContextMenu,\n Menu\n};\n//# sourceMappingURL=AndroidMenu.js.map\n"],"mappings":";;;;;;AAIA,IAAI,uBAAuB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BAAK,WAAW;EACrC;EACA,SAAS;EACT,UAA0B,oBAAK,MAAM;GACnC,KAAK;GACL,aAAa;GACb,GAAG;GACH;EACF,CAAC;CACH,CAAC;AACH;AACA,SAAS,KAAK,OAAO;CACnB,OAAuB,oBAAK,kBAAkB;EAC5C,GAAG;EACH,cAAc;CAChB,CAAC;AACH;AACA,SAAS,YAAY,OAAO;CAC1B,IAAI;CACJ,OAAuB,oBAAK,kBAAkB;EAC5C,GAAG;EACH,qBAAqB,4BAA4B,MAAM,wBAAwB,QAAQ,8BAA8B,KAAK,IAAI,4BAA4B;EAC1J,cAAc;CAChB,CAAC;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "one",
3
- "version": "2.0.0-beta.148.1",
3
+ "version": "2.0.0-beta.150.1",
4
4
  "description": "One is a React framework for web, iOS, and Android apps.",
5
5
  "license": "BSD-3-Clause",
6
6
  "sideEffects": [
@@ -209,18 +209,18 @@
209
209
  "@react-navigation/native-stack": "8.0.0-alpha.52",
210
210
  "@react-navigation/routers": "8.0.0-alpha.17",
211
211
  "@ungap/structured-clone": "^1.2.0",
212
- "@vxrn/color-scheme": "2.0.0-beta.148.1",
213
- "@vxrn/compiler": "2.0.0-beta.148.1",
214
- "@vxrn/resolve": "2.0.0-beta.148.1",
215
- "@vxrn/tslib-lite": "2.0.0-beta.148.1",
216
- "@vxrn/use-isomorphic-layout-effect": "2.0.0-beta.148.1",
217
- "@vxrn/utils": "2.0.0-beta.148.1",
218
- "@vxrn/vite-plugin-metro": "2.0.0-beta.148.1",
212
+ "@vxrn/color-scheme": "2.0.0-beta.150.1",
213
+ "@vxrn/compiler": "2.0.0-beta.150.1",
214
+ "@vxrn/resolve": "2.0.0-beta.150.1",
215
+ "@vxrn/tslib-lite": "2.0.0-beta.150.1",
216
+ "@vxrn/use-isomorphic-layout-effect": "2.0.0-beta.150.1",
217
+ "@vxrn/utils": "2.0.0-beta.150.1",
218
+ "@vxrn/vite-plugin-metro": "2.0.0-beta.150.1",
219
219
  "babel-dead-code-elimination": "1.0.10",
220
220
  "babel-plugin-module-resolver": "^5.0.2",
221
221
  "citty": "^0.1.6",
222
222
  "core-js": "^3.38.1",
223
- "create-vxrn": "2.0.0-beta.148.1",
223
+ "create-vxrn": "2.0.0-beta.150.1",
224
224
  "escape-string-regexp": "^5.0.0",
225
225
  "fast-deep-equal": "^3.1.3",
226
226
  "fast-glob": "^3.3.3",
@@ -242,7 +242,7 @@
242
242
  "tsconfig-paths": "^4",
243
243
  "use-latest-callback": "^0.2.3",
244
244
  "vite": "^8.2.2",
245
- "vxrn": "2.0.0-beta.148.1",
245
+ "vxrn": "2.0.0-beta.150.1",
246
246
  "web-streams-polyfill": "^4.3.0",
247
247
  "ws": "^8.21.0",
248
248
  "xxhashjs": "^0.2.2"
@@ -6,6 +6,7 @@ import { expect, it, vi } from 'vitest'
6
6
  vi.mock('react-native', () => ({
7
7
  findNodeHandle: vi.fn(),
8
8
  Pressable: 'Pressable',
9
+ requireNativeComponent: vi.fn((name: string) => name),
9
10
  TurboModuleRegistry: { get: vi.fn() },
10
11
  View: 'View',
11
12
  }))
@@ -1,10 +1,24 @@
1
- import { useRef } from 'react'
2
- import { findNodeHandle, Pressable, TurboModuleRegistry, View } from 'react-native'
1
+ import { useRef, type ComponentRef } from 'react'
2
+ import {
3
+ findNodeHandle,
4
+ Pressable,
5
+ requireNativeComponent,
6
+ TurboModuleRegistry,
7
+ View,
8
+ type ViewProps,
9
+ } from 'react-native'
3
10
  import { flattenMenuItems } from './menuItems'
4
11
  import type { NativeMenuItem } from './specs/OneNativeMenuNativeComponent'
5
12
  import type { ContextMenuProps, MenuProps } from './types'
6
13
  import type { TurboModule } from 'react-native'
7
14
 
15
+ const NativeContextTrigger = requireNativeComponent<
16
+ ViewProps & {
17
+ contextMenuEnabled: boolean
18
+ onNativeMenuLongPress: () => void
19
+ }
20
+ >('OneNativeMenuTrigger')
21
+
8
22
  type Selection = {
9
23
  type: 'action' | 'toggle'
10
24
  id: string
@@ -42,6 +56,7 @@ function MenuPresentation({
42
56
  ...viewProps
43
57
  }: MenuProps & { presentation: 'menu' | 'contextMenu' }) {
44
58
  const anchor = useRef<View>(null)
59
+ const contextAnchor = useRef<ComponentRef<typeof NativeContextTrigger>>(null)
45
60
  const nativeItems = flattenMenuItems(items)
46
61
  if (!onValueChange && nativeItems.some((item) => item.type === 'toggle')) {
47
62
  throw new Error('Menu with toggles requires onValueChange')
@@ -49,7 +64,9 @@ function MenuPresentation({
49
64
 
50
65
  const open = async () => {
51
66
  if (disabled) return
52
- const anchorTag = findNodeHandle(anchor.current)
67
+ const anchorTag = findNodeHandle(
68
+ presentation === 'contextMenu' ? contextAnchor.current : anchor.current
69
+ )
53
70
  if (anchorTag == null) throw new Error('Menu trigger has no native view')
54
71
  const selection = await popup().show(anchorTag, nativeItems)
55
72
  if (selection?.type === 'action') onAction(selection.id)
@@ -58,12 +75,22 @@ function MenuPresentation({
58
75
  }
59
76
  }
60
77
 
78
+ if (presentation === 'contextMenu') {
79
+ return (
80
+ <NativeContextTrigger
81
+ ref={contextAnchor}
82
+ collapsable={false}
83
+ {...viewProps}
84
+ contextMenuEnabled={!disabled}
85
+ onNativeMenuLongPress={open}
86
+ >
87
+ {children}
88
+ </NativeContextTrigger>
89
+ )
90
+ }
91
+
61
92
  return (
62
- <Pressable
63
- disabled={disabled}
64
- onPress={presentation === 'menu' ? open : undefined}
65
- onLongPress={presentation === 'contextMenu' ? open : undefined}
66
- >
93
+ <Pressable disabled={disabled} onPress={open}>
67
94
  <View ref={anchor} collapsable={false} {...viewProps}>
68
95
  {children}
69
96
  </View>
@@ -1 +1 @@
1
- {"version":3,"file":"AndroidMenu.d.ts","sourceRoot":"","sources":["../../src/platform/AndroidMenu.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAqE1D,wBAAgB,IAAI,CAAC,KAAK,EAAE,SAAS,2CAEpC;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,2CAQlD"}
1
+ {"version":3,"file":"AndroidMenu.d.ts","sourceRoot":"","sources":["../../src/platform/AndroidMenu.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAyF1D,wBAAgB,IAAI,CAAC,KAAK,EAAE,SAAS,2CAEpC;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,2CAQlD"}