@xaui/native 0.0.28 → 0.0.29

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.
@@ -155,6 +155,7 @@ var Menu = ({
155
155
  trigger,
156
156
  position = "bottom",
157
157
  onDismiss,
158
+ onItemPress,
158
159
  children,
159
160
  customAppearance,
160
161
  maxHeight = 280
@@ -164,6 +165,17 @@ var Menu = ({
164
165
  const { contentSize, handleContentLayout, isMeasured } = useMenuContentLayout(visible);
165
166
  const menuPosition = useMenuPosition(triggerPosition, contentSize, position);
166
167
  const { opacity, scale } = useMenuAnimation(visible);
168
+ const handledChildren = _react2.default.Children.map(children, (child) => {
169
+ if (!_react2.default.isValidElement(child)) return child;
170
+ const { onPress, itemKey } = child.props;
171
+ if (!onPress && !itemKey) return child;
172
+ return _react2.default.cloneElement(child, {
173
+ onPress: (e) => {
174
+ _optionalChain([onPress, 'optionalCall', _5 => _5(e)]);
175
+ if (itemKey) _optionalChain([onItemPress, 'optionalCall', _6 => _6(itemKey)]);
176
+ }
177
+ });
178
+ });
167
179
  return /* @__PURE__ */ _react2.default.createElement(_react2.default.Fragment, null, /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { ref: triggerRef, collapsable: false }, trigger), /* @__PURE__ */ _react2.default.createElement(
168
180
  _reactnative.Modal,
169
181
  {
@@ -175,7 +187,7 @@ var Menu = ({
175
187
  /* @__PURE__ */ _react2.default.createElement(
176
188
  _reactnative.Pressable,
177
189
  {
178
- style: [styles.overlay, _optionalChain([customAppearance, 'optionalAccess', _5 => _5.overlay])],
190
+ style: [styles.overlay, _optionalChain([customAppearance, 'optionalAccess', _7 => _7.overlay])],
179
191
  onPress: onDismiss,
180
192
  accessibilityRole: "button",
181
193
  accessibilityLabel: "Close menu"
@@ -195,10 +207,10 @@ var Menu = ({
195
207
  transform: [{ scale }],
196
208
  ...theme.shadows.md
197
209
  },
198
- _optionalChain([customAppearance, 'optionalAccess', _6 => _6.container])
210
+ _optionalChain([customAppearance, 'optionalAccess', _8 => _8.container])
199
211
  ]
200
212
  },
201
- /* @__PURE__ */ _react2.default.createElement(_reactnative.Pressable, { onPress: (e) => e.stopPropagation() }, /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { style: _optionalChain([customAppearance, 'optionalAccess', _7 => _7.content]) }, /* @__PURE__ */ _react2.default.createElement(_reactnative.ScrollView, { style: { maxHeight } }, children)))
213
+ /* @__PURE__ */ _react2.default.createElement(_reactnative.Pressable, { onPress: (e) => e.stopPropagation() }, /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { style: _optionalChain([customAppearance, 'optionalAccess', _9 => _9.content]) }, /* @__PURE__ */ _react2.default.createElement(_reactnative.ScrollView, { style: { maxHeight } }, handledChildren)))
202
214
  )
203
215
  )
204
216
  ));
@@ -269,7 +281,7 @@ var MenuItem = ({
269
281
  return /* @__PURE__ */ _react2.default.createElement(
270
282
  _reactnative.Text,
271
283
  {
272
- style: [styles2.titleText, { color: titleColor }, _optionalChain([customAppearance, 'optionalAccess', _8 => _8.title])],
284
+ style: [styles2.titleText, { color: titleColor }, _optionalChain([customAppearance, 'optionalAccess', _10 => _10.title])],
273
285
  numberOfLines: 1
274
286
  },
275
287
  title
@@ -292,10 +304,10 @@ var MenuItem = ({
292
304
  pressed && !isDisabled && {
293
305
  backgroundColor: theme.colors.foreground + "10"
294
306
  },
295
- _optionalChain([customAppearance, 'optionalAccess', _9 => _9.container])
307
+ _optionalChain([customAppearance, 'optionalAccess', _11 => _11.container])
296
308
  ]
297
309
  },
298
- /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { style: [styles2.row, _optionalChain([customAppearance, 'optionalAccess', _10 => _10.content])] }, startContent && /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { style: styles2.startContent }, startContent), /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { style: styles2.content }, renderTitle()), endContent && /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { style: styles2.endContent }, endContent))
310
+ /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { style: [styles2.row, _optionalChain([customAppearance, 'optionalAccess', _12 => _12.content])] }, startContent && /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { style: styles2.startContent }, startContent), /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { style: styles2.content }, renderTitle()), endContent && /* @__PURE__ */ _react2.default.createElement(_reactnative.View, { style: styles2.endContent }, endContent))
299
311
  );
