UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

1 lines • 4.21 kB
{"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 onPickerChange: _onPickerChange,\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 (nativeItems.some((item) => item.type === \"picker\")) {\n throw new Error(\"Menu picker items are not supported on Android\");\n }\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 ?? \"\",\n presentation: \"contextMenu\"\n }\n );\n}\nexport {\n ContextMenu,\n Menu\n};\n//# sourceMappingURL=AndroidMenu.js.map\n"],"mappings":";;;;;;AAUA,MAAM,uBAAuB,uBAAuB,sBAAsB;AAC1E,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,gBAAgB,iBAChB,eAAe,gBACf,UACA,WAAW,OACX,UAAU,WACV,WAAW,YACX,2BAA2B,4BAC3B,cACA,GAAG,aACF;CACD,MAAM,SAAS,OAAO,IAAI;CAC1B,MAAM,gBAAgB,OAAO,IAAI;CACjC,MAAM,cAAc,iBAAiB,KAAK;CAC1C,IAAI,YAAY,MAAM,SAAS,KAAK,SAAS,QAAQ,GAAG;EACtD,MAAM,IAAI,MAAM,gDAAgD;CAClE;CACA,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,eAChB,iBAAiB,gBAAgB,cAAc,UAAU,OAAO,OAClE;EACA,IAAI,aAAa,MAAM,MAAM,IAAI,MAAM,iCAAiC;EACxE,MAAM,YAAY,MAAM,MAAM,CAAC,CAAC,KAAK,WAAW,WAAW;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