@tamagui/native 2.7.0 → 2.7.2
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/.turbo/turbo-build.log +1 -1
- package/dist/cjs/expoUIMenuAdapter.cjs +22 -8
- package/dist/cjs/expoUIMenuAdapter.native.js +22 -8
- package/dist/cjs/expoUIMenuAdapter.native.js.map +1 -1
- package/dist/esm/expoUIMenuAdapter.mjs +22 -8
- package/dist/esm/expoUIMenuAdapter.mjs.map +1 -1
- package/dist/esm/expoUIMenuAdapter.native.js +22 -8
- package/dist/esm/expoUIMenuAdapter.native.js.map +1 -1
- package/package.json +2 -2
- package/src/expoUIMenuAdapter.tsx +42 -12
- package/types/expoUIMenuAdapter.d.ts.map +2 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
$ tamagui-build
|
|
2
|
-
built @tamagui/native in
|
|
2
|
+
built @tamagui/native in 3473 ms
|
|
@@ -43,14 +43,28 @@ function marker(name) {
|
|
|
43
43
|
Marker.displayName = `ExpoUI${name}`;
|
|
44
44
|
return Marker;
|
|
45
45
|
}
|
|
46
|
+
function isMarkerType(candidate, type) {
|
|
47
|
+
if (candidate === type) return true;
|
|
48
|
+
const wanted = type.displayName;
|
|
49
|
+
if (!wanted) return false;
|
|
50
|
+
return typeof candidate === "function" && candidate.displayName === wanted;
|
|
51
|
+
}
|
|
46
52
|
function elementOfType(children, type) {
|
|
47
53
|
for (const child of import_react.default.Children.toArray(children)) {
|
|
48
|
-
if (import_react.default.isValidElement(child) && child.type
|
|
54
|
+
if (import_react.default.isValidElement(child) && isMarkerType(child.type, type)) {
|
|
49
55
|
return child;
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
58
|
return null;
|
|
53
59
|
}
|
|
60
|
+
const warnedUnsupported = /* @__PURE__ */new Set();
|
|
61
|
+
function warnUnsupported(feature) {
|
|
62
|
+
if (warnedUnsupported.has(feature) || process.env.NODE_ENV === "production") {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
warnedUnsupported.add(feature);
|
|
66
|
+
console.warn(`[Tamagui] @expo/ui/community/menu does not support ${feature}, so it will not render. Register a different native menu adapter if you need it.`);
|
|
67
|
+
}
|
|
54
68
|
function textFromNode(node) {
|
|
55
69
|
if (typeof node === "string" || typeof node === "number") return String(node);
|
|
56
70
|
if (!import_react.default.isValidElement(node)) return "";
|
|
@@ -88,7 +102,7 @@ function createExpoUIMenuAdapter({
|
|
|
88
102
|
const preview = elementOfType(children, Preview);
|
|
89
103
|
const auxiliary = elementOfType(children, Auxiliary);
|
|
90
104
|
if (preview || auxiliary) {
|
|
91
|
-
|
|
105
|
+
warnUnsupported("context-menu previews or auxiliary views");
|
|
92
106
|
}
|
|
93
107
|
if (!trigger || !content) {
|
|
94
108
|
throw new Error("Tamagui native menus require one Trigger and one Content");
|
|
@@ -149,12 +163,12 @@ function createExpoUIMenuAdapter({
|
|
|
149
163
|
}
|
|
150
164
|
for (const child of import_react.default.Children.toArray(childrenToParse)) {
|
|
151
165
|
if (!import_react.default.isValidElement(child)) continue;
|
|
152
|
-
if (child.type
|
|
166
|
+
if (isMarkerType(child.type, Separator)) {
|
|
153
167
|
if (!section) section = actions.splice(0);
|
|
154
168
|
flushSection();
|
|
155
169
|
continue;
|
|
156
170
|
}
|
|
157
|
-
if (child.type
|
|
171
|
+
if (isMarkerType(child.type, Group)) {
|
|
158
172
|
const label2 = elementOfType(child.props.children, Label);
|
|
159
173
|
append({
|
|
160
174
|
id: actionId(child),
|
|
@@ -164,7 +178,7 @@ function createExpoUIMenuAdapter({
|
|
|
164
178
|
});
|
|
165
179
|
continue;
|
|
166
180
|
}
|
|
167
|
-
if (child.type
|
|
181
|
+
if (isMarkerType(child.type, Sub)) {
|
|
168
182
|
const subTrigger = elementOfType(child.props.children, SubTrigger);
|
|
169
183
|
const subContent = elementOfType(child.props.children, SubContent);
|
|
170
184
|
if (!subTrigger || !subContent) {
|
|
@@ -179,12 +193,12 @@ function createExpoUIMenuAdapter({
|
|
|
179
193
|
});
|
|
180
194
|
continue;
|
|
181
195
|
}
|
|
182
|
-
if (child.type
|
|
196
|
+
if (!isMarkerType(child.type, Item) && !isMarkerType(child.type, CheckboxItem)) continue;
|
|
183
197
|
if (elementOfType(child.props.children, ItemSubtitle)) {
|
|
184
|
-
|
|
198
|
+
warnUnsupported("menu item subtitles");
|
|
185
199
|
}
|
|
186
200
|
const id = actionId(child);
|
|
187
|
-
if (child.type
|
|
201
|
+
if (isMarkerType(child.type, CheckboxItem)) {
|
|
188
202
|
const current = child.props.value === true || child.props.value === "on" || child.props.checked === true;
|
|
189
203
|
const onValueChange = child.props.onValueChange;
|
|
190
204
|
const onCheckedChange = child.props.onCheckedChange;
|
|
@@ -52,6 +52,12 @@ function marker(name) {
|
|
|
52
52
|
Marker.displayName = `ExpoUI${name}`;
|
|
53
53
|
return Marker;
|
|
54
54
|
}
|
|
55
|
+
function isMarkerType(candidate, type) {
|
|
56
|
+
if (candidate === type) return true;
|
|
57
|
+
var wanted = type.displayName;
|
|
58
|
+
if (!wanted) return false;
|
|
59
|
+
return typeof candidate === "function" && candidate.displayName === wanted;
|
|
60
|
+
}
|
|
55
61
|
function elementOfType(children, type) {
|
|
56
62
|
var _iteratorNormalCompletion = true,
|
|
57
63
|
_didIteratorError = false,
|
|
@@ -59,7 +65,7 @@ function elementOfType(children, type) {
|
|
|
59
65
|
try {
|
|
60
66
|
for (var _iterator = import_react.default.Children.toArray(children)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
61
67
|
var child = _step.value;
|
|
62
|
-
if (/* @__PURE__ */import_react.default.isValidElement(child) && child.type
|
|
68
|
+
if (/* @__PURE__ */import_react.default.isValidElement(child) && isMarkerType(child.type, type)) {
|
|
63
69
|
return child;
|
|
64
70
|
}
|
|
65
71
|
}
|
|
@@ -79,6 +85,14 @@ function elementOfType(children, type) {
|
|
|
79
85
|
}
|
|
80
86
|
return null;
|
|
81
87
|
}
|
|
88
|
+
var warnedUnsupported = /* @__PURE__ */new Set();
|
|
89
|
+
function warnUnsupported(feature) {
|
|
90
|
+
if (warnedUnsupported.has(feature) || process.env.NODE_ENV === "production") {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
warnedUnsupported.add(feature);
|
|
94
|
+
console.warn(`[Tamagui] @expo/ui/community/menu does not support ${feature}, so it will not render. Register a different native menu adapter if you need it.`);
|
|
95
|
+
}
|
|
82
96
|
function textFromNode(node) {
|
|
83
97
|
if (typeof node === "string" || typeof node === "number") return String(node);
|
|
84
98
|
if (! /* @__PURE__ */import_react.default.isValidElement(node)) return "";
|
|
@@ -118,7 +132,7 @@ function createExpoUIMenuAdapter(param) {
|
|
|
118
132
|
var preview = elementOfType(children, Preview);
|
|
119
133
|
var auxiliary = elementOfType(children, Auxiliary);
|
|
120
134
|
if (preview || auxiliary) {
|
|
121
|
-
|
|
135
|
+
warnUnsupported("context-menu previews or auxiliary views");
|
|
122
136
|
}
|
|
123
137
|
if (!trigger || !content) {
|
|
124
138
|
throw new Error("Tamagui native menus require one Trigger and one Content");
|
|
@@ -184,12 +198,12 @@ function createExpoUIMenuAdapter(param) {
|
|
|
184
198
|
var _loop = function () {
|
|
185
199
|
var child = _step.value;
|
|
186
200
|
if (! /* @__PURE__ */import_react.default.isValidElement(child)) return "continue";
|
|
187
|
-
if (child.type
|
|
201
|
+
if (isMarkerType(child.type, Separator)) {
|
|
188
202
|
if (!section) section = actions.splice(0);
|
|
189
203
|
flushSection();
|
|
190
204
|
return "continue";
|
|
191
205
|
}
|
|
192
|
-
if (child.type
|
|
206
|
+
if (isMarkerType(child.type, Group)) {
|
|
193
207
|
var label2 = elementOfType(child.props.children, Label);
|
|
194
208
|
append({
|
|
195
209
|
id: actionId(child),
|
|
@@ -199,7 +213,7 @@ function createExpoUIMenuAdapter(param) {
|
|
|
199
213
|
});
|
|
200
214
|
return "continue";
|
|
201
215
|
}
|
|
202
|
-
if (child.type
|
|
216
|
+
if (isMarkerType(child.type, Sub)) {
|
|
203
217
|
var subTrigger = elementOfType(child.props.children, SubTrigger);
|
|
204
218
|
var subContent = elementOfType(child.props.children, SubContent);
|
|
205
219
|
if (!subTrigger || !subContent) {
|
|
@@ -214,12 +228,12 @@ function createExpoUIMenuAdapter(param) {
|
|
|
214
228
|
});
|
|
215
229
|
return "continue";
|
|
216
230
|
}
|
|
217
|
-
if (child.type
|
|
231
|
+
if (!isMarkerType(child.type, Item) && !isMarkerType(child.type, CheckboxItem)) return "continue";
|
|
218
232
|
if (elementOfType(child.props.children, ItemSubtitle)) {
|
|
219
|
-
|
|
233
|
+
warnUnsupported("menu item subtitles");
|
|
220
234
|
}
|
|
221
235
|
var id = actionId(child);
|
|
222
|
-
if (child.type
|
|
236
|
+
if (isMarkerType(child.type, CheckboxItem)) {
|
|
223
237
|
var current = child.props.value === true || child.props.value === "on" || child.props.checked === true;
|
|
224
238
|
var onValueChange = child.props.onValueChange;
|
|
225
239
|
var onCheckedChange = child.props.onCheckedChange;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","expoUIMenuAdapter_exports","__export","createExpoUIMenuAdapter","module","exports","import_jsx_runtime","require","import_react","__toESM","_type_of","obj","Symbol","constructor","marker","name","Marker","displayName","
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","expoUIMenuAdapter_exports","__export","createExpoUIMenuAdapter","module","exports","import_jsx_runtime","require","import_react","__toESM","_type_of","obj","Symbol","constructor","marker","name","Marker","displayName","isMarkerType","candidate","type","wanted","elementOfType","children","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","default","Children","toArray","iterator","_step","next","done","child","isValidElement","err","return","warnedUnsupported","Set","warnUnsupported","feature","has","process","env","NODE_ENV","add","console","warn","textFromNode","node","String","props","map","join","param","MenuView","NativeMenuView","createModule","isContextMenu","Trigger","Content","Item","ItemTitle","ItemSubtitle","ItemIcon","ItemImage","ItemIndicator","Group","Label","Separator","Sub","SubTrigger","SubContent","CheckboxItem","Preview","Auxiliary","Root","param2","onOpenChange","onOpenWillChange","trigger","content","preview","auxiliary","Error","nextId","handlers","Map","actionId","element","key","replace","itemTitle","textValue","title","actionImage","image","source","icon","ios","iosIconName","attributes","destructive","disabled","hidden","actionsFrom","childrenToParse","actions","section","append","action","push","flushSection","length","id","subactions","displayInline","_loop","splice","label2","subTrigger","subContent","current","checked","onValueChange","onCheckedChange","set","state","onSelect","label","triggerAction","jsx","shouldOpenOnLongPress","onPressAction","event","_handlers_get","get","nativeEvent"],"sources":["../../src/expoUIMenuAdapter.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,yBAAA;AAAAC,QAAA,CAAAD,yBAAA;EAAAE,uBAAA,EAAAA,CAAA,KAAAA;AAAA;AACAC,MAAA,CAAAC,OAAA,GAAAT,YAAkB,CAAAK,yBAAA;AA4SV,IAAAK,kBAAA,GAAAC,OAAA;AAvQR,IAAAC,YAAgB,GAAAC,OAA0C,CAAAF,OAAA;AACxD,SAAMG,QAASA,CAAAC,GAAA,EAAM;EACrB,uBAAqB;;EACrB,OAAOA,GAAA,WAAAC,MAAA,oBAAAD,GAAA,CAAAE,WAAA,KAAAD,MAAA,qBAAAD,GAAA;AACT;AAEA,SAASG,OAAAC,IAAA,EAAa;EACpB,IAAIC,MAAA,YAAAA,CAAA,EAAoB;IAMxB,OAAM;EACN;EACAA,MAAA,CACEC,WAAO,YAAcF,IAAA;EAGzB,OAAAC,MAAA;AAEA;AAIE,SAAAE,YAAWA,CAASC,SAAA,EAAAC,IAAA;EAClB,IAAAD,SAAI,KAAAC,IAAA,SAAM;EACR,IAAAC,MAAA,GAAOD,IAAA,CAAAH,WA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
6
|
return Marker;
|
|
7
7
|
}
|
|
8
|
+
function isMarkerType(candidate, type) {
|
|
9
|
+
if (candidate === type) return true;
|
|
10
|
+
const wanted = type.displayName;
|
|
11
|
+
if (!wanted) return false;
|
|
12
|
+
return typeof candidate === "function" && candidate.displayName === wanted;
|
|
13
|
+
}
|
|
8
14
|
function elementOfType(children, type) {
|
|
9
15
|
for (const child of React.Children.toArray(children)) {
|
|
10
|
-
if (React.isValidElement(child) && child.type
|
|
16
|
+
if (React.isValidElement(child) && isMarkerType(child.type, type)) {
|
|
11
17
|
return child;
|
|
12
18
|
}
|
|
13
19
|
}
|
|
14
20
|
return null;
|
|
15
21
|
}
|
|
22
|
+
const warnedUnsupported = /* @__PURE__ */new Set();
|
|
23
|
+
function warnUnsupported(feature) {
|
|
24
|
+
if (warnedUnsupported.has(feature) || process.env.NODE_ENV === "production") {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
warnedUnsupported.add(feature);
|
|
28
|
+
console.warn(`[Tamagui] @expo/ui/community/menu does not support ${feature}, so it will not render. Register a different native menu adapter if you need it.`);
|
|
29
|
+
}
|
|
16
30
|
function textFromNode(node) {
|
|
17
31
|
if (typeof node === "string" || typeof node === "number") return String(node);
|
|
18
32
|
if (!React.isValidElement(node)) return "";
|
|
@@ -50,7 +64,7 @@ function createExpoUIMenuAdapter({
|
|
|
50
64
|
const preview = elementOfType(children, Preview);
|
|
51
65
|
const auxiliary = elementOfType(children, Auxiliary);
|
|
52
66
|
if (preview || auxiliary) {
|
|
53
|
-
|
|
67
|
+
warnUnsupported("context-menu previews or auxiliary views");
|
|
54
68
|
}
|
|
55
69
|
if (!trigger || !content) {
|
|
56
70
|
throw new Error("Tamagui native menus require one Trigger and one Content");
|
|
@@ -111,12 +125,12 @@ function createExpoUIMenuAdapter({
|
|
|
111
125
|
}
|
|
112
126
|
for (const child of React.Children.toArray(childrenToParse)) {
|
|
113
127
|
if (!React.isValidElement(child)) continue;
|
|
114
|
-
if (child.type
|
|
128
|
+
if (isMarkerType(child.type, Separator)) {
|
|
115
129
|
if (!section) section = actions.splice(0);
|
|
116
130
|
flushSection();
|
|
117
131
|
continue;
|
|
118
132
|
}
|
|
119
|
-
if (child.type
|
|
133
|
+
if (isMarkerType(child.type, Group)) {
|
|
120
134
|
const label2 = elementOfType(child.props.children, Label);
|
|
121
135
|
append({
|
|
122
136
|
id: actionId(child),
|
|
@@ -126,7 +140,7 @@ function createExpoUIMenuAdapter({
|
|
|
126
140
|
});
|
|
127
141
|
continue;
|
|
128
142
|
}
|
|
129
|
-
if (child.type
|
|
143
|
+
if (isMarkerType(child.type, Sub)) {
|
|
130
144
|
const subTrigger = elementOfType(child.props.children, SubTrigger);
|
|
131
145
|
const subContent = elementOfType(child.props.children, SubContent);
|
|
132
146
|
if (!subTrigger || !subContent) {
|
|
@@ -141,12 +155,12 @@ function createExpoUIMenuAdapter({
|
|
|
141
155
|
});
|
|
142
156
|
continue;
|
|
143
157
|
}
|
|
144
|
-
if (child.type
|
|
158
|
+
if (!isMarkerType(child.type, Item) && !isMarkerType(child.type, CheckboxItem)) continue;
|
|
145
159
|
if (elementOfType(child.props.children, ItemSubtitle)) {
|
|
146
|
-
|
|
160
|
+
warnUnsupported("menu item subtitles");
|
|
147
161
|
}
|
|
148
162
|
const id = actionId(child);
|
|
149
|
-
if (child.type
|
|
163
|
+
if (isMarkerType(child.type, CheckboxItem)) {
|
|
150
164
|
const current = child.props.value === true || child.props.value === "on" || child.props.checked === true;
|
|
151
165
|
const onValueChange = child.props.onValueChange;
|
|
152
166
|
const onCheckedChange = child.props.onCheckedChange;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","jsx","marker","name","Marker","displayName","
|
|
1
|
+
{"version":3,"names":["React","jsx","marker","name","Marker","displayName","isMarkerType","candidate","type","wanted","elementOfType","children","child","Children","toArray","isValidElement","warnedUnsupported","Set","warnUnsupported","feature","has","process","env","NODE_ENV","add","console","warn","textFromNode","node","String","props","map","join","createExpoUIMenuAdapter","MenuView","NativeMenuView","createModule","isContextMenu","Trigger","Content","Item","ItemTitle","ItemSubtitle","ItemIcon","ItemImage","ItemIndicator","Group","Label","Separator","Sub","SubTrigger","SubContent","CheckboxItem","Preview","Auxiliary","Root","onOpenChange","onOpenWillChange","trigger","content","preview","auxiliary","Error","nextId","handlers","Map","actionId","element","key","replace","itemTitle","textValue","title","actionImage","image","source","icon","ios","iosIconName","attributes","destructive","disabled","hidden","actionsFrom","childrenToParse","actions","section","append","action","push","flushSection","length","id","subactions","displayInline","splice","label","label2","subTrigger","subContent","current","value","checked","onValueChange","onCheckedChange","set","state","onSelect","triggerAction","shouldOpenOnLongPress","onPressAction","event","get","nativeEvent","onOpenMenu","onCloseMenu","Menu","ContextMenu"],"sources":["../../src/expoUIMenuAdapter.tsx"],"sourcesContent":[null],"mappings":"AACA,OAAOA,KAAA,MAAW;AA4SV,SAAAC,GAAA;AAvQR,SAASC,OAAOC,IAAA,EAA0C;EACxD,MAAMC,MAAA,GAASA,CAAA,KAAM;EACrBA,MAAA,CAAOC,WAAA,GAAc,SAASF,IAAI;EAClC,OAAOC,MAAA;AACT;AAEA,SAASE,aAAaC,SAAA,EAAoBC,IAAA,EAA2C;EACnF,IAAID,SAAA,KAAcC,IAAA,EAAM,OAAO;EAM/B,MAAMC,MAAA,GAAUD,IAAA,CAAkCH,WAAA;EAClD,IAAI,CAACI,MAAA,EAAQ,OAAO;EACpB,OACE,OAAOF,SAAA,KAAc,cACpBA,SAAA,CAAuCF,WAAA,KAAgBI,MAAA;AAE5D;AAEA,SAASC,cACPC,QAAA,EACAH,IAAA,EACkC;EAClC,WAAWI,KAAA,IAASZ,KAAA,CAAMa,QAAA,CAASC,OAAA,CAAQH,QAAQ,GAAG;IACpD,IAAIX,KAAA,CAAMe,cAAA,CAA4BH,KAAK,KAAKN,YAAA,CAAaM,KAAA,CAAMJ,IAAA,EAAMA,IAAI,GAAG;MAC9E,OAAOI,KAAA;IACT;EACF;EACA,OAAO;AACT;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,GAAQrE,YAAA,CAAaqE,KAAA,CAAMlE,KAAA,CAAMnB,QAAQ,IAAI;QACpDkG,qBAAA,EACED,aAAA,KAAkB,eAAgBA,aAAA,KAAkB,WAAWvE,aAAA;QAEjEyE,aAAA,EAAgBC,KAAA,IAAU/C,QAAA,CAASgD,GAAA,CAAID,KAAA,CAAME,WAAA,CAAYF,KAAK,IAAI;QAClEG,UAAA,EAAYA,CAAA,KAAM;UAChBzD,gBAAA,GAAmB,IAAI;UACvBD,YAAA,GAAe,IAAI;QACrB;QACA2D,WAAA,EAAaA,CAAA,KAAM;UACjB1D,gBAAA,GAAmB,KAAK;UACxBD,YAAA,GAAe,KAAK;QACtB;QAEC7C,QAAA,EAAA+C,OAAA,CAAQ5B,KAAA,CAAMnB;MAAA,CACjB;IAEJ;IAEA,OAAO;MACL4C,IAAA;MACAjB,OAAA;MACAC,OAAA;MACAC,IAAA;MACAC,SAAA;MACAC,YAAA;MACAC,QAAA;MACAC,SAAA;MACAC,aAAA;MACAC,KAAA;MACAC,KAAA;MACAC,SAAA;MACAC,GAAA;MACAC,UAAA;MACAC,UAAA;MACAC,YAAA;MACAC,OAAA;MACAC;IACF;EACF;EAEA,OAAO;IACLnD,IAAA,EAAM;IACNiH,IAAA,EAAMhF,YAAA,CAAa,KAAK;IACxBiF,WAAA,EAAajF,YAAA,CAAa,IAAI;EAChC;AACF","ignoreList":[]}
|
|
@@ -12,6 +12,12 @@ function marker(name) {
|
|
|
12
12
|
Marker.displayName = `ExpoUI${name}`;
|
|
13
13
|
return Marker;
|
|
14
14
|
}
|
|
15
|
+
function isMarkerType(candidate, type) {
|
|
16
|
+
if (candidate === type) return true;
|
|
17
|
+
var wanted = type.displayName;
|
|
18
|
+
if (!wanted) return false;
|
|
19
|
+
return typeof candidate === "function" && candidate.displayName === wanted;
|
|
20
|
+
}
|
|
15
21
|
function elementOfType(children, type) {
|
|
16
22
|
var _iteratorNormalCompletion = true,
|
|
17
23
|
_didIteratorError = false,
|
|
@@ -19,7 +25,7 @@ function elementOfType(children, type) {
|
|
|
19
25
|
try {
|
|
20
26
|
for (var _iterator = React.Children.toArray(children)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
21
27
|
var child = _step.value;
|
|
22
|
-
if (/* @__PURE__ */React.isValidElement(child) && child.type
|
|
28
|
+
if (/* @__PURE__ */React.isValidElement(child) && isMarkerType(child.type, type)) {
|
|
23
29
|
return child;
|
|
24
30
|
}
|
|
25
31
|
}
|
|
@@ -39,6 +45,14 @@ function elementOfType(children, type) {
|
|
|
39
45
|
}
|
|
40
46
|
return null;
|
|
41
47
|
}
|
|
48
|
+
var warnedUnsupported = /* @__PURE__ */new Set();
|
|
49
|
+
function warnUnsupported(feature) {
|
|
50
|
+
if (warnedUnsupported.has(feature) || process.env.NODE_ENV === "production") {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
warnedUnsupported.add(feature);
|
|
54
|
+
console.warn(`[Tamagui] @expo/ui/community/menu does not support ${feature}, so it will not render. Register a different native menu adapter if you need it.`);
|
|
55
|
+
}
|
|
42
56
|
function textFromNode(node) {
|
|
43
57
|
if (typeof node === "string" || typeof node === "number") return String(node);
|
|
44
58
|
if (! /* @__PURE__ */React.isValidElement(node)) return "";
|
|
@@ -78,7 +92,7 @@ function createExpoUIMenuAdapter(param) {
|
|
|
78
92
|
var preview = elementOfType(children, Preview);
|
|
79
93
|
var auxiliary = elementOfType(children, Auxiliary);
|
|
80
94
|
if (preview || auxiliary) {
|
|
81
|
-
|
|
95
|
+
warnUnsupported("context-menu previews or auxiliary views");
|
|
82
96
|
}
|
|
83
97
|
if (!trigger || !content) {
|
|
84
98
|
throw new Error("Tamagui native menus require one Trigger and one Content");
|
|
@@ -144,12 +158,12 @@ function createExpoUIMenuAdapter(param) {
|
|
|
144
158
|
var _loop = function () {
|
|
145
159
|
var child = _step.value;
|
|
146
160
|
if (! /* @__PURE__ */React.isValidElement(child)) return "continue";
|
|
147
|
-
if (child.type
|
|
161
|
+
if (isMarkerType(child.type, Separator)) {
|
|
148
162
|
if (!section) section = actions.splice(0);
|
|
149
163
|
flushSection();
|
|
150
164
|
return "continue";
|
|
151
165
|
}
|
|
152
|
-
if (child.type
|
|
166
|
+
if (isMarkerType(child.type, Group)) {
|
|
153
167
|
var label2 = elementOfType(child.props.children, Label);
|
|
154
168
|
append({
|
|
155
169
|
id: actionId(child),
|
|
@@ -159,7 +173,7 @@ function createExpoUIMenuAdapter(param) {
|
|
|
159
173
|
});
|
|
160
174
|
return "continue";
|
|
161
175
|
}
|
|
162
|
-
if (child.type
|
|
176
|
+
if (isMarkerType(child.type, Sub)) {
|
|
163
177
|
var subTrigger = elementOfType(child.props.children, SubTrigger);
|
|
164
178
|
var subContent = elementOfType(child.props.children, SubContent);
|
|
165
179
|
if (!subTrigger || !subContent) {
|
|
@@ -174,12 +188,12 @@ function createExpoUIMenuAdapter(param) {
|
|
|
174
188
|
});
|
|
175
189
|
return "continue";
|
|
176
190
|
}
|
|
177
|
-
if (child.type
|
|
191
|
+
if (!isMarkerType(child.type, Item) && !isMarkerType(child.type, CheckboxItem)) return "continue";
|
|
178
192
|
if (elementOfType(child.props.children, ItemSubtitle)) {
|
|
179
|
-
|
|
193
|
+
warnUnsupported("menu item subtitles");
|
|
180
194
|
}
|
|
181
195
|
var id = actionId(child);
|
|
182
|
-
if (child.type
|
|
196
|
+
if (isMarkerType(child.type, CheckboxItem)) {
|
|
183
197
|
var current = child.props.value === true || child.props.value === "on" || child.props.checked === true;
|
|
184
198
|
var onValueChange = child.props.onValueChange;
|
|
185
199
|
var onCheckedChange = child.props.onCheckedChange;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["jsx","_jsx","React","_type_of","obj","Symbol","constructor","marker","name","Marker","displayName","
|
|
1
|
+
{"version":3,"names":["jsx","_jsx","React","_type_of","obj","Symbol","constructor","marker","name","Marker","displayName","isMarkerType","candidate","type","wanted","elementOfType","children","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","Children","toArray","iterator","_step","next","done","child","value","isValidElement","err","return","warnedUnsupported","Set","warnUnsupported","feature","has","process","env","NODE_ENV","add","console","warn","textFromNode","node","String","props","map","join","createExpoUIMenuAdapter","param","MenuView","NativeMenuView","createModule","isContextMenu","Trigger","Content","Item","ItemTitle","ItemSubtitle","ItemIcon","ItemImage","ItemIndicator","Group","Label","Separator","Sub","SubTrigger","SubContent","CheckboxItem","Preview","Auxiliary","Root","param2","onOpenChange","onOpenWillChange","trigger","content","preview","auxiliary","Error","nextId","handlers","Map","actionId","element","key","replace","itemTitle","textValue","title","actionImage","image","source","icon","ios","iosIconName","attributes","destructive","disabled","hidden","actionsFrom","childrenToParse","actions","section","append","action","push","flushSection","length","id","subactions","displayInline","_loop","splice","label2","subTrigger","subContent","current","checked","onValueChange","onCheckedChange","set","state","onSelect","label","triggerAction","shouldOpenOnLongPress","onPressAction","event","_handlers_get","get","nativeEvent"],"sources":["../../src/expoUIMenuAdapter.tsx"],"sourcesContent":[null],"mappings":"AACA,SAAOA,GAAA,IAAAC,IAAW;AA4SV,OAAAC,KAAA;AAvQR,SAASC,QAAOA,CAAAC,GAAA,EAA0C;EACxD,uBAAqB;;EACrB,OAAOA,GAAA,WAAcC,MAAA,KAAS,WAAI,IAAAD,GAAA,CAAAE,WAAA,KAAAD,MAAA,qBAAAD,GAAA;AAClC;AACF,SAAAG,OAAAC,IAAA;EAEA,IAAAC,MAAS,YAAAA,CAAA,EAAa;IACpB,OAAI;EAMJ;EACAA,MAAK,CAAAC,WAAQ,GAAO,SAAAF,IAAA;EACpB,OACEC,MAAA;AAGJ;AAEA,SAASE,aAAAC,SACP,EACAC,IAAA,EACkC;EAClC,IAAAD,SAAW,KAAAC,IAAS,SAAM,IAAS;EACjC,IAAAC,MAAI,GAAMD,IAAA,CAAAH,WAA4B;EACpC,KAAAI,MAAO;EAAA,OACT,OAAAF,SAAA,mBAAAA,SAAA,CAAAF,WAAA,K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,SAAA,CAAAK,IAAA,IAAAC,IAAA,GAAAT,yBAAA,SAAAgG,KAAA;QAEA,SAAOnF,GAAA;UACLZ,iBAAA;UACAC,cAAA,GAAAW,GAAA;QACA;UACA;YACA,KAAAb,yBAAA,IAAAG,SAAA,CAAAW,MAAA;cACAX,SAAA,CAAAW,MAAA;YACA;UACA;YACA,IAAAb,iBAAA;cACA,MAAAC,cAAA;YACA;UACA;QACA;QACA,IAAAqF,OAAA,EAAAI,YAAA;QACA,OAAAL,OAAA;MACA;MACA,IAAAsB,KAAA,GAAA9G,aAAA,CAAA8D,OAAA,CAAA/B,KAAA,CAAA9B,QAAA,EAAAgD,KAAA;MACA,IAAA8D,aAAA,GAAAlD,OAAA,CAAA9B,KAAA,CAAA4D,MAAA;MACF,sBAAAzG,IAAA,CAAAmD,cAAA;QACFmD,OAAA,EAAAF,WAAA,CAAAxB,OAAA,CAAA/B,KAAA,CAAA9B,QAAA;QAEA0E,KAAO,EAAAmC,KAAA,GAAAlF,YAAA,CAAAkF,KAAA,CAAA/E,KAAA,CAAA9B,QAAA;QACL+G,qBAAM,EAAAD,aAAA,oBAAAA,aAAA,gBAAAxE,aAAA;QACN0E,aAAM,EAAa,SAAAA,CAAKC,KAAA;UACxB,IAAAC,aAAa;UACf,QAAAA,aAAA,GAAAhD,QAAA,CAAAiD,GAAA,CAAAF,KAAA,CAAAG,WAAA,CAAAH,KAAA,eAAAC,aAAA,uBAAAA,aAAA;QACF","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/native",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.2",
|
|
4
4
|
"description": "Native setup modules for Tamagui - portals, gesture handler, worklets, and more",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -156,7 +156,7 @@
|
|
|
156
156
|
"clean:build": "tamagui-build clean:build"
|
|
157
157
|
},
|
|
158
158
|
"devDependencies": {
|
|
159
|
-
"@tamagui/build": "2.7.
|
|
159
|
+
"@tamagui/build": "2.7.2",
|
|
160
160
|
"burnt": "^0.12.2",
|
|
161
161
|
"react": ">=19",
|
|
162
162
|
"react-native": "0.83.2",
|
|
@@ -42,18 +42,51 @@ function marker(name: string): ComponentType<MarkerProps> {
|
|
|
42
42
|
return Marker
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
function isMarkerType(candidate: unknown, type: ComponentType<MarkerProps>): boolean {
|
|
46
|
+
if (candidate === type) return true
|
|
47
|
+
// createMenu runs every native component through withNativeMenu, which wraps
|
|
48
|
+
// it in a new function component and copies the marker's displayName onto the
|
|
49
|
+
// wrapper. that wrapper is a different reference, so an identity-only check
|
|
50
|
+
// matches nothing and every item silently comes back with an empty title, no
|
|
51
|
+
// icon, and no submenu. fall back to the (unique, ExpoUI-prefixed) name.
|
|
52
|
+
const wanted = (type as { displayName?: string }).displayName
|
|
53
|
+
if (!wanted) return false
|
|
54
|
+
return (
|
|
55
|
+
typeof candidate === 'function' &&
|
|
56
|
+
(candidate as { displayName?: string }).displayName === wanted
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
45
60
|
function elementOfType(
|
|
46
61
|
children: ReactNode,
|
|
47
62
|
type: ComponentType<MarkerProps>
|
|
48
63
|
): ReactElement<MarkerProps> | null {
|
|
49
64
|
for (const child of React.Children.toArray(children)) {
|
|
50
|
-
if (React.isValidElement<MarkerProps>(child) && child.type
|
|
65
|
+
if (React.isValidElement<MarkerProps>(child) && isMarkerType(child.type, type)) {
|
|
51
66
|
return child
|
|
52
67
|
}
|
|
53
68
|
}
|
|
54
69
|
return null
|
|
55
70
|
}
|
|
56
71
|
|
|
72
|
+
const warnedUnsupported = new Set<string>()
|
|
73
|
+
|
|
74
|
+
// @expo/ui's MenuAction carries no subtitle, and its MenuView has no preview or
|
|
75
|
+
// auxiliary view. these are decorations on a menu that is otherwise complete, so
|
|
76
|
+
// drop them and warn once. throwing took down the whole app for an optional
|
|
77
|
+
// embellishment, and an app that renders the same menu on zeego and on expo-ui
|
|
78
|
+
// cannot avoid it without forking its markup per adapter.
|
|
79
|
+
function warnUnsupported(feature: string) {
|
|
80
|
+
if (warnedUnsupported.has(feature) || process.env.NODE_ENV === 'production') {
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
warnedUnsupported.add(feature)
|
|
84
|
+
console.warn(
|
|
85
|
+
`[Tamagui] @expo/ui/community/menu does not support ${feature}, so it will not render. ` +
|
|
86
|
+
`Register a different native menu adapter if you need it.`
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
57
90
|
function textFromNode(node: ReactNode): string {
|
|
58
91
|
if (typeof node === 'string' || typeof node === 'number') return String(node)
|
|
59
92
|
if (!React.isValidElement<MarkerProps>(node)) return ''
|
|
@@ -99,9 +132,7 @@ export function createExpoUIMenuAdapter({
|
|
|
99
132
|
const auxiliary = elementOfType(children, Auxiliary)
|
|
100
133
|
|
|
101
134
|
if (preview || auxiliary) {
|
|
102
|
-
|
|
103
|
-
'@expo/ui/community/menu does not support Tamagui context-menu previews or auxiliary views'
|
|
104
|
-
)
|
|
135
|
+
warnUnsupported('context-menu previews or auxiliary views')
|
|
105
136
|
}
|
|
106
137
|
if (!trigger || !content) {
|
|
107
138
|
throw new Error('Tamagui native menus require one Trigger and one Content')
|
|
@@ -181,13 +212,13 @@ export function createExpoUIMenuAdapter({
|
|
|
181
212
|
for (const child of React.Children.toArray(childrenToParse)) {
|
|
182
213
|
if (!React.isValidElement<MarkerProps>(child)) continue
|
|
183
214
|
|
|
184
|
-
if (child.type
|
|
215
|
+
if (isMarkerType(child.type, Separator)) {
|
|
185
216
|
if (!section) section = actions.splice(0)
|
|
186
217
|
flushSection()
|
|
187
218
|
continue
|
|
188
219
|
}
|
|
189
220
|
|
|
190
|
-
if (child.type
|
|
221
|
+
if (isMarkerType(child.type, Group)) {
|
|
191
222
|
const label = elementOfType(child.props.children, Label)
|
|
192
223
|
append({
|
|
193
224
|
id: actionId(child),
|
|
@@ -198,7 +229,7 @@ export function createExpoUIMenuAdapter({
|
|
|
198
229
|
continue
|
|
199
230
|
}
|
|
200
231
|
|
|
201
|
-
if (child.type
|
|
232
|
+
if (isMarkerType(child.type, Sub)) {
|
|
202
233
|
const subTrigger = elementOfType(child.props.children, SubTrigger)
|
|
203
234
|
const subContent = elementOfType(child.props.children, SubContent)
|
|
204
235
|
if (!subTrigger || !subContent) {
|
|
@@ -216,16 +247,15 @@ export function createExpoUIMenuAdapter({
|
|
|
216
247
|
continue
|
|
217
248
|
}
|
|
218
249
|
|
|
219
|
-
if (child.type
|
|
250
|
+
if (!isMarkerType(child.type, Item) && !isMarkerType(child.type, CheckboxItem))
|
|
251
|
+
continue
|
|
220
252
|
|
|
221
253
|
if (elementOfType(child.props.children, ItemSubtitle)) {
|
|
222
|
-
|
|
223
|
-
'@expo/ui/community/menu does not support menu item subtitles'
|
|
224
|
-
)
|
|
254
|
+
warnUnsupported('menu item subtitles')
|
|
225
255
|
}
|
|
226
256
|
|
|
227
257
|
const id = actionId(child)
|
|
228
|
-
if (child.type
|
|
258
|
+
if (isMarkerType(child.type, CheckboxItem)) {
|
|
229
259
|
const current =
|
|
230
260
|
child.props.value === true ||
|
|
231
261
|
child.props.value === 'on' ||
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"mappings": "AAAA,cAAc,qBAA8C;AAG5D,cAAc,yBAA2C;AA0BzD,YAAY,2BAA2B;CACrC,UAAU;;
|
|
2
|
+
"mappings": "AAAA,cAAc,qBAA8C;AAG5D,cAAc,yBAA2C;AA0BzD,YAAY,2BAA2B;CACrC,UAAU;;AAiEZ,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 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) && child.type === type) {\n return child\n }\n }\n return null\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 throw new Error(\n '@expo/ui/community/menu does not support Tamagui context-menu previews or auxiliary views'\n )\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 (child.type === Separator) {\n if (!section) section = actions.splice(0)\n flushSection()\n continue\n }\n\n if (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 (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 (child.type !== Item && child.type !== CheckboxItem) continue\n\n if (elementOfType(child.props.children, ItemSubtitle)) {\n throw new Error(\n '@expo/ui/community/menu does not support menu item subtitles'\n )\n }\n\n const id = actionId(child)\n if (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\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, and an app that renders the same menu on zeego and on expo-ui\n// cannot avoid it without forking its 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
|
}
|