300
312
  };
301
313
 
@@ -34,6 +34,10 @@ type MenuProps = {
34
34
  * Callback called when Menu is dismissed. The `visible` prop needs to be updated when this is called.
35
35
  */
36
36
  onDismiss?: () => void;
37
+ /**
38
+ * Callback fired when a MenuItem with an `itemKey` is pressed.
39
+ */
40
+ onItemPress?: (itemKey: string) => void;
37
41
  /**
38
42
  * Content of the Menu.
39
43
  */
@@ -66,6 +70,10 @@ type MenuItemCustomAppearance = {
66
70
  title?: TextStyle;
67
71
  };
68
72
  type MenuItemProps = {
73
+ /**
74
+ * Optional key emitted via Menu `onItemPress`.
75
+ */
76
+ itemKey?: string;
69
77
  /**
70
78
  * Title text for the MenuItem.
71
79
  */
@@ -34,6 +34,10 @@ type MenuProps = {
34
34
  * Callback called when Menu is dismissed. The `visible` prop needs to be updated when this is called.
35
35
  */
36
36
  onDismiss?: () => void;
37
+ /**
38
+ * Callback fired when a MenuItem with an `itemKey` is pressed.
39
+ */
40
+ onItemPress?: (itemKey: string) => void;
37
41
  /**
38
42
  * Content of the Menu.
39
43
  */
@@ -66,6 +70,10 @@ type MenuItemCustomAppearance = {
66
70
  title?: TextStyle;
67
71
  };
68
72
  type MenuItemProps = {
73
+ /**
74
+ * Optional key emitted via Menu `onItemPress`.
75
+ */
76
+ itemKey?: string;
69
77
  /**
70
78
  * Title text for the MenuItem.
71
79
  */
@@ -155,6 +155,7 @@ var Menu = ({
155
155
  trigger,
156
156
  position = "bottom",
157
157
  onDismiss,
158
+ onItemPress,
158
159
  children,
159
160
  customAppearance,
160
161
  maxHeight = 280
@@ -164,6 +165,17 @@ var Menu = ({
164
165
  const { contentSize, handleContentLayout, isMeasured } = useMenuContentLayout(visible);
165
166
  const menuPosition = useMenuPosition(triggerPosition, contentSize, position);
166
167
  const { opacity, scale } = useMenuAnimation(visible);
168
+ const handledChildren = React.Children.map(children, (child) => {
169
+ if (!React.isValidElement(child)) return child;
170
+ const { onPress, itemKey } = child.props;
171
+ if (!onPress && !itemKey) return child;
172
+ return React.cloneElement(child, {
173
+ onPress: (e) => {
174
+ onPress?.(e);
175
+ if (itemKey) onItemPress?.(itemKey);
176
+ }
177
+ });
178
+ });
167
179
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, { ref: triggerRef, collapsable: false }, trigger), /* @__PURE__ */ React.createElement(
168
180
  Modal,
169
181
  {
@@ -198,7 +210,7 @@ var Menu = ({
198
210
  customAppearance?.container
199
211
  ]
200
212
  },
201
- /* @__PURE__ */ React.createElement(Pressable, { onPress: (e) => e.stopPropagation() }, /* @__PURE__ */ React.createElement(View, { style: customAppearance?.content }, /* @__PURE__ */ React.createElement(ScrollView, { style: { maxHeight } }, children)))
213
+ /* @__PURE__ */ React.createElement(Pressable, { onPress: (e) => e.stopPropagation() }, /* @__PURE__ */ React.createElement(View, { style: customAppearance?.content }, /* @__PURE__ */ React.createElement(ScrollView, { style: { maxHeight } }, handledChildren)))
202
214
  )
203
215
  )
204
216
  ));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xaui/native",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "description": "Flutter-inspired React Native UI components with native animations powered by React Native Reanimated",
5
5
  "keywords": [
6
6
  "react-native",