one
Version:
One is a React framework for web, iOS, and Android apps.
84 lines (81 loc) • 3.34 kB
JavaScript
import { jsx } from "react/jsx-runtime";
import { useControlled } from "./controlled.native.js";
import { useMemo } from "react";
import { Platform, View } from "react-native";
import NativeMenu from "./specs/OneNativeMenuNativeComponent.native.js";
import { flattenMenuItems } from "./menuItems.native.js";
import { assertSwiftUIValue } from "./generated/swiftui.native.js";
function Menu(props) {
return /* @__PURE__ */ jsx(MenuPresentation, {
...props,
presentation: "menu"
});
}
function ContextMenu(props) {
var _props_accessibilityLabel;
return /* @__PURE__ */ jsx(MenuPresentation, {
...props,
accessibilityLabel: (_props_accessibilityLabel = props.accessibilityLabel) !== null && _props_accessibilityLabel !== void 0 ? _props_accessibilityLabel : "",
presentation: "contextMenu"
});
}
function MenuPresentation(param) {
var { items, onAction, primaryAction, children, onValueChange, onPickerChange, revision = 0, menuOrder = "automatic", menuActionDismissBehavior = "automatic", disabled = false, accessibilityLabel, presentation, ...props } = param;
var iosVersion = Number.parseFloat(String(Platform.Version));
assertSwiftUIValue("MenuOrder", menuOrder, iosVersion);
assertSwiftUIValue("MenuActionDismissBehavior", menuActionDismissBehavior, iosVersion);
var nativeItems = useMemo(function() {
return flattenMenuItems(items, iosVersion);
}, [items, iosVersion]);
if (!onValueChange && nativeItems.some(function(item) {
return item.type === "toggle";
})) {
var name = presentation === "contextMenu" ? "ContextMenu" : "Menu";
throw new Error(`Swift.${name} with toggles requires onValueChange`);
}
if (!onPickerChange && nativeItems.some(function(item) {
return item.type === "picker";
})) {
throw new Error("Swift.Menu with a Picker requires onPickerChange");
}
var controlled = useControlled(function(event) {
return onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(event.id, event.value, event.sourceIndex);
}, revision);
var pickerControlled = useControlled(function(event) {
return onPickerChange === null || onPickerChange === void 0 ? void 0 : onPickerChange(event.id, event.value);
}, revision);
return /* @__PURE__ */ jsx(NativeMenu, {
...props,
items: nativeItems,
revision,
acknowledgedEvent: controlled.acknowledgedEvent,
pickerAcknowledgedEvent: pickerControlled.acknowledgedEvent,
menuOrder,
menuActionDismissBehavior,
triggerLabel: accessibilityLabel,
disabled,
hasPrimaryAction: presentation === "menu" && !!primaryAction,
presentation,
onNativeMenuAction: function onNativeMenuAction(param2) {
var { nativeEvent } = param2;
return onAction(nativeEvent.id);
},
onNativeMenuPrimaryAction: function onNativeMenuPrimaryAction() {
return primaryAction === null || primaryAction === void 0 ? void 0 : primaryAction();
},
onNativeMenuValueChange: function onNativeMenuValueChange(param2) {
var { nativeEvent } = param2;
return controlled.onNativeChange(nativeEvent);
},
onNativeMenuPickerChange: function onNativeMenuPickerChange(param2) {
var { nativeEvent } = param2;
return pickerControlled.onNativeChange(nativeEvent);
},
children: /* @__PURE__ */ jsx(View, {
collapsable: false,
children
})
});
}
export { ContextMenu, Menu };
//# sourceMappingURL=Menu.native.js.map