@tamagui/native 3.0.0-beta.1161.1 → 3.0.0-beta.1173.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/dist/cjs/expoUIMenuView.cjs +82 -0
- package/dist/cjs/expoUIMenuView.native.cjs +100 -0
- package/dist/cjs/expoUIMenuView.native.js +102 -0
- package/dist/cjs/expoUIMenuView.native.js.map +1 -0
- package/dist/cjs/setup-expo-ui-menu.cjs +5 -1
- package/dist/cjs/setup-expo-ui-menu.native.cjs +5 -1
- package/dist/cjs/setup-expo-ui-menu.native.js +5 -1
- package/dist/cjs/setup-expo-ui-menu.native.js.map +1 -1
- package/dist/esm/expoUIMenuView.mjs +63 -0
- package/dist/esm/expoUIMenuView.mjs.map +1 -0
- package/dist/esm/expoUIMenuView.native.js +73 -0
- package/dist/esm/expoUIMenuView.native.js.map +1 -0
- package/dist/esm/setup-expo-ui-menu.mjs +5 -1
- package/dist/esm/setup-expo-ui-menu.mjs.map +1 -1
- package/dist/esm/setup-expo-ui-menu.native.js +5 -1
- package/dist/esm/setup-expo-ui-menu.native.js.map +1 -1
- package/package.json +4 -4
- package/src/expoUIMenuAdapter.tsx +2 -2
- package/src/expoUIMenuView.tsx +124 -0
- package/src/setup-expo-ui-menu.ts +5 -1
- package/types/expoUIMenuAdapter.d.ts +27 -1
- package/types/expoUIMenuAdapter.d.ts.map +2 -2
- package/types/expoUIMenuView.d.ts +24 -0
- package/types/expoUIMenuView.d.ts.map +11 -0
- package/types/setup-expo-ui-menu.d.ts.map +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var expoUIMenuView_exports = {};
|
|
22
|
+
__export(expoUIMenuView_exports, { createExpoUIMenuView: () => createExpoUIMenuView });
|
|
23
|
+
module.exports = __toCommonJS(expoUIMenuView_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
function createExpoUIMenuView({ swiftUI, modifiers }) {
|
|
26
|
+
const { Button, ContextMenu, Host, Menu, RNHostView, Section, Toggle } = swiftUI;
|
|
27
|
+
function renderAction(action, onPressAction) {
|
|
28
|
+
if (action.attributes?.hidden) return null;
|
|
29
|
+
const { subactions, displayInline, state, attributes, image, title } = action;
|
|
30
|
+
const systemImage = typeof image === "string" ? image : void 0;
|
|
31
|
+
if (subactions && subactions.length > 0) {
|
|
32
|
+
const children = subactions.map((sub) => renderAction(sub, onPressAction));
|
|
33
|
+
if (displayInline) {
|
|
34
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Section, {
|
|
35
|
+
title,
|
|
36
|
+
children
|
|
37
|
+
}, action.id);
|
|
38
|
+
}
|
|
39
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu, {
|
|
40
|
+
label: title,
|
|
41
|
+
systemImage,
|
|
42
|
+
children
|
|
43
|
+
}, action.id);
|
|
44
|
+
}
|
|
45
|
+
const fire = () => onPressAction?.({ nativeEvent: { event: action.id } });
|
|
46
|
+
const itemModifiers = attributes?.disabled ? [modifiers.disabled(true)] : void 0;
|
|
47
|
+
if (state === "on" || state === "off") {
|
|
48
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Toggle, {
|
|
49
|
+
label: title,
|
|
50
|
+
systemImage,
|
|
51
|
+
isOn: state === "on",
|
|
52
|
+
onIsOnChange: fire,
|
|
53
|
+
modifiers: itemModifiers
|
|
54
|
+
}, action.id);
|
|
55
|
+
}
|
|
56
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
|
|
57
|
+
label: title,
|
|
58
|
+
systemImage,
|
|
59
|
+
role: attributes?.destructive ? "destructive" : void 0,
|
|
60
|
+
modifiers: itemModifiers,
|
|
61
|
+
onPress: fire
|
|
62
|
+
}, action.id);
|
|
63
|
+
}
|
|
64
|
+
return function ExpoUIMenuView({ actions, onPressAction, shouldOpenOnLongPress, title, children }) {
|
|
65
|
+
const items = actions.map((action) => renderAction(action, onPressAction));
|
|
66
|
+
const body = title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Section, {
|
|
67
|
+
title,
|
|
68
|
+
children: items
|
|
69
|
+
}) : items;
|
|
70
|
+
const trigger = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RNHostView, {
|
|
71
|
+
matchContents: true,
|
|
72
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children })
|
|
73
|
+
});
|
|
74
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Host, {
|
|
75
|
+
ignoreSafeArea: "all",
|
|
76
|
+
children: shouldOpenOnLongPress ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ContextMenu, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContextMenu.Trigger, { children: trigger }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContextMenu.Items, { children: body })] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu, {
|
|
77
|
+
label: trigger,
|
|
78
|
+
children: body
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
+
get: () => from[key],
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
25
|
+
value: mod,
|
|
26
|
+
enumerable: true
|
|
27
|
+
}) : target, mod));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var expoUIMenuView_exports = {};
|
|
30
|
+
__export(expoUIMenuView_exports, { createExpoUIMenuView: () => createExpoUIMenuView });
|
|
31
|
+
module.exports = __toCommonJS(expoUIMenuView_exports);
|
|
32
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
+
var import_react = __toESM(require("react"), 1);
|
|
34
|
+
function createExpoUIMenuView(param) {
|
|
35
|
+
var { swiftUI, modifiers } = param;
|
|
36
|
+
var { Button, ContextMenu, Host, Menu, RNHostView, Section, Toggle } = swiftUI;
|
|
37
|
+
function renderAction(action, onPressAction) {
|
|
38
|
+
var _action_attributes;
|
|
39
|
+
if ((_action_attributes = action.attributes) === null || _action_attributes === void 0 ? void 0 : _action_attributes.hidden) return null;
|
|
40
|
+
var { subactions, displayInline, state, attributes, image, title } = action;
|
|
41
|
+
var systemImage = typeof image === "string" ? image : void 0;
|
|
42
|
+
if (subactions && subactions.length > 0) {
|
|
43
|
+
var children = subactions.map(function(sub) {
|
|
44
|
+
return renderAction(sub, onPressAction);
|
|
45
|
+
});
|
|
46
|
+
if (displayInline) {
|
|
47
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Section, {
|
|
48
|
+
title,
|
|
49
|
+
children
|
|
50
|
+
}, action.id);
|
|
51
|
+
}
|
|
52
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu, {
|
|
53
|
+
label: title,
|
|
54
|
+
systemImage,
|
|
55
|
+
children
|
|
56
|
+
}, action.id);
|
|
57
|
+
}
|
|
58
|
+
var fire = function() {
|
|
59
|
+
return onPressAction === null || onPressAction === void 0 ? void 0 : onPressAction({ nativeEvent: { event: action.id } });
|
|
60
|
+
};
|
|
61
|
+
var itemModifiers = (attributes === null || attributes === void 0 ? void 0 : attributes.disabled) ? [modifiers.disabled(true)] : void 0;
|
|
62
|
+
if (state === "on" || state === "off") {
|
|
63
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Toggle, {
|
|
64
|
+
label: title,
|
|
65
|
+
systemImage,
|
|
66
|
+
isOn: state === "on",
|
|
67
|
+
onIsOnChange: fire,
|
|
68
|
+
modifiers: itemModifiers
|
|
69
|
+
}, action.id);
|
|
70
|
+
}
|
|
71
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
|
|
72
|
+
label: title,
|
|
73
|
+
systemImage,
|
|
74
|
+
role: (attributes === null || attributes === void 0 ? void 0 : attributes.destructive) ? "destructive" : void 0,
|
|
75
|
+
modifiers: itemModifiers,
|
|
76
|
+
onPress: fire
|
|
77
|
+
}, action.id);
|
|
78
|
+
}
|
|
79
|
+
return function ExpoUIMenuView(param2) {
|
|
80
|
+
var { actions, onPressAction, shouldOpenOnLongPress, title, children } = param2;
|
|
81
|
+
var items = actions.map(function(action) {
|
|
82
|
+
return renderAction(action, onPressAction);
|
|
83
|
+
});
|
|
84
|
+
var body = title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Section, {
|
|
85
|
+
title,
|
|
86
|
+
children: items
|
|
87
|
+
}) : items;
|
|
88
|
+
var trigger = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RNHostView, {
|
|
89
|
+
matchContents: true,
|
|
90
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children })
|
|
91
|
+
});
|
|
92
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Host, {
|
|
93
|
+
ignoreSafeArea: "all",
|
|
94
|
+
children: shouldOpenOnLongPress ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ContextMenu, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContextMenu.Trigger, { children: trigger }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContextMenu.Items, { children: body })] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu, {
|
|
95
|
+
label: trigger,
|
|
96
|
+
children: body
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
+
get: () => from[key],
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
25
|
+
value: mod,
|
|
26
|
+
enumerable: true
|
|
27
|
+
}) : target, mod));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var expoUIMenuView_exports = {};
|
|
30
|
+
__export(expoUIMenuView_exports, { createExpoUIMenuView: () => createExpoUIMenuView });
|
|
31
|
+
module.exports = __toCommonJS(expoUIMenuView_exports);
|
|
32
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
+
var import_react = __toESM(require("react"), 1);
|
|
34
|
+
function createExpoUIMenuView(param) {
|
|
35
|
+
var { swiftUI, modifiers } = param;
|
|
36
|
+
var { Button, ContextMenu, Host, Menu, RNHostView, Section, Toggle } = swiftUI;
|
|
37
|
+
function renderAction(action, onPressAction) {
|
|
38
|
+
var _action_attributes;
|
|
39
|
+
if ((_action_attributes = action.attributes) === null || _action_attributes === void 0 ? void 0 : _action_attributes.hidden) return null;
|
|
40
|
+
var { subactions, displayInline, state, attributes, image, title } = action;
|
|
41
|
+
var systemImage = typeof image === "string" ? image : void 0;
|
|
42
|
+
if (subactions && subactions.length > 0) {
|
|
43
|
+
var children = subactions.map(function(sub) {
|
|
44
|
+
return renderAction(sub, onPressAction);
|
|
45
|
+
});
|
|
46
|
+
if (displayInline) {
|
|
47
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Section, {
|
|
48
|
+
title,
|
|
49
|
+
children
|
|
50
|
+
}, action.id);
|
|
51
|
+
}
|
|
52
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu, {
|
|
53
|
+
label: title,
|
|
54
|
+
systemImage,
|
|
55
|
+
children
|
|
56
|
+
}, action.id);
|
|
57
|
+
}
|
|
58
|
+
var fire = function() {
|
|
59
|
+
return onPressAction === null || onPressAction === void 0 ? void 0 : onPressAction({ nativeEvent: { event: action.id } });
|
|
60
|
+
};
|
|
61
|
+
var itemModifiers = (attributes === null || attributes === void 0 ? void 0 : attributes.disabled) ? [modifiers.disabled(true)] : void 0;
|
|
62
|
+
if (state === "on" || state === "off") {
|
|
63
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Toggle, {
|
|
64
|
+
label: title,
|
|
65
|
+
systemImage,
|
|
66
|
+
isOn: state === "on",
|
|
67
|
+
onIsOnChange: fire,
|
|
68
|
+
modifiers: itemModifiers
|
|
69
|
+
}, action.id);
|
|
70
|
+
}
|
|
71
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
|
|
72
|
+
label: title,
|
|
73
|
+
systemImage,
|
|
74
|
+
role: (attributes === null || attributes === void 0 ? void 0 : attributes.destructive) ? "destructive" : void 0,
|
|
75
|
+
modifiers: itemModifiers,
|
|
76
|
+
onPress: fire
|
|
77
|
+
}, action.id);
|
|
78
|
+
}
|
|
79
|
+
return function ExpoUIMenuView(param2) {
|
|
80
|
+
var { actions, onPressAction, shouldOpenOnLongPress, title, children } = param2;
|
|
81
|
+
var items = actions.map(function(action) {
|
|
82
|
+
return renderAction(action, onPressAction);
|
|
83
|
+
});
|
|
84
|
+
var body = title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Section, {
|
|
85
|
+
title,
|
|
86
|
+
children: items
|
|
87
|
+
}) : items;
|
|
88
|
+
var trigger = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RNHostView, {
|
|
89
|
+
matchContents: true,
|
|
90
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children })
|
|
91
|
+
});
|
|
92
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Host, {
|
|
93
|
+
ignoreSafeArea: "all",
|
|
94
|
+
children: shouldOpenOnLongPress ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ContextMenu, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContextMenu.Trigger, { children: trigger }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContextMenu.Items, { children: body })] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu, {
|
|
95
|
+
label: trigger,
|
|
96
|
+
children: body
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//# sourceMappingURL=expoUIMenuView.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expoUIMenuView.native.js","names":[],"sources":["cjs/expoUIMenuView.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar expoUIMenuView_exports = {};\n__export(expoUIMenuView_exports, {\n createExpoUIMenuView: () => createExpoUIMenuView\n});\nmodule.exports = __toCommonJS(expoUIMenuView_exports);\nvar import_jsx_runtime = require(\"react/jsx-runtime\");\nvar import_react = __toESM(require(\"react\"), 1);\nfunction createExpoUIMenuView(param) {\n var { swiftUI, modifiers } = param;\n var { Button, ContextMenu, Host, Menu, RNHostView, Section, Toggle } = swiftUI;\n function renderAction(action, onPressAction) {\n var _action_attributes;\n if ((_action_attributes = action.attributes) === null || _action_attributes === void 0 ? void 0 : _action_attributes.hidden) return null;\n var { subactions, displayInline, state, attributes, image, title } = action;\n var systemImage = typeof image === \"string\" ? image : void 0;\n if (subactions && subactions.length > 0) {\n var children = subactions.map(function(sub) {\n return renderAction(sub, onPressAction);\n });\n if (displayInline) {\n return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Section, {\n title,\n children\n }, action.id);\n }\n return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu, {\n label: title,\n systemImage,\n children\n }, action.id);\n }\n var fire = function() {\n return onPressAction === null || onPressAction === void 0 ? void 0 : onPressAction({\n nativeEvent: {\n event: action.id\n }\n });\n };\n var itemModifiers = (attributes === null || attributes === void 0 ? void 0 : attributes.disabled) ? [\n modifiers.disabled(true)\n ] : void 0;\n if (state === \"on\" || state === \"off\") {\n return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Toggle, {\n label: title,\n systemImage,\n isOn: state === \"on\",\n onIsOnChange: fire,\n modifiers: itemModifiers\n }, action.id);\n }\n return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {\n label: title,\n systemImage,\n role: (attributes === null || attributes === void 0 ? void 0 : attributes.destructive) ? \"destructive\" : void 0,\n modifiers: itemModifiers,\n onPress: fire\n }, action.id);\n }\n return function ExpoUIMenuView(param2) {\n var { actions, onPressAction, shouldOpenOnLongPress, title, children } = param2;\n var items = actions.map(function(action) {\n return renderAction(action, onPressAction);\n });\n var body = title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Section, {\n title,\n children: items\n }) : items;\n var trigger = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RNHostView, {\n matchContents: true,\n children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {\n children\n })\n });\n return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Host, {\n ignoreSafeArea: \"all\",\n children: shouldOpenOnLongPress ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ContextMenu, {\n children: [\n /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContextMenu.Trigger, {\n children: trigger\n }),\n /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContextMenu.Items, {\n children: body\n })\n ]\n }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Menu, {\n label: trigger,\n children: body\n })\n });\n };\n}\n//# sourceMappingURL=expoUIMenuView.js.map\n"],"mappings":";;;AACA,IAAI,WAAW,OAAO;AACtB,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO;AAC1B,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,WAAW,KAAK,YAAY,YAAY,SAAS,OAAO,OAAO,SAAS,aAAa,GAAG,CAAC,IAAI,CAAC,GAAG,YAKnG,cAAc,CAAC,OAAO,CAAC,IAAI,aAAa,UAAU,QAAQ,WAAW;CAAE,OAAO;CAAK,YAAY;AAAK,CAAC,IAAI,QACzG,GACF;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,yBAAyB,CAAC;AAC9B,SAAS,wBAAwB,EAC/B,4BAA4B,qBAC9B,CAAC;AACD,OAAO,UAAU,aAAa,sBAAsB;AACpD,IAAI,qBAAqB,QAAQ,mBAAmB;AACpD,IAAI,eAAe,QAAQ,QAAQ,OAAO,GAAG,CAAC;AAC9C,SAAS,qBAAqB,OAAO;CACnC,IAAI,EAAE,SAAS,cAAc;CAC7B,IAAI,EAAE,QAAQ,aAAa,MAAM,MAAM,YAAY,SAAS,WAAW;CACvE,SAAS,aAAa,QAAQ,eAAe;EAC3C,IAAI;EACJ,KAAK,qBAAqB,OAAO,gBAAgB,QAAQ,uBAAuB,KAAK,IAAI,KAAK,IAAI,mBAAmB,QAAQ,OAAO;EACpI,IAAI,EAAE,YAAY,eAAe,OAAO,YAAY,OAAO,UAAU;EACrE,IAAI,cAAc,OAAO,UAAU,WAAW,QAAQ,KAAK;EAC3D,IAAI,cAAc,WAAW,SAAS,GAAG;GACvC,IAAI,WAAW,WAAW,IAAI,SAAS,KAAK;IAC1C,OAAO,aAAa,KAAK,aAAa;GACxC,CAAC;GACD,IAAI,eAAe;IACjB,OAAuB,iBAAC,GAAG,mBAAmB,IAAG,CAAE,SAAS;KAC1D;KACA;IACF,GAAG,OAAO,EAAE;GACd;GACA,OAAuB,iBAAC,GAAG,mBAAmB,IAAG,CAAE,MAAM;IACvD,OAAO;IACP;IACA;GACF,GAAG,OAAO,EAAE;EACd;EACA,IAAI,OAAO,WAAW;GACpB,OAAO,kBAAkB,QAAQ,kBAAkB,KAAK,IAAI,KAAK,IAAI,cAAc,EACjF,aAAa,EACX,OAAO,OAAO,GAChB,EACF,CAAC;EACH;EACA,IAAI,iBAAiB,eAAe,QAAQ,eAAe,KAAK,IAAI,KAAK,IAAI,WAAW,YAAY,CAClG,UAAU,SAAS,IAAI,CACzB,IAAI,KAAK;EACT,IAAI,UAAU,QAAQ,UAAU,OAAO;GACrC,OAAuB,iBAAC,GAAG,mBAAmB,IAAG,CAAE,QAAQ;IACzD,OAAO;IACP;IACA,MAAM,UAAU;IAChB,cAAc;IACd,WAAW;GACb,GAAG,OAAO,EAAE;EACd;EACA,OAAuB,iBAAC,GAAG,mBAAmB,IAAG,CAAE,QAAQ;GACzD,OAAO;GACP;GACA,OAAO,eAAe,QAAQ,eAAe,KAAK,IAAI,KAAK,IAAI,WAAW,eAAe,gBAAgB,KAAK;GAC9G,WAAW;GACX,SAAS;EACX,GAAG,OAAO,EAAE;CACd;CACA,OAAO,SAAS,eAAe,QAAQ;EACrC,IAAI,EAAE,SAAS,eAAe,uBAAuB,OAAO,aAAa;EACzE,IAAI,QAAQ,QAAQ,IAAI,SAAS,QAAQ;GACvC,OAAO,aAAa,QAAQ,aAAa;EAC3C,CAAC;EACD,IAAI,OAAO,QAAwB,iBAAC,GAAG,mBAAmB,IAAG,CAAE,SAAS;GACtE;GACA,UAAU;EACZ,CAAC,IAAI;EACL,IAAI,UAA0B,iBAAC,GAAG,mBAAmB,IAAG,CAAE,YAAY;GACpE,eAAe;GACf,UAA0B,iBAAC,GAAG,mBAAmB,IAAG,CAAE,mBAAmB,UAAU,EACjF,SACF,CAAC;EACH,CAAC;EACD,OAAuB,iBAAC,GAAG,mBAAmB,IAAG,CAAE,MAAM;GACvD,gBAAgB;GAChB,UAAU,wBAAwC,iBAAC,GAAG,mBAAmB,KAAI,CAAE,aAAa,EAC1F,UAAU,CACQ,iBAAC,GAAG,mBAAmB,IAAG,CAAE,YAAY,SAAS,EAC/D,UAAU,QACZ,CAAC,GACe,iBAAC,GAAG,mBAAmB,IAAG,CAAE,YAAY,OAAO,EAC7D,UAAU,KACZ,CAAC,CACH,EACF,CAAC,IAAoB,iBAAC,GAAG,mBAAmB,IAAG,CAAE,MAAM;IACrD,OAAO;IACP,UAAU;GACZ,CAAC;EACH,CAAC;CACH;AACF"}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
var import_expoUIMenuAdapter = require("./expoUIMenuAdapter.cjs");
|
|
2
|
+
var import_expoUIMenuView = require("./expoUIMenuView.cjs");
|
|
2
3
|
var import_nativeMenuState = require("./nativeMenuState.cjs");
|
|
3
4
|
function setup() {
|
|
4
5
|
let MenuView;
|
|
5
6
|
try {
|
|
6
|
-
MenuView =
|
|
7
|
+
MenuView = (0, import_expoUIMenuView.createExpoUIMenuView)({
|
|
8
|
+
swiftUI: require("@expo/ui/swift-ui"),
|
|
9
|
+
modifiers: require("@expo/ui/swift-ui/modifiers")
|
|
10
|
+
});
|
|
7
11
|
} catch (error) {
|
|
8
12
|
if (process.env.NODE_ENV === "development") {
|
|
9
13
|
console.warn("Error setting up Expo UI native menus", error);
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var import_expoUIMenuAdapter = require("./expoUIMenuAdapter.native.js");
|
|
4
|
+
var import_expoUIMenuView = require("./expoUIMenuView.native.js");
|
|
4
5
|
var import_nativeMenuState = require("./nativeMenuState.native.js");
|
|
5
6
|
function setup() {
|
|
6
7
|
var MenuView;
|
|
7
8
|
try {
|
|
8
|
-
MenuView =
|
|
9
|
+
MenuView = (0, import_expoUIMenuView.createExpoUIMenuView)({
|
|
10
|
+
swiftUI: require("@expo/ui/swift-ui"),
|
|
11
|
+
modifiers: require("@expo/ui/swift-ui/modifiers")
|
|
12
|
+
});
|
|
9
13
|
} catch (error) {
|
|
10
14
|
if (process.env.NODE_ENV === "development") {
|
|
11
15
|
console.warn("Error setting up Expo UI native menus", error);
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var import_expoUIMenuAdapter = require("./expoUIMenuAdapter.native.js");
|
|
4
|
+
var import_expoUIMenuView = require("./expoUIMenuView.native.js");
|
|
4
5
|
var import_nativeMenuState = require("./nativeMenuState.native.js");
|
|
5
6
|
function setup() {
|
|
6
7
|
var MenuView;
|
|
7
8
|
try {
|
|
8
|
-
MenuView =
|
|
9
|
+
MenuView = (0, import_expoUIMenuView.createExpoUIMenuView)({
|
|
10
|
+
swiftUI: require("@expo/ui/swift-ui"),
|
|
11
|
+
modifiers: require("@expo/ui/swift-ui/modifiers")
|
|
12
|
+
});
|
|
9
13
|
} catch (error) {
|
|
10
14
|
if (process.env.NODE_ENV === "development") {
|
|
11
15
|
console.warn("Error setting up Expo UI native menus", error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-expo-ui-menu.native.js","names":[],"sources":["cjs/setup-expo-ui-menu.native.js"],"sourcesContent":["\"use strict\";\nvar import_expoUIMenuAdapter = require(\"./expoUIMenuAdapter\");\nvar import_nativeMenuState = require(\"./nativeMenuState\");\nfunction setup() {\n var MenuView;\n try {\n MenuView = require(\"@expo/ui/
|
|
1
|
+
{"version":3,"file":"setup-expo-ui-menu.native.js","names":[],"sources":["cjs/setup-expo-ui-menu.native.js"],"sourcesContent":["\"use strict\";\nvar import_expoUIMenuAdapter = require(\"./expoUIMenuAdapter\");\nvar import_expoUIMenuView = require(\"./expoUIMenuView\");\nvar import_nativeMenuState = require(\"./nativeMenuState\");\nfunction setup() {\n var MenuView;\n try {\n MenuView = (0, import_expoUIMenuView.createExpoUIMenuView)({\n swiftUI: require(\"@expo/ui/swift-ui\"),\n modifiers: require(\"@expo/ui/swift-ui/modifiers\")\n });\n } catch (error) {\n if (process.env.NODE_ENV === \"development\") {\n console.warn(\"Error setting up Expo UI native menus\", error);\n }\n return;\n }\n (0, import_nativeMenuState.registerNativeMenuAdapter)((0, import_expoUIMenuAdapter.createExpoUIMenuAdapter)({\n MenuView\n }));\n}\nsetup();\n//# sourceMappingURL=setup-expo-ui-menu.js.map\n"],"mappings":";;;AACA,IAAI,2BAA2B,QAAQ,+BAAqB;AAC5D,IAAI,wBAAwB,QAAQ,4BAAkB;AACtD,IAAI,yBAAyB,QAAQ,6BAAmB;AACxD,SAAS,QAAQ;CACf,IAAI;CACJ,IAAI;EACF,YAAY,GAAG,sBAAsB,qBAAoB,CAAE;GACzD,SAAS,QAAQ,mBAAmB;GACpC,WAAW,QAAQ,6BAA6B;EAClD,CAAC;CACH,SAAS,OAAO;EACd,IAAI,QAAQ,IAAI,aAAa,eAAe;GAC1C,QAAQ,KAAK,yCAAyC,KAAK;EAC7D;EACA;CACF;CACA,CAAC,GAAG,uBAAuB,0BAAyB,EAAG,GAAG,yBAAyB,wBAAuB,CAAE,EAC1G,SACF,CAAC,CAAC;AACJ;AACA,MAAM"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
|
|
3
|
+
function createExpoUIMenuView({ swiftUI, modifiers }) {
|
|
4
|
+
const { Button, ContextMenu, Host, Menu, RNHostView, Section, Toggle } = swiftUI;
|
|
5
|
+
function renderAction(action, onPressAction) {
|
|
6
|
+
if (action.attributes?.hidden) return null;
|
|
7
|
+
const { subactions, displayInline, state, attributes, image, title } = action;
|
|
8
|
+
const systemImage = typeof image === "string" ? image : void 0;
|
|
9
|
+
if (subactions && subactions.length > 0) {
|
|
10
|
+
const children = subactions.map((sub) => renderAction(sub, onPressAction));
|
|
11
|
+
if (displayInline) {
|
|
12
|
+
return /* @__PURE__ */ jsx(Section, {
|
|
13
|
+
title,
|
|
14
|
+
children
|
|
15
|
+
}, action.id);
|
|
16
|
+
}
|
|
17
|
+
return /* @__PURE__ */ jsx(Menu, {
|
|
18
|
+
label: title,
|
|
19
|
+
systemImage,
|
|
20
|
+
children
|
|
21
|
+
}, action.id);
|
|
22
|
+
}
|
|
23
|
+
const fire = () => onPressAction?.({ nativeEvent: { event: action.id } });
|
|
24
|
+
const itemModifiers = attributes?.disabled ? [modifiers.disabled(true)] : void 0;
|
|
25
|
+
if (state === "on" || state === "off") {
|
|
26
|
+
return /* @__PURE__ */ jsx(Toggle, {
|
|
27
|
+
label: title,
|
|
28
|
+
systemImage,
|
|
29
|
+
isOn: state === "on",
|
|
30
|
+
onIsOnChange: fire,
|
|
31
|
+
modifiers: itemModifiers
|
|
32
|
+
}, action.id);
|
|
33
|
+
}
|
|
34
|
+
return /* @__PURE__ */ jsx(Button, {
|
|
35
|
+
label: title,
|
|
36
|
+
systemImage,
|
|
37
|
+
role: attributes?.destructive ? "destructive" : void 0,
|
|
38
|
+
modifiers: itemModifiers,
|
|
39
|
+
onPress: fire
|
|
40
|
+
}, action.id);
|
|
41
|
+
}
|
|
42
|
+
return function ExpoUIMenuView({ actions, onPressAction, shouldOpenOnLongPress, title, children }) {
|
|
43
|
+
const items = actions.map((action) => renderAction(action, onPressAction));
|
|
44
|
+
const body = title ? /* @__PURE__ */ jsx(Section, {
|
|
45
|
+
title,
|
|
46
|
+
children: items
|
|
47
|
+
}) : items;
|
|
48
|
+
const trigger = /* @__PURE__ */ jsx(RNHostView, {
|
|
49
|
+
matchContents: true,
|
|
50
|
+
children: /* @__PURE__ */ jsx(Fragment, { children })
|
|
51
|
+
});
|
|
52
|
+
return /* @__PURE__ */ jsx(Host, {
|
|
53
|
+
ignoreSafeArea: "all",
|
|
54
|
+
children: shouldOpenOnLongPress ? /* @__PURE__ */ jsxs(ContextMenu, { children: [/* @__PURE__ */ jsx(ContextMenu.Trigger, { children: trigger }), /* @__PURE__ */ jsx(ContextMenu.Items, { children: body })] }) : /* @__PURE__ */ jsx(Menu, {
|
|
55
|
+
label: trigger,
|
|
56
|
+
children: body
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { createExpoUIMenuView };
|
|
63
|
+
//# sourceMappingURL=expoUIMenuView.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expoUIMenuView.js","names":[],"sources":["esm/expoUIMenuView.js"],"sourcesContent":["import { Fragment, jsx, jsxs } from \"react/jsx-runtime\";\nfunction createExpoUIMenuView({\n swiftUI,\n modifiers\n}) {\n const { Button, ContextMenu, Host, Menu, RNHostView, Section, Toggle } = swiftUI;\n function renderAction(action, onPressAction) {\n if (action.attributes?.hidden) return null;\n const { subactions, displayInline, state, attributes, image, title } = action;\n const systemImage = typeof image === \"string\" ? image : void 0;\n if (subactions && subactions.length > 0) {\n const children = subactions.map((sub) => renderAction(sub, onPressAction));\n if (displayInline) {\n return /* @__PURE__ */ jsx(Section, { title, children }, action.id);\n }\n return /* @__PURE__ */ jsx(Menu, { label: title, systemImage, children }, action.id);\n }\n const fire = () => onPressAction?.({ nativeEvent: { event: action.id } });\n const itemModifiers = attributes?.disabled ? [modifiers.disabled(true)] : void 0;\n if (state === \"on\" || state === \"off\") {\n return /* @__PURE__ */ jsx(\n Toggle,\n {\n label: title,\n systemImage,\n isOn: state === \"on\",\n onIsOnChange: fire,\n modifiers: itemModifiers\n },\n action.id\n );\n }\n return /* @__PURE__ */ jsx(\n Button,\n {\n label: title,\n systemImage,\n role: attributes?.destructive ? \"destructive\" : void 0,\n modifiers: itemModifiers,\n onPress: fire\n },\n action.id\n );\n }\n return function ExpoUIMenuView({\n actions,\n onPressAction,\n shouldOpenOnLongPress,\n title,\n children\n }) {\n const items = actions.map((action) => renderAction(action, onPressAction));\n const body = title ? /* @__PURE__ */ jsx(Section, { title, children: items }) : items;\n const trigger = /* @__PURE__ */ jsx(RNHostView, { matchContents: true, children: /* @__PURE__ */ jsx(Fragment, { children }) });\n return /* @__PURE__ */ jsx(Host, { ignoreSafeArea: \"all\", children: shouldOpenOnLongPress ? /* @__PURE__ */ jsxs(ContextMenu, { children: [\n /* @__PURE__ */ jsx(ContextMenu.Trigger, { children: trigger }),\n /* @__PURE__ */ jsx(ContextMenu.Items, { children: body })\n ] }) : /* @__PURE__ */ jsx(Menu, { label: trigger, children: body }) });\n };\n}\nexport {\n createExpoUIMenuView\n};\n//# sourceMappingURL=expoUIMenuView.js.map\n"],"mappings":";;;AACA,SAAS,qBAAqB,EAC5B,SACA,aACC;CACD,MAAM,EAAE,QAAQ,aAAa,MAAM,MAAM,YAAY,SAAS,WAAW;CACzE,SAAS,aAAa,QAAQ,eAAe;EAC3C,IAAI,OAAO,YAAY,QAAQ,OAAO;EACtC,MAAM,EAAE,YAAY,eAAe,OAAO,YAAY,OAAO,UAAU;EACvE,MAAM,cAAc,OAAO,UAAU,WAAW,QAAQ,KAAK;EAC7D,IAAI,cAAc,WAAW,SAAS,GAAG;GACvC,MAAM,WAAW,WAAW,KAAK,QAAQ,aAAa,KAAK,aAAa,CAAC;GACzE,IAAI,eAAe;IACjB,OAAuB,oBAAI,SAAS;KAAE;KAAO;IAAS,GAAG,OAAO,EAAE;GACpE;GACA,OAAuB,oBAAI,MAAM;IAAE,OAAO;IAAO;IAAa;GAAS,GAAG,OAAO,EAAE;EACrF;EACA,MAAM,aAAa,gBAAgB,EAAE,aAAa,EAAE,OAAO,OAAO,GAAG,EAAE,CAAC;EACxE,MAAM,gBAAgB,YAAY,WAAW,CAAC,UAAU,SAAS,IAAI,CAAC,IAAI,KAAK;EAC/E,IAAI,UAAU,QAAQ,UAAU,OAAO;GACrC,OAAuB,oBACrB,QACA;IACE,OAAO;IACP;IACA,MAAM,UAAU;IAChB,cAAc;IACd,WAAW;GACb,GACA,OAAO,EACT;EACF;EACA,OAAuB,oBACrB,QACA;GACE,OAAO;GACP;GACA,MAAM,YAAY,cAAc,gBAAgB,KAAK;GACrD,WAAW;GACX,SAAS;EACX,GACA,OAAO,EACT;CACF;CACA,OAAO,SAAS,eAAe,EAC7B,SACA,eACA,uBACA,OACA,YACC;EACD,MAAM,QAAQ,QAAQ,KAAK,WAAW,aAAa,QAAQ,aAAa,CAAC;EACzE,MAAM,OAAO,QAAwB,oBAAI,SAAS;GAAE;GAAO,UAAU;EAAM,CAAC,IAAI;EAChF,MAAM,UAA0B,oBAAI,YAAY;GAAE,eAAe;GAAM,UAA0B,oBAAI,UAAU,EAAE,SAAS,CAAC;EAAE,CAAC;EAC9H,OAAuB,oBAAI,MAAM;GAAE,gBAAgB;GAAO,UAAU,wBAAwC,qBAAK,aAAa,EAAE,UAAU,CACxH,oBAAI,YAAY,SAAS,EAAE,UAAU,QAAQ,CAAC,GAC9C,oBAAI,YAAY,OAAO,EAAE,UAAU,KAAK,CAAC,CAC3D,EAAE,CAAC,IAAoB,oBAAI,MAAM;IAAE,OAAO;IAAS,UAAU;GAAK,CAAC;EAAE,CAAC;CACxE;AACF"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "react";
|
|
3
|
+
|
|
4
|
+
function createExpoUIMenuView(param) {
|
|
5
|
+
var { swiftUI, modifiers } = param;
|
|
6
|
+
var { Button, ContextMenu, Host, Menu, RNHostView, Section, Toggle } = swiftUI;
|
|
7
|
+
function renderAction(action, onPressAction) {
|
|
8
|
+
var _action_attributes;
|
|
9
|
+
if ((_action_attributes = action.attributes) === null || _action_attributes === void 0 ? void 0 : _action_attributes.hidden) return null;
|
|
10
|
+
var { subactions, displayInline, state, attributes, image, title } = action;
|
|
11
|
+
var systemImage = typeof image === "string" ? image : void 0;
|
|
12
|
+
if (subactions && subactions.length > 0) {
|
|
13
|
+
var children = subactions.map(function(sub) {
|
|
14
|
+
return renderAction(sub, onPressAction);
|
|
15
|
+
});
|
|
16
|
+
if (displayInline) {
|
|
17
|
+
return /* @__PURE__ */ jsx(Section, {
|
|
18
|
+
title,
|
|
19
|
+
children
|
|
20
|
+
}, action.id);
|
|
21
|
+
}
|
|
22
|
+
return /* @__PURE__ */ jsx(Menu, {
|
|
23
|
+
label: title,
|
|
24
|
+
systemImage,
|
|
25
|
+
children
|
|
26
|
+
}, action.id);
|
|
27
|
+
}
|
|
28
|
+
var fire = function() {
|
|
29
|
+
return onPressAction === null || onPressAction === void 0 ? void 0 : onPressAction({ nativeEvent: { event: action.id } });
|
|
30
|
+
};
|
|
31
|
+
var itemModifiers = (attributes === null || attributes === void 0 ? void 0 : attributes.disabled) ? [modifiers.disabled(true)] : void 0;
|
|
32
|
+
if (state === "on" || state === "off") {
|
|
33
|
+
return /* @__PURE__ */ jsx(Toggle, {
|
|
34
|
+
label: title,
|
|
35
|
+
systemImage,
|
|
36
|
+
isOn: state === "on",
|
|
37
|
+
onIsOnChange: fire,
|
|
38
|
+
modifiers: itemModifiers
|
|
39
|
+
}, action.id);
|
|
40
|
+
}
|
|
41
|
+
return /* @__PURE__ */ jsx(Button, {
|
|
42
|
+
label: title,
|
|
43
|
+
systemImage,
|
|
44
|
+
role: (attributes === null || attributes === void 0 ? void 0 : attributes.destructive) ? "destructive" : void 0,
|
|
45
|
+
modifiers: itemModifiers,
|
|
46
|
+
onPress: fire
|
|
47
|
+
}, action.id);
|
|
48
|
+
}
|
|
49
|
+
return function ExpoUIMenuView(param2) {
|
|
50
|
+
var { actions, onPressAction, shouldOpenOnLongPress, title, children } = param2;
|
|
51
|
+
var items = actions.map(function(action) {
|
|
52
|
+
return renderAction(action, onPressAction);
|
|
53
|
+
});
|
|
54
|
+
var body = title ? /* @__PURE__ */ jsx(Section, {
|
|
55
|
+
title,
|
|
56
|
+
children: items
|
|
57
|
+
}) : items;
|
|
58
|
+
var trigger = /* @__PURE__ */ jsx(RNHostView, {
|
|
59
|
+
matchContents: true,
|
|
60
|
+
children: /* @__PURE__ */ jsx(Fragment, { children })
|
|
61
|
+
});
|
|
62
|
+
return /* @__PURE__ */ jsx(Host, {
|
|
63
|
+
ignoreSafeArea: "all",
|
|
64
|
+
children: shouldOpenOnLongPress ? /* @__PURE__ */ jsxs(ContextMenu, { children: [/* @__PURE__ */ jsx(ContextMenu.Trigger, { children: trigger }), /* @__PURE__ */ jsx(ContextMenu.Items, { children: body })] }) : /* @__PURE__ */ jsx(Menu, {
|
|
65
|
+
label: trigger,
|
|
66
|
+
children: body
|
|
67
|
+
})
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { createExpoUIMenuView };
|
|
73
|
+
//# sourceMappingURL=expoUIMenuView.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expoUIMenuView.native.js","names":["_Fragment"],"sources":["esm/expoUIMenuView.native.js"],"sourcesContent":["import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from \"react/jsx-runtime\";\nimport React from \"react\";\nfunction createExpoUIMenuView(param) {\n var { swiftUI, modifiers } = param;\n var { Button, ContextMenu, Host, Menu, RNHostView, Section, Toggle } = swiftUI;\n function renderAction(action, onPressAction) {\n var _action_attributes;\n if ((_action_attributes = action.attributes) === null || _action_attributes === void 0 ? void 0 : _action_attributes.hidden) return null;\n var { subactions, displayInline, state, attributes, image, title } = action;\n var systemImage = typeof image === \"string\" ? image : void 0;\n if (subactions && subactions.length > 0) {\n var children = subactions.map(function(sub) {\n return renderAction(sub, onPressAction);\n });\n if (displayInline) {\n return /* @__PURE__ */ _jsx(Section, {\n title,\n children\n }, action.id);\n }\n return /* @__PURE__ */ _jsx(Menu, {\n label: title,\n systemImage,\n children\n }, action.id);\n }\n var fire = function() {\n return onPressAction === null || onPressAction === void 0 ? void 0 : onPressAction({\n nativeEvent: {\n event: action.id\n }\n });\n };\n var itemModifiers = (attributes === null || attributes === void 0 ? void 0 : attributes.disabled) ? [\n modifiers.disabled(true)\n ] : void 0;\n if (state === \"on\" || state === \"off\") {\n return /* @__PURE__ */ _jsx(Toggle, {\n label: title,\n systemImage,\n isOn: state === \"on\",\n onIsOnChange: fire,\n modifiers: itemModifiers\n }, action.id);\n }\n return /* @__PURE__ */ _jsx(Button, {\n label: title,\n systemImage,\n role: (attributes === null || attributes === void 0 ? void 0 : attributes.destructive) ? \"destructive\" : void 0,\n modifiers: itemModifiers,\n onPress: fire\n }, action.id);\n }\n return function ExpoUIMenuView(param2) {\n var { actions, onPressAction, shouldOpenOnLongPress, title, children } = param2;\n var items = actions.map(function(action) {\n return renderAction(action, onPressAction);\n });\n var body = title ? /* @__PURE__ */ _jsx(Section, {\n title,\n children: items\n }) : items;\n var trigger = /* @__PURE__ */ _jsx(RNHostView, {\n matchContents: true,\n children: /* @__PURE__ */ _jsx(_Fragment, {\n children\n })\n });\n return /* @__PURE__ */ _jsx(Host, {\n ignoreSafeArea: \"all\",\n children: shouldOpenOnLongPress ? /* @__PURE__ */ _jsxs(ContextMenu, {\n children: [\n /* @__PURE__ */ _jsx(ContextMenu.Trigger, {\n children: trigger\n }),\n /* @__PURE__ */ _jsx(ContextMenu.Items, {\n children: body\n })\n ]\n }) : /* @__PURE__ */ _jsx(Menu, {\n label: trigger,\n children: body\n })\n });\n };\n}\nexport {\n createExpoUIMenuView\n};\n//# sourceMappingURL=expoUIMenuView.js.map\n"],"mappings":";;;;AAEA,SAAS,qBAAqB,OAAO;CACnC,IAAI,EAAE,SAAS,cAAc;CAC7B,IAAI,EAAE,QAAQ,aAAa,MAAM,MAAM,YAAY,SAAS,WAAW;CACvE,SAAS,aAAa,QAAQ,eAAe;EAC3C,IAAI;EACJ,KAAK,qBAAqB,OAAO,gBAAgB,QAAQ,uBAAuB,KAAK,IAAI,KAAK,IAAI,mBAAmB,QAAQ,OAAO;EACpI,IAAI,EAAE,YAAY,eAAe,OAAO,YAAY,OAAO,UAAU;EACrE,IAAI,cAAc,OAAO,UAAU,WAAW,QAAQ,KAAK;EAC3D,IAAI,cAAc,WAAW,SAAS,GAAG;GACvC,IAAI,WAAW,WAAW,IAAI,SAAS,KAAK;IAC1C,OAAO,aAAa,KAAK,aAAa;GACxC,CAAC;GACD,IAAI,eAAe;IACjB,OAAuB,oBAAK,SAAS;KACnC;KACA;IACF,GAAG,OAAO,EAAE;GACd;GACA,OAAuB,oBAAK,MAAM;IAChC,OAAO;IACP;IACA;GACF,GAAG,OAAO,EAAE;EACd;EACA,IAAI,OAAO,WAAW;GACpB,OAAO,kBAAkB,QAAQ,kBAAkB,KAAK,IAAI,KAAK,IAAI,cAAc,EACjF,aAAa,EACX,OAAO,OAAO,GAChB,EACF,CAAC;EACH;EACA,IAAI,iBAAiB,eAAe,QAAQ,eAAe,KAAK,IAAI,KAAK,IAAI,WAAW,YAAY,CAClG,UAAU,SAAS,IAAI,CACzB,IAAI,KAAK;EACT,IAAI,UAAU,QAAQ,UAAU,OAAO;GACrC,OAAuB,oBAAK,QAAQ;IAClC,OAAO;IACP;IACA,MAAM,UAAU;IAChB,cAAc;IACd,WAAW;GACb,GAAG,OAAO,EAAE;EACd;EACA,OAAuB,oBAAK,QAAQ;GAClC,OAAO;GACP;GACA,OAAO,eAAe,QAAQ,eAAe,KAAK,IAAI,KAAK,IAAI,WAAW,eAAe,gBAAgB,KAAK;GAC9G,WAAW;GACX,SAAS;EACX,GAAG,OAAO,EAAE;CACd;CACA,OAAO,SAAS,eAAe,QAAQ;EACrC,IAAI,EAAE,SAAS,eAAe,uBAAuB,OAAO,aAAa;EACzE,IAAI,QAAQ,QAAQ,IAAI,SAAS,QAAQ;GACvC,OAAO,aAAa,QAAQ,aAAa;EAC3C,CAAC;EACD,IAAI,OAAO,QAAwB,oBAAK,SAAS;GAC/C;GACA,UAAU;EACZ,CAAC,IAAI;EACL,IAAI,UAA0B,oBAAK,YAAY;GAC7C,eAAe;GACf,UAA0B,oBAAKA,UAAW,EACxC,SACF,CAAC;EACH,CAAC;EACD,OAAuB,oBAAK,MAAM;GAChC,gBAAgB;GAChB,UAAU,wBAAwC,qBAAM,aAAa,EACnE,UAAU,CACQ,oBAAK,YAAY,SAAS,EACxC,UAAU,QACZ,CAAC,GACe,oBAAK,YAAY,OAAO,EACtC,UAAU,KACZ,CAAC,CACH,EACF,CAAC,IAAoB,oBAAK,MAAM;IAC9B,OAAO;IACP,UAAU;GACZ,CAAC;EACH,CAAC;CACH;AACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createExpoUIMenuAdapter } from "./expoUIMenuAdapter.mjs";
|
|
2
|
+
import { createExpoUIMenuView } from "./expoUIMenuView.mjs";
|
|
2
3
|
import { registerNativeMenuAdapter } from "./nativeMenuState.mjs";
|
|
3
4
|
|
|
4
5
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
@@ -9,7 +10,10 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
9
10
|
function setup() {
|
|
10
11
|
let MenuView;
|
|
11
12
|
try {
|
|
12
|
-
MenuView =
|
|
13
|
+
MenuView = createExpoUIMenuView({
|
|
14
|
+
swiftUI: __require("@expo/ui/swift-ui"),
|
|
15
|
+
modifiers: __require("@expo/ui/swift-ui/modifiers")
|
|
16
|
+
});
|
|
13
17
|
} catch (error) {
|
|
14
18
|
if (process.env.NODE_ENV === "development") {
|
|
15
19
|
console.warn("Error setting up Expo UI native menus", error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-expo-ui-menu.js","names":[],"sources":["esm/setup-expo-ui-menu.js"],"sourcesContent":["import { createExpoUIMenuAdapter } from \"./expoUIMenuAdapter\";\nimport { registerNativeMenuAdapter } from \"./nativeMenuState\";\nfunction setup() {\n let MenuView;\n try {\n MenuView = require(\"@expo/ui/
|
|
1
|
+
{"version":3,"file":"setup-expo-ui-menu.js","names":[],"sources":["esm/setup-expo-ui-menu.js"],"sourcesContent":["import { createExpoUIMenuAdapter } from \"./expoUIMenuAdapter\";\nimport { createExpoUIMenuView } from \"./expoUIMenuView\";\nimport { registerNativeMenuAdapter } from \"./nativeMenuState\";\nfunction setup() {\n let MenuView;\n try {\n MenuView = createExpoUIMenuView({\n swiftUI: require(\"@expo/ui/swift-ui\"),\n modifiers: require(\"@expo/ui/swift-ui/modifiers\")\n });\n } catch (error) {\n if (process.env.NODE_ENV === \"development\") {\n console.warn(\"Error setting up Expo UI native menus\", error);\n }\n return;\n }\n registerNativeMenuAdapter(createExpoUIMenuAdapter({ MenuView }));\n}\nsetup();\n//# sourceMappingURL=setup-expo-ui-menu.js.map\n"],"mappings":";;;;;;;;;;;;AAGA,SAAS,QAAQ;CACf,IAAI;CACJ,IAAI;EACF,WAAW,qBAAqB;GAC9B,mBAAiB,mBAAmB;GACpC,qBAAmB,6BAA6B;EAClD,CAAC;CACH,SAAS,OAAO;EACd,IAAI,QAAQ,IAAI,aAAa,eAAe;GAC1C,QAAQ,KAAK,yCAAyC,KAAK;EAC7D;EACA;CACF;CACA,0BAA0B,wBAAwB,EAAE,SAAS,CAAC,CAAC;AACjE;AACA,MAAM"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createExpoUIMenuAdapter } from "./expoUIMenuAdapter.native.js";
|
|
2
|
+
import { createExpoUIMenuView } from "./expoUIMenuView.native.js";
|
|
2
3
|
import { registerNativeMenuAdapter } from "./nativeMenuState.native.js";
|
|
3
4
|
|
|
4
5
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
@@ -9,7 +10,10 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
9
10
|
function setup() {
|
|
10
11
|
var MenuView;
|
|
11
12
|
try {
|
|
12
|
-
MenuView =
|
|
13
|
+
MenuView = createExpoUIMenuView({
|
|
14
|
+
swiftUI: require("@expo/ui/swift-ui"),
|
|
15
|
+
modifiers: require("@expo/ui/swift-ui/modifiers")
|
|
16
|
+
});
|
|
13
17
|
} catch (error) {
|
|
14
18
|
if (process.env.NODE_ENV === "development") {
|
|
15
19
|
console.warn("Error setting up Expo UI native menus", error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-expo-ui-menu.native.js","names":[],"sources":["esm/setup-expo-ui-menu.native.js"],"sourcesContent":["import { createExpoUIMenuAdapter } from \"./expoUIMenuAdapter\";\nimport { registerNativeMenuAdapter } from \"./nativeMenuState\";\nfunction setup() {\n var MenuView;\n try {\n MenuView = require(\"@expo/ui/
|
|
1
|
+
{"version":3,"file":"setup-expo-ui-menu.native.js","names":[],"sources":["esm/setup-expo-ui-menu.native.js"],"sourcesContent":["import { createExpoUIMenuAdapter } from \"./expoUIMenuAdapter\";\nimport { createExpoUIMenuView } from \"./expoUIMenuView\";\nimport { registerNativeMenuAdapter } from \"./nativeMenuState\";\nfunction setup() {\n var MenuView;\n try {\n MenuView = createExpoUIMenuView({\n swiftUI: require(\"@expo/ui/swift-ui\"),\n modifiers: require(\"@expo/ui/swift-ui/modifiers\")\n });\n } catch (error) {\n if (process.env.NODE_ENV === \"development\") {\n console.warn(\"Error setting up Expo UI native menus\", error);\n }\n return;\n }\n registerNativeMenuAdapter(createExpoUIMenuAdapter({\n MenuView\n }));\n}\nsetup();\n//# sourceMappingURL=setup-expo-ui-menu.js.map\n"],"mappings":";;;;;;;;;;;;AAGA,SAAS,QAAQ;CACf,IAAI;CACJ,IAAI;EACF,WAAW,qBAAqB;GAC9B,mBAAiB,mBAAmB;GACpC,qBAAmB,6BAA6B;EAClD,CAAC;CACH,SAAS,OAAO;EACd,IAAI,QAAQ,IAAI,aAAa,eAAe;GAC1C,QAAQ,KAAK,yCAAyC,KAAK;EAC7D;EACA;CACF;CACA,0BAA0B,wBAAwB,EAChD,SACF,CAAC,CAAC;AACJ;AACA,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/native",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.1173.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Native setup modules for Tamagui - portals, gesture handler, worklets, and more",
|
|
6
6
|
"type": "module",
|
|
@@ -182,12 +182,12 @@
|
|
|
182
182
|
"clean:build": "tamagui-build clean:build"
|
|
183
183
|
},
|
|
184
184
|
"dependencies": {
|
|
185
|
-
"@tamagui/compose-refs": "3.0.0-beta.
|
|
186
|
-
"@tamagui/react-native-types": "3.0.0-beta.
|
|
185
|
+
"@tamagui/compose-refs": "3.0.0-beta.1173.1",
|
|
186
|
+
"@tamagui/react-native-types": "3.0.0-beta.1173.1"
|
|
187
187
|
},
|
|
188
188
|
"devDependencies": {
|
|
189
189
|
"@expo/ui": "~57.0.12",
|
|
190
|
-
"@tamagui/build": "3.0.0-beta.
|
|
190
|
+
"@tamagui/build": "3.0.0-beta.1173.1",
|
|
191
191
|
"burnt": "^0.13.0",
|
|
192
192
|
"expo-linear-gradient": "~57.0.1",
|
|
193
193
|
"react": "19.2.3",
|
|
@@ -3,7 +3,7 @@ import React from 'react'
|
|
|
3
3
|
|
|
4
4
|
import type { NativeMenuAdapter, NativeMenuModule } from './nativeMenuState'
|
|
5
5
|
|
|
6
|
-
type ExpoMenuAction = {
|
|
6
|
+
export type ExpoMenuAction = {
|
|
7
7
|
id: string
|
|
8
8
|
title: string
|
|
9
9
|
image?: unknown
|
|
@@ -17,7 +17,7 @@ type ExpoMenuAction = {
|
|
|
17
17
|
displayInline?: boolean
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
type ExpoMenuViewProps = {
|
|
20
|
+
export type ExpoMenuViewProps = {
|
|
21
21
|
actions: ExpoMenuAction[]
|
|
22
22
|
title?: string
|
|
23
23
|
shouldOpenOnLongPress?: boolean
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from 'react'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import type { ExpoMenuAction, ExpoMenuViewProps } from './expoUIMenuAdapter'
|
|
5
|
+
|
|
6
|
+
// the swiftui menu behind every native Menu and ContextMenu trigger on ios,
|
|
7
|
+
// composed from @expo/ui/swift-ui the same way @expo/ui's community MenuView
|
|
8
|
+
// is, minus `matchContents` on the Host. that flag copies each SwiftUI
|
|
9
|
+
// measurement back onto the host's yoga node as a fixed height, and yoga then
|
|
10
|
+
// measures the trigger's react-native children against that height, so trigger
|
|
11
|
+
// content can shrink but never grow: a row that mounts empty and fills in later
|
|
12
|
+
// stays at 0pt, and a streaming paragraph stays at its first line count. without
|
|
13
|
+
// the flag the host takes its height from the hosted react-native subtree like
|
|
14
|
+
// any other view, and RNHostView still sizes the SwiftUI side from that
|
|
15
|
+
// subtree's yoga bounds.
|
|
16
|
+
|
|
17
|
+
type SwiftUIModule = {
|
|
18
|
+
Button: ComponentType<any>
|
|
19
|
+
ContextMenu: ComponentType<any> & {
|
|
20
|
+
Trigger: ComponentType<any>
|
|
21
|
+
Items: ComponentType<any>
|
|
22
|
+
}
|
|
23
|
+
Host: ComponentType<any>
|
|
24
|
+
Menu: ComponentType<any>
|
|
25
|
+
RNHostView: ComponentType<any>
|
|
26
|
+
Section: ComponentType<any>
|
|
27
|
+
Toggle: ComponentType<any>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type SwiftUIModifiersModule = {
|
|
31
|
+
disabled: (value: boolean) => unknown
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function createExpoUIMenuView({
|
|
35
|
+
swiftUI,
|
|
36
|
+
modifiers,
|
|
37
|
+
}: {
|
|
38
|
+
swiftUI: SwiftUIModule
|
|
39
|
+
modifiers: SwiftUIModifiersModule
|
|
40
|
+
}): ComponentType<ExpoMenuViewProps> {
|
|
41
|
+
const { Button, ContextMenu, Host, Menu, RNHostView, Section, Toggle } = swiftUI
|
|
42
|
+
|
|
43
|
+
function renderAction(
|
|
44
|
+
action: ExpoMenuAction,
|
|
45
|
+
onPressAction: ExpoMenuViewProps['onPressAction']
|
|
46
|
+
): ReactNode {
|
|
47
|
+
if (action.attributes?.hidden) return null
|
|
48
|
+
const { subactions, displayInline, state, attributes, image, title } = action
|
|
49
|
+
const systemImage = typeof image === 'string' ? image : undefined
|
|
50
|
+
|
|
51
|
+
if (subactions && subactions.length > 0) {
|
|
52
|
+
const children = subactions.map((sub) => renderAction(sub, onPressAction))
|
|
53
|
+
if (displayInline) {
|
|
54
|
+
return (
|
|
55
|
+
<Section key={action.id} title={title}>
|
|
56
|
+
{children}
|
|
57
|
+
</Section>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
return (
|
|
61
|
+
<Menu key={action.id} label={title} systemImage={systemImage}>
|
|
62
|
+
{children}
|
|
63
|
+
</Menu>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const fire = () => onPressAction?.({ nativeEvent: { event: action.id } })
|
|
68
|
+
const itemModifiers = attributes?.disabled ? [modifiers.disabled(true)] : undefined
|
|
69
|
+
|
|
70
|
+
if (state === 'on' || state === 'off') {
|
|
71
|
+
return (
|
|
72
|
+
<Toggle
|
|
73
|
+
key={action.id}
|
|
74
|
+
label={title}
|
|
75
|
+
systemImage={systemImage}
|
|
76
|
+
isOn={state === 'on'}
|
|
77
|
+
onIsOnChange={fire}
|
|
78
|
+
modifiers={itemModifiers}
|
|
79
|
+
/>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<Button
|
|
85
|
+
key={action.id}
|
|
86
|
+
label={title}
|
|
87
|
+
systemImage={systemImage}
|
|
88
|
+
role={attributes?.destructive ? 'destructive' : undefined}
|
|
89
|
+
modifiers={itemModifiers}
|
|
90
|
+
onPress={fire}
|
|
91
|
+
/>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return function ExpoUIMenuView({
|
|
96
|
+
actions,
|
|
97
|
+
onPressAction,
|
|
98
|
+
shouldOpenOnLongPress,
|
|
99
|
+
title,
|
|
100
|
+
children,
|
|
101
|
+
}: ExpoMenuViewProps) {
|
|
102
|
+
const items = actions.map((action) => renderAction(action, onPressAction))
|
|
103
|
+
const body = title ? <Section title={title}>{items}</Section> : items
|
|
104
|
+
// RNHostView takes exactly one element, so the trigger children ride in a
|
|
105
|
+
// fragment
|
|
106
|
+
const trigger = (
|
|
107
|
+
<RNHostView matchContents>
|
|
108
|
+
<>{children}</>
|
|
109
|
+
</RNHostView>
|
|
110
|
+
)
|
|
111
|
+
return (
|
|
112
|
+
<Host ignoreSafeArea="all">
|
|
113
|
+
{shouldOpenOnLongPress ? (
|
|
114
|
+
<ContextMenu>
|
|
115
|
+
<ContextMenu.Trigger>{trigger}</ContextMenu.Trigger>
|
|
116
|
+
<ContextMenu.Items>{body}</ContextMenu.Items>
|
|
117
|
+
</ContextMenu>
|
|
118
|
+
) : (
|
|
119
|
+
<Menu label={trigger}>{body}</Menu>
|
|
120
|
+
)}
|
|
121
|
+
</Host>
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -6,12 +6,16 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { createExpoUIMenuAdapter } from './expoUIMenuAdapter'
|
|
9
|
+
import { createExpoUIMenuView } from './expoUIMenuView'
|
|
9
10
|
import { registerNativeMenuAdapter } from './nativeMenuState'
|
|
10
11
|
|
|
11
12
|
function setup(): void {
|
|
12
13
|
let MenuView
|
|
13
14
|
try {
|
|
14
|
-
MenuView =
|
|
15
|
+
MenuView = createExpoUIMenuView({
|
|
16
|
+
swiftUI: require('@expo/ui/swift-ui'),
|
|
17
|
+
modifiers: require('@expo/ui/swift-ui/modifiers'),
|
|
18
|
+
})
|
|
15
19
|
} catch (error) {
|
|
16
20
|
if (process.env.NODE_ENV === 'development') {
|
|
17
21
|
console.warn('Error setting up Expo UI native menus', error)
|
|
@@ -1,5 +1,31 @@
|
|
|
1
|
-
import type { ComponentType } from "react";
|
|
1
|
+
import type { ComponentType, ReactNode } from "react";
|
|
2
2
|
import type { NativeMenuAdapter } from "./nativeMenuState";
|
|
3
|
+
export type ExpoMenuAction = {
|
|
4
|
+
id: string;
|
|
5
|
+
title: string;
|
|
6
|
+
image?: unknown;
|
|
7
|
+
state?: "on" | "off";
|
|
8
|
+
attributes?: {
|
|
9
|
+
destructive?: boolean;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
hidden?: boolean;
|
|
12
|
+
};
|
|
13
|
+
subactions?: ExpoMenuAction[];
|
|
14
|
+
displayInline?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type ExpoMenuViewProps = {
|
|
17
|
+
actions: ExpoMenuAction[];
|
|
18
|
+
title?: string;
|
|
19
|
+
shouldOpenOnLongPress?: boolean;
|
|
20
|
+
onPressAction?: (event: {
|
|
21
|
+
nativeEvent: {
|
|
22
|
+
event: string;
|
|
23
|
+
};
|
|
24
|
+
}) => void;
|
|
25
|
+
onOpenMenu?: () => void;
|
|
26
|
+
onCloseMenu?: () => void;
|
|
27
|
+
children?: ReactNode;
|
|
28
|
+
};
|
|
3
29
|
export type ExpoUIMenuAdapterOptions = {
|
|
4
30
|
MenuView: ComponentType<any>;
|
|
5
31
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"mappings": "AAAA,cAAc,
|
|
2
|
+
"mappings": "AAAA,cAAc,eAA6B,iBAAiB;AAG5D,cAAc,yBAA2C;AAEzD,YAAY,iBAAiB;CAC3B;CACA;CACA;CACA,QAAQ,OAAO;CACf,aAAa;EACX;EACA;EACA;;CAEF,aAAa;CACb;;AAGF,YAAY,oBAAoB;CAC9B,SAAS;CACT;CACA;CACA,iBAAiB,OAAO;EAAE,aAAa;GAAE;;;CACzC;CACA;CACA,WAAW;;AAGb,YAAY,2BAA2B;CACrC,UAAU;;AAgEZ,OAAO,iBAAS,wBAAwB,EACtC,YACC,2BAA2B",
|
|
3
3
|
"names": [],
|
|
4
4
|
"sources": [
|
|
5
5
|
"src/expoUIMenuAdapter.tsx"
|
|
6
6
|
],
|
|
7
7
|
"version": 3,
|
|
8
8
|
"sourcesContent": [
|
|
9
|
-
"import type { ComponentType, ReactElement, ReactNode } from 'react'\nimport React from 'react'\n\nimport type { NativeMenuAdapter, NativeMenuModule } from './nativeMenuState'\n\ntype ExpoMenuAction = {\n id: string\n title: string\n image?: unknown\n state?: 'on' | 'off'\n attributes?: {\n destructive?: boolean\n disabled?: boolean\n hidden?: boolean\n }\n subactions?: ExpoMenuAction[]\n displayInline?: boolean\n}\n\ntype ExpoMenuViewProps = {\n actions: ExpoMenuAction[]\n title?: string\n shouldOpenOnLongPress?: boolean\n onPressAction?: (event: { nativeEvent: { event: string } }) => void\n onOpenMenu?: () => void\n onCloseMenu?: () => void\n children?: ReactNode\n}\n\nexport type ExpoUIMenuAdapterOptions = {\n MenuView: ComponentType<any>\n}\n\ntype MarkerProps = {\n children?: ReactNode\n [key: string]: unknown\n}\n\nfunction marker(name: string): ComponentType<MarkerProps> {\n const Marker = () => null\n Marker.displayName = `ExpoUI${name}`\n return Marker\n}\n\nfunction isMarkerType(candidate: unknown, type: ComponentType<MarkerProps>): boolean {\n if (candidate === type) return true\n // createMenu runs every native component through withNativeMenu, which wraps\n // it in a new function component and copies the marker's displayName onto the\n // wrapper. that wrapper is a different reference, so an identity-only check\n // matches nothing and every item silently comes back with an empty title, no\n // icon, and no submenu. fall back to the (unique, ExpoUI-prefixed) name.\n const wanted = (type as { displayName?: string }).displayName\n if (!wanted) return false\n return (\n typeof candidate === 'function' &&\n (candidate as { displayName?: string }).displayName === wanted\n )\n}\n\nfunction elementOfType(\n children: ReactNode,\n type: ComponentType<MarkerProps>\n): ReactElement<MarkerProps> | null {\n for (const child of React.Children.toArray(children)) {\n if (React.isValidElement<MarkerProps>(child) && isMarkerType(child.type, type)) {\n return child\n }\n }\n return null\n}\n\nconst warnedUnsupported = new Set<string>()\n\n// @expo/ui's MenuAction carries no subtitle, and its MenuView has no preview or\n// auxiliary view. these are decorations on a menu that is otherwise complete, so\n// drop them and warn once. throwing took down the whole app for an optional\n// embellishment. apps cannot avoid this without forking their markup per adapter.\nfunction warnUnsupported(feature: string) {\n if (warnedUnsupported.has(feature) || process.env.NODE_ENV === 'production') {\n return\n }\n warnedUnsupported.add(feature)\n console.warn(\n `[Tamagui] @expo/ui/community/menu does not support ${feature}, so it will not render. ` +\n `Register a different native menu adapter if you need it.`\n )\n}\n\nfunction textFromNode(node: ReactNode): string {\n if (typeof node === 'string' || typeof node === 'number') return String(node)\n if (!React.isValidElement<MarkerProps>(node)) return ''\n return React.Children.toArray(node.props.children).map(textFromNode).join('')\n}\n\nexport function createExpoUIMenuAdapter({\n MenuView,\n}: ExpoUIMenuAdapterOptions): NativeMenuAdapter {\n const NativeMenuView: ComponentType<ExpoMenuViewProps> = MenuView\n\n function createModule(isContextMenu: boolean): NativeMenuModule {\n const Trigger = marker('Trigger')\n const Content = marker('Content')\n const Item = marker('Item')\n const ItemTitle = marker('ItemTitle')\n const ItemSubtitle = marker('ItemSubtitle')\n const ItemIcon = marker('ItemIcon')\n const ItemImage = marker('ItemImage')\n const ItemIndicator = marker('ItemIndicator')\n const Group = marker('Group')\n const Label = marker('Label')\n const Separator = marker('Separator')\n const Sub = marker('Sub')\n const SubTrigger = marker('SubTrigger')\n const SubContent = marker('SubContent')\n const CheckboxItem = marker('CheckboxItem')\n const Preview = marker('Preview')\n const Auxiliary = marker('Auxiliary')\n\n function Root({\n children,\n onOpenChange,\n onOpenWillChange,\n }: {\n children?: ReactNode\n onOpenChange?: (open: boolean) => void\n onOpenWillChange?: (open: boolean) => void\n }) {\n const trigger = elementOfType(children, Trigger)\n const content = elementOfType(children, Content)\n const preview = elementOfType(children, Preview)\n const auxiliary = elementOfType(children, Auxiliary)\n\n if (preview || auxiliary) {\n warnUnsupported('context-menu previews or auxiliary views')\n }\n if (!trigger || !content) {\n throw new Error('Tamagui native menus require one Trigger and one Content')\n }\n\n let nextId = 0\n const handlers = new Map<string, () => void>()\n\n function actionId(element: ReactElement<MarkerProps>): string {\n return element.key == null\n ? `tamagui-menu-${nextId++}`\n : String(element.key).replace(/^\\.\\$/, '')\n }\n\n function itemTitle(element: ReactElement<MarkerProps>): string {\n if (typeof element.props.textValue === 'string') return element.props.textValue\n const title = elementOfType(element.props.children, ItemTitle)\n return title ? textFromNode(title.props.children) : ''\n }\n\n function actionImage(element: ReactElement<MarkerProps>): unknown {\n const image = elementOfType(element.props.children, ItemImage)\n if (image?.props.source) return image.props.source\n const icon = elementOfType(element.props.children, ItemIcon)\n if (!icon) return undefined\n const ios = icon.props.ios\n if (\n typeof ios === 'object' &&\n ios &&\n 'name' in ios &&\n typeof ios.name === 'string'\n ) {\n return ios.name\n }\n return typeof icon.props.iosIconName === 'string'\n ? icon.props.iosIconName\n : undefined\n }\n\n function attributes(\n element: ReactElement<MarkerProps>\n ): ExpoMenuAction['attributes'] {\n const destructive = element.props.destructive === true\n const disabled = element.props.disabled === true\n const hidden = element.props.hidden === true\n return destructive || disabled || hidden\n ? { destructive, disabled, hidden }\n : undefined\n }\n\n function actionsFrom(childrenToParse: ReactNode): ExpoMenuAction[] {\n const actions: ExpoMenuAction[] = []\n let section: ExpoMenuAction[] | null = null\n\n function append(action: ExpoMenuAction) {\n if (section) {\n section.push(action)\n } else {\n actions.push(action)\n }\n }\n\n function flushSection() {\n if (!section?.length) {\n section = []\n return\n }\n actions.push({\n id: `tamagui-menu-section-${nextId++}`,\n title: '',\n subactions: section,\n displayInline: true,\n })\n section = []\n }\n\n for (const child of React.Children.toArray(childrenToParse)) {\n if (!React.isValidElement<MarkerProps>(child)) continue\n\n if (isMarkerType(child.type, Separator)) {\n if (!section) section = actions.splice(0)\n flushSection()\n continue\n }\n\n if (isMarkerType(child.type, Group)) {\n const label = elementOfType(child.props.children, Label)\n append({\n id: actionId(child),\n title: label ? textFromNode(label.props.children) : '',\n subactions: actionsFrom(child.props.children),\n displayInline: true,\n })\n continue\n }\n\n if (isMarkerType(child.type, Sub)) {\n const subTrigger = elementOfType(child.props.children, SubTrigger)\n const subContent = elementOfType(child.props.children, SubContent)\n if (!subTrigger || !subContent) {\n throw new Error(\n 'Tamagui native submenus require one SubTrigger and SubContent'\n )\n }\n append({\n id: actionId(child),\n title: itemTitle(subTrigger),\n image: actionImage(subTrigger),\n attributes: attributes(subTrigger),\n subactions: actionsFrom(subContent.props.children),\n })\n continue\n }\n\n if (!isMarkerType(child.type, Item) && !isMarkerType(child.type, CheckboxItem))\n continue\n\n if (elementOfType(child.props.children, ItemSubtitle)) {\n warnUnsupported('menu item subtitles')\n }\n\n const id = actionId(child)\n if (isMarkerType(child.type, CheckboxItem)) {\n const current =\n child.props.value === true ||\n child.props.value === 'on' ||\n child.props.checked === true\n const onValueChange = child.props.onValueChange\n const onCheckedChange = child.props.onCheckedChange\n handlers.set(id, () => {\n if (typeof onValueChange === 'function') {\n onValueChange(current ? 'off' : 'on', current ? 'on' : 'off')\n } else if (typeof onCheckedChange === 'function') {\n onCheckedChange(!current)\n }\n })\n append({\n id,\n title: itemTitle(child),\n image: actionImage(child),\n state: current ? 'on' : 'off',\n attributes: attributes(child),\n })\n continue\n }\n\n const onSelect = child.props.onSelect\n if (typeof onSelect === 'function') {\n handlers.set(id, () => onSelect())\n }\n append({\n id,\n title: itemTitle(child),\n image: actionImage(child),\n attributes: attributes(child),\n })\n }\n\n if (section) flushSection()\n return actions\n }\n\n const label = elementOfType(content.props.children, Label)\n const triggerAction = trigger.props.action\n\n return (\n <NativeMenuView\n actions={actionsFrom(content.props.children)}\n title={label ? textFromNode(label.props.children) : undefined}\n shouldOpenOnLongPress={\n triggerAction === 'longPress' || (triggerAction !== 'press' && isContextMenu)\n }\n onPressAction={(event) => handlers.get(event.nativeEvent.event)?.()}\n onOpenMenu={() => {\n onOpenWillChange?.(true)\n onOpenChange?.(true)\n }}\n onCloseMenu={() => {\n onOpenWillChange?.(false)\n onOpenChange?.(false)\n }}\n >\n {trigger.props.children}\n </NativeMenuView>\n )\n }\n\n return {\n Root,\n Trigger,\n Content,\n Item,\n ItemTitle,\n ItemSubtitle,\n ItemIcon,\n ItemImage,\n ItemIndicator,\n Group,\n Label,\n Separator,\n Sub,\n SubTrigger,\n SubContent,\n CheckboxItem,\n Preview,\n Auxiliary,\n }\n }\n\n return {\n name: 'expo-ui',\n Menu: createModule(false),\n ContextMenu: createModule(true),\n }\n}\n"
|
|
9
|
+
"import type { ComponentType, ReactElement, ReactNode } from 'react'\nimport React from 'react'\n\nimport type { NativeMenuAdapter, NativeMenuModule } from './nativeMenuState'\n\nexport type ExpoMenuAction = {\n id: string\n title: string\n image?: unknown\n state?: 'on' | 'off'\n attributes?: {\n destructive?: boolean\n disabled?: boolean\n hidden?: boolean\n }\n subactions?: ExpoMenuAction[]\n displayInline?: boolean\n}\n\nexport type ExpoMenuViewProps = {\n actions: ExpoMenuAction[]\n title?: string\n shouldOpenOnLongPress?: boolean\n onPressAction?: (event: { nativeEvent: { event: string } }) => void\n onOpenMenu?: () => void\n onCloseMenu?: () => void\n children?: ReactNode\n}\n\nexport type ExpoUIMenuAdapterOptions = {\n MenuView: ComponentType<any>\n}\n\ntype MarkerProps = {\n children?: ReactNode\n [key: string]: unknown\n}\n\nfunction marker(name: string): ComponentType<MarkerProps> {\n const Marker = () => null\n Marker.displayName = `ExpoUI${name}`\n return Marker\n}\n\nfunction isMarkerType(candidate: unknown, type: ComponentType<MarkerProps>): boolean {\n if (candidate === type) return true\n // createMenu runs every native component through withNativeMenu, which wraps\n // it in a new function component and copies the marker's displayName onto the\n // wrapper. that wrapper is a different reference, so an identity-only check\n // matches nothing and every item silently comes back with an empty title, no\n // icon, and no submenu. fall back to the (unique, ExpoUI-prefixed) name.\n const wanted = (type as { displayName?: string }).displayName\n if (!wanted) return false\n return (\n typeof candidate === 'function' &&\n (candidate as { displayName?: string }).displayName === wanted\n )\n}\n\nfunction elementOfType(\n children: ReactNode,\n type: ComponentType<MarkerProps>\n): ReactElement<MarkerProps> | null {\n for (const child of React.Children.toArray(children)) {\n if (React.isValidElement<MarkerProps>(child) && isMarkerType(child.type, type)) {\n return child\n }\n }\n return null\n}\n\nconst warnedUnsupported = new Set<string>()\n\n// @expo/ui's MenuAction carries no subtitle, and its MenuView has no preview or\n// auxiliary view. these are decorations on a menu that is otherwise complete, so\n// drop them and warn once. throwing took down the whole app for an optional\n// embellishment. apps cannot avoid this without forking their markup per adapter.\nfunction warnUnsupported(feature: string) {\n if (warnedUnsupported.has(feature) || process.env.NODE_ENV === 'production') {\n return\n }\n warnedUnsupported.add(feature)\n console.warn(\n `[Tamagui] @expo/ui/community/menu does not support ${feature}, so it will not render. ` +\n `Register a different native menu adapter if you need it.`\n )\n}\n\nfunction textFromNode(node: ReactNode): string {\n if (typeof node === 'string' || typeof node === 'number') return String(node)\n if (!React.isValidElement<MarkerProps>(node)) return ''\n return React.Children.toArray(node.props.children).map(textFromNode).join('')\n}\n\nexport function createExpoUIMenuAdapter({\n MenuView,\n}: ExpoUIMenuAdapterOptions): NativeMenuAdapter {\n const NativeMenuView: ComponentType<ExpoMenuViewProps> = MenuView\n\n function createModule(isContextMenu: boolean): NativeMenuModule {\n const Trigger = marker('Trigger')\n const Content = marker('Content')\n const Item = marker('Item')\n const ItemTitle = marker('ItemTitle')\n const ItemSubtitle = marker('ItemSubtitle')\n const ItemIcon = marker('ItemIcon')\n const ItemImage = marker('ItemImage')\n const ItemIndicator = marker('ItemIndicator')\n const Group = marker('Group')\n const Label = marker('Label')\n const Separator = marker('Separator')\n const Sub = marker('Sub')\n const SubTrigger = marker('SubTrigger')\n const SubContent = marker('SubContent')\n const CheckboxItem = marker('CheckboxItem')\n const Preview = marker('Preview')\n const Auxiliary = marker('Auxiliary')\n\n function Root({\n children,\n onOpenChange,\n onOpenWillChange,\n }: {\n children?: ReactNode\n onOpenChange?: (open: boolean) => void\n onOpenWillChange?: (open: boolean) => void\n }) {\n const trigger = elementOfType(children, Trigger)\n const content = elementOfType(children, Content)\n const preview = elementOfType(children, Preview)\n const auxiliary = elementOfType(children, Auxiliary)\n\n if (preview || auxiliary) {\n warnUnsupported('context-menu previews or auxiliary views')\n }\n if (!trigger || !content) {\n throw new Error('Tamagui native menus require one Trigger and one Content')\n }\n\n let nextId = 0\n const handlers = new Map<string, () => void>()\n\n function actionId(element: ReactElement<MarkerProps>): string {\n return element.key == null\n ? `tamagui-menu-${nextId++}`\n : String(element.key).replace(/^\\.\\$/, '')\n }\n\n function itemTitle(element: ReactElement<MarkerProps>): string {\n if (typeof element.props.textValue === 'string') return element.props.textValue\n const title = elementOfType(element.props.children, ItemTitle)\n return title ? textFromNode(title.props.children) : ''\n }\n\n function actionImage(element: ReactElement<MarkerProps>): unknown {\n const image = elementOfType(element.props.children, ItemImage)\n if (image?.props.source) return image.props.source\n const icon = elementOfType(element.props.children, ItemIcon)\n if (!icon) return undefined\n const ios = icon.props.ios\n if (\n typeof ios === 'object' &&\n ios &&\n 'name' in ios &&\n typeof ios.name === 'string'\n ) {\n return ios.name\n }\n return typeof icon.props.iosIconName === 'string'\n ? icon.props.iosIconName\n : undefined\n }\n\n function attributes(\n element: ReactElement<MarkerProps>\n ): ExpoMenuAction['attributes'] {\n const destructive = element.props.destructive === true\n const disabled = element.props.disabled === true\n const hidden = element.props.hidden === true\n return destructive || disabled || hidden\n ? { destructive, disabled, hidden }\n : undefined\n }\n\n function actionsFrom(childrenToParse: ReactNode): ExpoMenuAction[] {\n const actions: ExpoMenuAction[] = []\n let section: ExpoMenuAction[] | null = null\n\n function append(action: ExpoMenuAction) {\n if (section) {\n section.push(action)\n } else {\n actions.push(action)\n }\n }\n\n function flushSection() {\n if (!section?.length) {\n section = []\n return\n }\n actions.push({\n id: `tamagui-menu-section-${nextId++}`,\n title: '',\n subactions: section,\n displayInline: true,\n })\n section = []\n }\n\n for (const child of React.Children.toArray(childrenToParse)) {\n if (!React.isValidElement<MarkerProps>(child)) continue\n\n if (isMarkerType(child.type, Separator)) {\n if (!section) section = actions.splice(0)\n flushSection()\n continue\n }\n\n if (isMarkerType(child.type, Group)) {\n const label = elementOfType(child.props.children, Label)\n append({\n id: actionId(child),\n title: label ? textFromNode(label.props.children) : '',\n subactions: actionsFrom(child.props.children),\n displayInline: true,\n })\n continue\n }\n\n if (isMarkerType(child.type, Sub)) {\n const subTrigger = elementOfType(child.props.children, SubTrigger)\n const subContent = elementOfType(child.props.children, SubContent)\n if (!subTrigger || !subContent) {\n throw new Error(\n 'Tamagui native submenus require one SubTrigger and SubContent'\n )\n }\n append({\n id: actionId(child),\n title: itemTitle(subTrigger),\n image: actionImage(subTrigger),\n attributes: attributes(subTrigger),\n subactions: actionsFrom(subContent.props.children),\n })\n continue\n }\n\n if (!isMarkerType(child.type, Item) && !isMarkerType(child.type, CheckboxItem))\n continue\n\n if (elementOfType(child.props.children, ItemSubtitle)) {\n warnUnsupported('menu item subtitles')\n }\n\n const id = actionId(child)\n if (isMarkerType(child.type, CheckboxItem)) {\n const current =\n child.props.value === true ||\n child.props.value === 'on' ||\n child.props.checked === true\n const onValueChange = child.props.onValueChange\n const onCheckedChange = child.props.onCheckedChange\n handlers.set(id, () => {\n if (typeof onValueChange === 'function') {\n onValueChange(current ? 'off' : 'on', current ? 'on' : 'off')\n } else if (typeof onCheckedChange === 'function') {\n onCheckedChange(!current)\n }\n })\n append({\n id,\n title: itemTitle(child),\n image: actionImage(child),\n state: current ? 'on' : 'off',\n attributes: attributes(child),\n })\n continue\n }\n\n const onSelect = child.props.onSelect\n if (typeof onSelect === 'function') {\n handlers.set(id, () => onSelect())\n }\n append({\n id,\n title: itemTitle(child),\n image: actionImage(child),\n attributes: attributes(child),\n })\n }\n\n if (section) flushSection()\n return actions\n }\n\n const label = elementOfType(content.props.children, Label)\n const triggerAction = trigger.props.action\n\n return (\n <NativeMenuView\n actions={actionsFrom(content.props.children)}\n title={label ? textFromNode(label.props.children) : undefined}\n shouldOpenOnLongPress={\n triggerAction === 'longPress' || (triggerAction !== 'press' && isContextMenu)\n }\n onPressAction={(event) => handlers.get(event.nativeEvent.event)?.()}\n onOpenMenu={() => {\n onOpenWillChange?.(true)\n onOpenChange?.(true)\n }}\n onCloseMenu={() => {\n onOpenWillChange?.(false)\n onOpenChange?.(false)\n }}\n >\n {trigger.props.children}\n </NativeMenuView>\n )\n }\n\n return {\n Root,\n Trigger,\n Content,\n Item,\n ItemTitle,\n ItemSubtitle,\n ItemIcon,\n ItemImage,\n ItemIndicator,\n Group,\n Label,\n Separator,\n Sub,\n SubTrigger,\n SubContent,\n CheckboxItem,\n Preview,\n Auxiliary,\n }\n }\n\n return {\n name: 'expo-ui',\n Menu: createModule(false),\n ContextMenu: createModule(true),\n }\n}\n"
|
|
10
10
|
]
|
|
11
11
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ComponentType } from "react";
|
|
2
|
+
import type { ExpoMenuViewProps } from "./expoUIMenuAdapter";
|
|
3
|
+
type SwiftUIModule = {
|
|
4
|
+
Button: ComponentType<any>;
|
|
5
|
+
ContextMenu: ComponentType<any> & {
|
|
6
|
+
Trigger: ComponentType<any>;
|
|
7
|
+
Items: ComponentType<any>;
|
|
8
|
+
};
|
|
9
|
+
Host: ComponentType<any>;
|
|
10
|
+
Menu: ComponentType<any>;
|
|
11
|
+
RNHostView: ComponentType<any>;
|
|
12
|
+
Section: ComponentType<any>;
|
|
13
|
+
Toggle: ComponentType<any>;
|
|
14
|
+
};
|
|
15
|
+
type SwiftUIModifiersModule = {
|
|
16
|
+
disabled: (value: boolean) => unknown;
|
|
17
|
+
};
|
|
18
|
+
export declare function createExpoUIMenuView({ swiftUI, modifiers }: {
|
|
19
|
+
swiftUI: SwiftUIModule;
|
|
20
|
+
modifiers: SwiftUIModifiersModule;
|
|
21
|
+
}): ComponentType<ExpoMenuViewProps>;
|
|
22
|
+
export {};
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=expoUIMenuView.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"mappings": "AAAA,cAAc,qBAAgC;AAG9C,cAA8B,yBAAyB;KAalD,gBAAgB;CACnB,QAAQ;CACR,aAAa,qBAAqB;EAChC,SAAS;EACT,OAAO;;CAET,MAAM;CACN,MAAM;CACN,YAAY;CACZ,SAAS;CACT,QAAQ;;KAGL,yBAAyB;CAC5B,WAAW;;AAGb,OAAO,iBAAS,qBAAqB,EACnC,SACA,aACC;CACD,SAAS;CACT,WAAW;IACT,cAAc",
|
|
3
|
+
"names": [],
|
|
4
|
+
"sources": [
|
|
5
|
+
"src/expoUIMenuView.tsx"
|
|
6
|
+
],
|
|
7
|
+
"version": 3,
|
|
8
|
+
"sourcesContent": [
|
|
9
|
+
"import type { ComponentType, ReactNode } from 'react'\nimport React from 'react'\n\nimport type { ExpoMenuAction, ExpoMenuViewProps } from './expoUIMenuAdapter'\n\n// the swiftui menu behind every native Menu and ContextMenu trigger on ios,\n// composed from @expo/ui/swift-ui the same way @expo/ui's community MenuView\n// is, minus `matchContents` on the Host. that flag copies each SwiftUI\n// measurement back onto the host's yoga node as a fixed height, and yoga then\n// measures the trigger's react-native children against that height, so trigger\n// content can shrink but never grow: a row that mounts empty and fills in later\n// stays at 0pt, and a streaming paragraph stays at its first line count. without\n// the flag the host takes its height from the hosted react-native subtree like\n// any other view, and RNHostView still sizes the SwiftUI side from that\n// subtree's yoga bounds.\n\ntype SwiftUIModule = {\n Button: ComponentType<any>\n ContextMenu: ComponentType<any> & {\n Trigger: ComponentType<any>\n Items: ComponentType<any>\n }\n Host: ComponentType<any>\n Menu: ComponentType<any>\n RNHostView: ComponentType<any>\n Section: ComponentType<any>\n Toggle: ComponentType<any>\n}\n\ntype SwiftUIModifiersModule = {\n disabled: (value: boolean) => unknown\n}\n\nexport function createExpoUIMenuView({\n swiftUI,\n modifiers,\n}: {\n swiftUI: SwiftUIModule\n modifiers: SwiftUIModifiersModule\n}): ComponentType<ExpoMenuViewProps> {\n const { Button, ContextMenu, Host, Menu, RNHostView, Section, Toggle } = swiftUI\n\n function renderAction(\n action: ExpoMenuAction,\n onPressAction: ExpoMenuViewProps['onPressAction']\n ): ReactNode {\n if (action.attributes?.hidden) return null\n const { subactions, displayInline, state, attributes, image, title } = action\n const systemImage = typeof image === 'string' ? image : undefined\n\n if (subactions && subactions.length > 0) {\n const children = subactions.map((sub) => renderAction(sub, onPressAction))\n if (displayInline) {\n return (\n <Section key={action.id} title={title}>\n {children}\n </Section>\n )\n }\n return (\n <Menu key={action.id} label={title} systemImage={systemImage}>\n {children}\n </Menu>\n )\n }\n\n const fire = () => onPressAction?.({ nativeEvent: { event: action.id } })\n const itemModifiers = attributes?.disabled ? [modifiers.disabled(true)] : undefined\n\n if (state === 'on' || state === 'off') {\n return (\n <Toggle\n key={action.id}\n label={title}\n systemImage={systemImage}\n isOn={state === 'on'}\n onIsOnChange={fire}\n modifiers={itemModifiers}\n />\n )\n }\n\n return (\n <Button\n key={action.id}\n label={title}\n systemImage={systemImage}\n role={attributes?.destructive ? 'destructive' : undefined}\n modifiers={itemModifiers}\n onPress={fire}\n />\n )\n }\n\n return function ExpoUIMenuView({\n actions,\n onPressAction,\n shouldOpenOnLongPress,\n title,\n children,\n }: ExpoMenuViewProps) {\n const items = actions.map((action) => renderAction(action, onPressAction))\n const body = title ? <Section title={title}>{items}</Section> : items\n // RNHostView takes exactly one element, so the trigger children ride in a\n // fragment\n const trigger = (\n <RNHostView matchContents>\n <>{children}</>\n </RNHostView>\n )\n return (\n <Host ignoreSafeArea=\"all\">\n {shouldOpenOnLongPress ? (\n <ContextMenu>\n <ContextMenu.Trigger>{trigger}</ContextMenu.Trigger>\n <ContextMenu.Items>{body}</ContextMenu.Items>\n </ContextMenu>\n ) : (\n <Menu label={trigger}>{body}</Menu>\n )}\n </Host>\n )\n }\n}\n"
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
],
|
|
7
7
|
"version": 3,
|
|
8
8
|
"sourcesContent": [
|
|
9
|
-
"/**\n * Setup Expo UI for Tamagui native Menu and ContextMenu components.\n *\n * Import this module once at the top of the app entry point after installing\n * `@expo/ui`.\n */\n\nimport { createExpoUIMenuAdapter } from './expoUIMenuAdapter'\nimport { registerNativeMenuAdapter } from './nativeMenuState'\n\nfunction setup(): void {\n let MenuView\n try {\n MenuView = require('@expo/ui/
|
|
9
|
+
"/**\n * Setup Expo UI for Tamagui native Menu and ContextMenu components.\n *\n * Import this module once at the top of the app entry point after installing\n * `@expo/ui`.\n */\n\nimport { createExpoUIMenuAdapter } from './expoUIMenuAdapter'\nimport { createExpoUIMenuView } from './expoUIMenuView'\nimport { registerNativeMenuAdapter } from './nativeMenuState'\n\nfunction setup(): void {\n let MenuView\n try {\n MenuView = createExpoUIMenuView({\n swiftUI: require('@expo/ui/swift-ui'),\n modifiers: require('@expo/ui/swift-ui/modifiers'),\n })\n } catch (error) {\n if (process.env.NODE_ENV === 'development') {\n console.warn('Error setting up Expo UI native menus', error)\n }\n return\n }\n\n registerNativeMenuAdapter(createExpoUIMenuAdapter({ MenuView }))\n}\n\nsetup()\n"
|
|
10
10
|
]
|
|
11
11
|
}
|