@vvedantb/native-ui 0.36.0 → 0.36.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/Button.jsx CHANGED
@@ -126,8 +126,12 @@ const PRIMITIVE_VARIANT = {
126
126
  link: "link",
127
127
  tinted: "secondary"
128
128
  };
129
- export function Button(t0) {
130
- const $ = _c(67);
129
+ /**
130
+ * Forwards `ref` to the native view, so a parent (such as `DropdownMenuTrigger
131
+ * asChild`) can measure it.
132
+ */
133
+ export const Button = React.forwardRef(function Button(t0, ref) {
134
+ const $ = _c(68);
131
135
  let children;
132
136
  let className;
133
137
  let endContent;
@@ -330,21 +334,22 @@ export function Button(t0) {
330
334
  t27 = $[55];
331
335
  }
332
336
  let t28;
333
- if ($[56] !== onPress || $[57] !== props || $[58] !== shape || $[59] !== t13 || $[60] !== t14 || $[61] !== t19 || $[62] !== t20 || $[63] !== t24 || $[64] !== t25 || $[65] !== t27) {
334
- t28 = <PrimitiveButton onPress={onPress} variant={t13} shape={shape} hitSlop={t14} accessibilityRole="button" className={t19} {...props} disabled={t20} accessibilityState={t24} style={t25}>{t27}</PrimitiveButton>;
337
+ if ($[56] !== onPress || $[57] !== props || $[58] !== ref || $[59] !== shape || $[60] !== t13 || $[61] !== t14 || $[62] !== t19 || $[63] !== t20 || $[64] !== t24 || $[65] !== t25 || $[66] !== t27) {
338
+ t28 = <PrimitiveButton ref={ref} onPress={onPress} variant={t13} shape={shape} hitSlop={t14} accessibilityRole="button" className={t19} {...props} disabled={t20} accessibilityState={t24} style={t25}>{t27}</PrimitiveButton>;
335
339
  $[56] = onPress;
336
340
  $[57] = props;
337
- $[58] = shape;
338
- $[59] = t13;
339
- $[60] = t14;
340
- $[61] = t19;
341
- $[62] = t20;
342
- $[63] = t24;
343
- $[64] = t25;
344
- $[65] = t27;
345
- $[66] = t28;
341
+ $[58] = ref;
342
+ $[59] = shape;
343
+ $[60] = t13;
344
+ $[61] = t14;
345
+ $[62] = t19;
346
+ $[63] = t20;
347
+ $[64] = t24;
348
+ $[65] = t25;
349
+ $[66] = t27;
350
+ $[67] = t28;
346
351
  } else {
347
- t28 = $[66];
352
+ t28 = $[67];
348
353
  }
349
354
  return t28;
350
- }
355
+ });
@@ -109,14 +109,46 @@ export function DropdownMenu(t0) {
109
109
  }
110
110
  return t4;
111
111
  }
112
+ /** A measured box is usable when it has a size: Android reports 0, 0, 0, 0 for a view it has not laid out. */
113
+ export function isMeasuredRect(rect) {
114
+ return rect.width > 0 && rect.height > 0;
115
+ }
116
+ /**
117
+ * The view's box in window coordinates, or `null` when it cannot be measured.
118
+ * `measureInWindow` first; when it returns an empty box, `measure` (its
119
+ * `pageX` and `pageY` are window coordinates too) as a second reading.
120
+ */
121
+ export function measureAnchor(view, done) {
122
+ view.measureInWindow((x, y, width, height) => {
123
+ const rect = {
124
+ x,
125
+ y,
126
+ width,
127
+ height
128
+ };
129
+ if (isMeasuredRect(rect)) return done(rect);
130
+ view.measure((_x, _y, w, h, pageX, pageY) => {
131
+ const second = {
132
+ x: pageX,
133
+ y: pageY,
134
+ width: w,
135
+ height: h
136
+ };
137
+ done(isMeasuredRect(second) ? second : null);
138
+ });
139
+ });
140
+ }
141
+
112
142
  /**
113
143
  * Opens the menu, or closes it when open. On press it measures itself
114
- * (`measureInWindow`) and the menu opens under it. Reports `expanded`.
144
+ * (`measureInWindow`) and the menu opens under it. Reports `expanded`. A
145
+ * caller `ref` is kept: the menu's own handle never replaces it.
115
146
  */
116
147
  export function DropdownMenuTrigger(t0) {
117
- const $ = _c(18);
148
+ const $ = _c(22);
118
149
  let accessibilityState;
119
150
  let asChild;
151
+ let callerRef;
120
152
  let onPress;
121
153
  let props;
122
154
  if ($[0] !== t0) {
@@ -124,18 +156,21 @@ export function DropdownMenuTrigger(t0) {
124
156
  asChild,
125
157
  onPress,
126
158
  accessibilityState,
159
+ ref: callerRef,
127
160
  ...props
128
161
  } = t0);
129
162
  $[0] = t0;
130
163
  $[1] = accessibilityState;
131
164
  $[2] = asChild;
132
- $[3] = onPress;
133
- $[4] = props;
165
+ $[3] = callerRef;
166
+ $[4] = onPress;
167
+ $[5] = props;
134
168
  } else {
135
169
  accessibilityState = $[1];
136
170
  asChild = $[2];
137
- onPress = $[3];
138
- props = $[4];
171
+ callerRef = $[3];
172
+ onPress = $[4];
173
+ props = $[5];
139
174
  }
140
175
  const {
141
176
  open,
@@ -145,58 +180,73 @@ export function DropdownMenuTrigger(t0) {
145
180
  const ref = useRef(null);
146
181
  const Component = asChild ? Slot.Pressable : Pressable;
147
182
  let t1;
148
- if ($[5] !== accessibilityState || $[6] !== open) {
149
- t1 = {
150
- ...accessibilityState,
151
- expanded: open
183
+ if ($[6] !== callerRef) {
184
+ t1 = view => {
185
+ ref.current = view;
186
+ if (typeof callerRef === "function") {
187
+ callerRef(view);
188
+ } else {
189
+ if (callerRef) {
190
+ callerRef.current = view;
191
+ }
192
+ }
152
193
  };
153
- $[5] = accessibilityState;
154
- $[6] = open;
194
+ $[6] = callerRef;
155
195
  $[7] = t1;
156
196
  } else {
157
197
  t1 = $[7];
158
198
  }
159
199
  let t2;
160
- if ($[8] !== onPress || $[9] !== open || $[10] !== setOpen || $[11] !== setTrigger) {
161
- t2 = event => {
200
+ if ($[8] !== accessibilityState || $[9] !== open) {
201
+ t2 = {
202
+ ...accessibilityState,
203
+ expanded: open
204
+ };
205
+ $[8] = accessibilityState;
206
+ $[9] = open;
207
+ $[10] = t2;
208
+ } else {
209
+ t2 = $[10];
210
+ }
211
+ let t3;
212
+ if ($[11] !== onPress || $[12] !== open || $[13] !== setOpen || $[14] !== setTrigger) {
213
+ t3 = event => {
162
214
  onPress?.(event);
163
215
  if (open) {
164
216
  return setOpen(false);
165
217
  }
166
- const view = ref.current;
167
- if (!view) {
218
+ const view_0 = ref.current;
219
+ if (!view_0) {
168
220
  return setOpen(true);
169
221
  }
170
- view.measureInWindow((x, y, width, height) => {
171
- setTrigger({
172
- x,
173
- y,
174
- width,
175
- height
176
- });
222
+ measureAnchor(view_0, rect => {
223
+ if (rect) {
224
+ setTrigger(rect);
225
+ }
177
226
  setOpen(true);
178
227
  });
179
228
  };
180
- $[8] = onPress;
181
- $[9] = open;
182
- $[10] = setOpen;
183
- $[11] = setTrigger;
184
- $[12] = t2;
229
+ $[11] = onPress;
230
+ $[12] = open;
231
+ $[13] = setOpen;
232
+ $[14] = setTrigger;
233
+ $[15] = t3;
185
234
  } else {
186
- t2 = $[12];
235
+ t3 = $[15];
187
236
  }
188
- let t3;
189
- if ($[13] !== Component || $[14] !== props || $[15] !== t1 || $[16] !== t2) {
190
- t3 = <Component ref={ref} accessibilityRole="button" {...props} accessibilityState={t1} onPress={t2} />;
191
- $[13] = Component;
192
- $[14] = props;
193
- $[15] = t1;
194
- $[16] = t2;
195
- $[17] = t3;
237
+ let t4;
238
+ if ($[16] !== Component || $[17] !== props || $[18] !== t1 || $[19] !== t2 || $[20] !== t3) {
239
+ t4 = <Component ref={t1} accessibilityRole="button" {...props} accessibilityState={t2} onPress={t3} />;
240
+ $[16] = Component;
241
+ $[17] = props;
242
+ $[18] = t1;
243
+ $[19] = t2;
244
+ $[20] = t3;
245
+ $[21] = t4;
196
246
  } else {
197
- t3 = $[17];
247
+ t4 = $[21];
198
248
  }
199
- return t3;
249
+ return t4;
200
250
  }
201
251
  /**
202
252
  * Where the menu goes: under the trigger, `sideOffset` away, its start edge on
@@ -1,4 +1,6 @@
1
1
  import { c as _c } from "react/compiler-runtime";
2
+ import { forwardRef } from "react";
3
+ import { View } from "react-native";
2
4
  import { touchSlop } from "./controlStyles";
3
5
  import { AnimatedPressable, usePressScale } from "./pressScale";
4
6
  import { withAlpha } from "./palette";
@@ -40,8 +42,8 @@ export function iconButtonColors(variant, scheme) {
40
42
  * 32, `md` 40) and 48, each reaching 44 with its hit slop. Not the AI chat
41
43
  * `ChatIconButton`.
42
44
  */
43
- export function IconButton(t0) {
44
- const $ = _c(35);
45
+ export const IconButton = forwardRef(function IconButton(t0, ref) {
46
+ const $ = _c(41);
45
47
  const {
46
48
  icon: Icon,
47
49
  label,
@@ -96,76 +98,97 @@ export function IconButton(t0) {
96
98
  }
97
99
  const press = usePressScale(t6);
98
100
  let t7;
99
- if ($[9] !== disabled) {
101
+ if ($[9] !== diameter) {
100
102
  t7 = {
101
- disabled
103
+ width: diameter,
104
+ height: diameter
102
105
  };
103
- $[9] = disabled;
106
+ $[9] = diameter;
104
107
  $[10] = t7;
105
108
  } else {
106
109
  t7 = $[10];
107
110
  }
108
111
  let t8;
109
- if ($[11] !== diameter) {
110
- t8 = touchSlop(diameter);
111
- $[11] = diameter;
112
+ if ($[11] !== disabled) {
113
+ t8 = {
114
+ disabled
115
+ };
116
+ $[11] = disabled;
112
117
  $[12] = t8;
113
118
  } else {
114
119
  t8 = $[12];
115
120
  }
116
- const t9 = diameter / 2;
117
- let t10;
118
- if ($[13] !== diameter || $[14] !== frame || $[15] !== t9) {
119
- t10 = {
121
+ let t9;
122
+ if ($[13] !== diameter) {
123
+ t9 = touchSlop(diameter);
124
+ $[13] = diameter;
125
+ $[14] = t9;
126
+ } else {
127
+ t9 = $[14];
128
+ }
129
+ const t10 = diameter / 2;
130
+ let t11;
131
+ if ($[15] !== diameter || $[16] !== frame || $[17] !== t10) {
132
+ t11 = {
120
133
  width: diameter,
121
134
  height: diameter,
122
- borderRadius: t9,
135
+ borderRadius: t10,
123
136
  borderWidth: 1,
124
137
  ...frame
125
138
  };
126
- $[13] = diameter;
127
- $[14] = frame;
128
- $[15] = t9;
129
- $[16] = t10;
139
+ $[15] = diameter;
140
+ $[16] = frame;
141
+ $[17] = t10;
142
+ $[18] = t11;
130
143
  } else {
131
- t10 = $[16];
144
+ t11 = $[18];
132
145
  }
133
- let t11;
134
- if ($[17] !== press.style || $[18] !== t10) {
135
- t11 = [t10, press.style];
136
- $[17] = press.style;
137
- $[18] = t10;
138
- $[19] = t11;
146
+ let t12;
147
+ if ($[19] !== press.style || $[20] !== t11) {
148
+ t12 = [t11, press.style];
149
+ $[19] = press.style;
150
+ $[20] = t11;
151
+ $[21] = t12;
139
152
  } else {
140
- t11 = $[19];
153
+ t12 = $[21];
141
154
  }
142
- const t12 = iconColor ?? color;
143
- let t13;
144
- if ($[20] !== Icon || $[21] !== iconSize || $[22] !== t12) {
145
- t13 = <Icon size={iconSize} color={t12} />;
146
- $[20] = Icon;
147
- $[21] = iconSize;
148
- $[22] = t12;
149
- $[23] = t13;
155
+ const t13 = iconColor ?? color;
156
+ let t14;
157
+ if ($[22] !== Icon || $[23] !== iconSize || $[24] !== t13) {
158
+ t14 = <Icon size={iconSize} color={t13} />;
159
+ $[22] = Icon;
160
+ $[23] = iconSize;
161
+ $[24] = t13;
162
+ $[25] = t14;
150
163
  } else {
151
- t13 = $[23];
164
+ t14 = $[25];
152
165
  }
153
- let t14;
154
- if ($[24] !== disabled || $[25] !== label || $[26] !== onPress || $[27] !== press.onPressIn || $[28] !== press.onPressOut || $[29] !== t11 || $[30] !== t13 || $[31] !== t7 || $[32] !== t8 || $[33] !== testID) {
155
- t14 = <AnimatedPressable testID={testID} accessibilityRole="button" accessibilityLabel={label} accessibilityState={t7} hitSlop={t8} disabled={disabled} onPress={onPress} onPressIn={press.onPressIn} onPressOut={press.onPressOut} className="items-center justify-center" style={t11}>{t13}</AnimatedPressable>;
156
- $[24] = disabled;
157
- $[25] = label;
158
- $[26] = onPress;
159
- $[27] = press.onPressIn;
160
- $[28] = press.onPressOut;
161
- $[29] = t11;
162
- $[30] = t13;
163
- $[31] = t7;
164
- $[32] = t8;
165
- $[33] = testID;
166
- $[34] = t14;
166
+ let t15;
167
+ if ($[26] !== disabled || $[27] !== label || $[28] !== onPress || $[29] !== press.onPressIn || $[30] !== press.onPressOut || $[31] !== t12 || $[32] !== t14 || $[33] !== t8 || $[34] !== t9 || $[35] !== testID) {
168
+ t15 = <AnimatedPressable testID={testID} accessibilityRole="button" accessibilityLabel={label} accessibilityState={t8} hitSlop={t9} disabled={disabled} onPress={onPress} onPressIn={press.onPressIn} onPressOut={press.onPressOut} className="items-center justify-center" style={t12}>{t14}</AnimatedPressable>;
169
+ $[26] = disabled;
170
+ $[27] = label;
171
+ $[28] = onPress;
172
+ $[29] = press.onPressIn;
173
+ $[30] = press.onPressOut;
174
+ $[31] = t12;
175
+ $[32] = t14;
176
+ $[33] = t8;
177
+ $[34] = t9;
178
+ $[35] = testID;
179
+ $[36] = t15;
167
180
  } else {
168
- t14 = $[34];
181
+ t15 = $[36];
169
182
  }
170
- return t14;
171
- }
183
+ let t16;
184
+ if ($[37] !== ref || $[38] !== t15 || $[39] !== t7) {
185
+ t16 = <View ref={ref} collapsable={false} style={t7}>{t15}</View>;
186
+ $[37] = ref;
187
+ $[38] = t15;
188
+ $[39] = t7;
189
+ $[40] = t16;
190
+ } else {
191
+ t16 = $[40];
192
+ }
193
+ return t16;
194
+ });
@@ -1,4 +1,5 @@
1
1
  import { c as _c } from "react/compiler-runtime";
2
+ import { forwardRef } from "react";
2
3
  import { Button } from "../Button";
3
4
  import { cn } from "../cn";
4
5
  import { MIN_TOUCH_TARGET, buttonColors, touchSlop } from "../controlStyles";
@@ -45,8 +46,8 @@ const CHAT_ICON_BUTTON = {
45
46
  * actions, the composer tools and its send button, and the code copy button.
46
47
  * Round from the `Button` pill default; `shape="rounded"` gives radius 16.
47
48
  */
48
- export function ChatIconButton(t0) {
49
- const $ = _c(42);
49
+ export const ChatIconButton = forwardRef(function ChatIconButton(t0, ref) {
50
+ const $ = _c(45);
50
51
  let Icon;
51
52
  let className;
52
53
  let iconColor;
@@ -98,82 +99,88 @@ export function ChatIconButton(t0) {
98
99
  let t6;
99
100
  let t7;
100
101
  let t8;
101
- if ($[9] !== className || $[10] !== iconColor || $[11] !== label || $[12] !== largerText || $[13] !== scheme || $[14] !== size || $[15] !== slop || $[16] !== variant) {
102
+ let t9;
103
+ if ($[9] !== className || $[10] !== iconColor || $[11] !== label || $[12] !== largerText || $[13] !== ref || $[14] !== scheme || $[15] !== size || $[16] !== slop || $[17] !== variant) {
102
104
  metrics = largerText ? {
103
105
  side: MIN_TOUCH_TARGET,
104
106
  icon: 20,
105
107
  className: "h-11 w-11"
106
108
  } : CHAT_ICON_BUTTON[size];
107
- let t9;
108
- if ($[25] !== iconColor || $[26] !== scheme || $[27] !== variant) {
109
- t9 = iconColor ?? buttonColors(variant, scheme)?.color ?? tokens.color.foreground[scheme];
110
- $[25] = iconColor;
111
- $[26] = scheme;
112
- $[27] = variant;
113
- $[28] = t9;
109
+ let t10;
110
+ if ($[27] !== iconColor || $[28] !== scheme || $[29] !== variant) {
111
+ t10 = iconColor ?? buttonColors(variant, scheme)?.color ?? tokens.color.foreground[scheme];
112
+ $[27] = iconColor;
113
+ $[28] = scheme;
114
+ $[29] = variant;
115
+ $[30] = t10;
114
116
  } else {
115
- t9 = $[28];
117
+ t10 = $[30];
116
118
  }
117
- color = t9;
119
+ color = t10;
118
120
  T0 = Button;
119
- t4 = variant;
120
- t5 = "icon";
121
- t6 = label;
122
- t7 = slop === "square" ? touchSlop(metrics.side) : {
121
+ t4 = ref;
122
+ t5 = variant;
123
+ t6 = "icon";
124
+ t7 = label;
125
+ t8 = slop === "square" ? touchSlop(metrics.side) : {
123
126
  ...touchSlop(MIN_TOUCH_TARGET, metrics.side),
124
127
  ...(slop === "vertical" ? null : slop)
125
128
  };
126
- t8 = cn(metrics.className, className);
129
+ t9 = cn(metrics.className, className);
127
130
  $[9] = className;
128
131
  $[10] = iconColor;
129
132
  $[11] = label;
130
133
  $[12] = largerText;
131
- $[13] = scheme;
132
- $[14] = size;
133
- $[15] = slop;
134
- $[16] = variant;
135
- $[17] = T0;
136
- $[18] = color;
137
- $[19] = metrics;
138
- $[20] = t4;
139
- $[21] = t5;
140
- $[22] = t6;
141
- $[23] = t7;
142
- $[24] = t8;
134
+ $[13] = ref;
135
+ $[14] = scheme;
136
+ $[15] = size;
137
+ $[16] = slop;
138
+ $[17] = variant;
139
+ $[18] = T0;
140
+ $[19] = color;
141
+ $[20] = metrics;
142
+ $[21] = t4;
143
+ $[22] = t5;
144
+ $[23] = t6;
145
+ $[24] = t7;
146
+ $[25] = t8;
147
+ $[26] = t9;
143
148
  } else {
144
- T0 = $[17];
145
- color = $[18];
146
- metrics = $[19];
147
- t4 = $[20];
148
- t5 = $[21];
149
- t6 = $[22];
150
- t7 = $[23];
151
- t8 = $[24];
149
+ T0 = $[18];
150
+ color = $[19];
151
+ metrics = $[20];
152
+ t4 = $[21];
153
+ t5 = $[22];
154
+ t6 = $[23];
155
+ t7 = $[24];
156
+ t8 = $[25];
157
+ t9 = $[26];
152
158
  }
153
- let t9;
154
- if ($[29] !== Icon || $[30] !== color || $[31] !== metrics.icon) {
155
- t9 = <Icon size={metrics.icon} color={color} />;
156
- $[29] = Icon;
157
- $[30] = color;
158
- $[31] = metrics.icon;
159
- $[32] = t9;
159
+ let t10;
160
+ if ($[31] !== Icon || $[32] !== color || $[33] !== metrics.icon) {
161
+ t10 = <Icon size={metrics.icon} color={color} />;
162
+ $[31] = Icon;
163
+ $[32] = color;
164
+ $[33] = metrics.icon;
165
+ $[34] = t10;
160
166
  } else {
161
- t9 = $[32];
167
+ t10 = $[34];
162
168
  }
163
- let t10;
164
- if ($[33] !== T0 || $[34] !== props || $[35] !== t4 || $[36] !== t5 || $[37] !== t6 || $[38] !== t7 || $[39] !== t8 || $[40] !== t9) {
165
- t10 = <T0 variant={t4} size={t5} accessibilityLabel={t6} hitSlop={t7} className={t8} {...props}>{t9}</T0>;
166
- $[33] = T0;
167
- $[34] = props;
168
- $[35] = t4;
169
- $[36] = t5;
170
- $[37] = t6;
171
- $[38] = t7;
172
- $[39] = t8;
173
- $[40] = t9;
174
- $[41] = t10;
169
+ let t11;
170
+ if ($[35] !== T0 || $[36] !== props || $[37] !== t10 || $[38] !== t4 || $[39] !== t5 || $[40] !== t6 || $[41] !== t7 || $[42] !== t8 || $[43] !== t9) {
171
+ t11 = <T0 ref={t4} variant={t5} size={t6} accessibilityLabel={t7} hitSlop={t8} className={t9} {...props}>{t10}</T0>;
172
+ $[35] = T0;
173
+ $[36] = props;
174
+ $[37] = t10;
175
+ $[38] = t4;
176
+ $[39] = t5;
177
+ $[40] = t6;
178
+ $[41] = t7;
179
+ $[42] = t8;
180
+ $[43] = t9;
181
+ $[44] = t11;
175
182
  } else {
176
- t10 = $[41];
183
+ t11 = $[44];
177
184
  }
178
- return t10;
179
- }
185
+ return t11;
186
+ });
@@ -1,5 +1,5 @@
1
1
  import { c as _c } from "react/compiler-runtime";
2
- import { useContext, useState } from "react";
2
+ import { forwardRef, useContext, useState } from "react";
3
3
  import { Platform, Pressable, Text, View, useWindowDimensions } from "react-native";
4
4
  import { useSafeAreaInsets } from "react-native-safe-area-context";
5
5
  import { IconArrowUp, IconChevronDown, IconPlayerStopFilled } from "@tabler/icons-react-native";
@@ -75,18 +75,19 @@ export function PromptInputSubmit(t0) {
75
75
  return t3;
76
76
  }
77
77
  /** A ghost tool button for the composer `toolbar`, such as attach (web `PromptInputButton`). Give it `icon` and `label`. */
78
- export function PromptInputButton(props) {
79
- const $ = _c(2);
78
+ export const PromptInputButton = forwardRef(function PromptInputButton(props, ref) {
79
+ const $ = _c(3);
80
80
  let t0;
81
- if ($[0] !== props) {
82
- t0 = <ChatIconButton variant="ghost" {...props} />;
81
+ if ($[0] !== props || $[1] !== ref) {
82
+ t0 = <ChatIconButton ref={ref} variant="ghost" {...props} />;
83
83
  $[0] = props;
84
- $[1] = t0;
84
+ $[1] = ref;
85
+ $[2] = t0;
85
86
  } else {
86
- t0 = $[1];
87
+ t0 = $[2];
87
88
  }
88
89
  return t0;
89
- }
90
+ });
90
91
 
91
92
  /**
92
93
  * The web `ModelPicker` trigger (`model-picker.tsx` `TRIGGER_CLASS`), the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vvedantb/native-ui",
3
- "version": "0.36.0",
3
+ "version": "0.36.1",
4
4
  "license": "MIT",
5
5
  "description": "Shared React Native / Expo UI primitives. Floating surfaces, forms, overlays, toasts, settings chrome, tab bar, AI chat parts, the family app marks, a NativeWind preset, the Expo web root and Clerk + Convex auth screens.",
6
6
  "type": "module",
package/src/Button.tsx CHANGED
@@ -140,7 +140,11 @@ const PRIMITIVE_VARIANT = {
140
140
 
141
141
  export type { ButtonProps, ButtonShape, ButtonSize, ButtonVariant };
142
142
 
143
- export function Button({
143
+ /**
144
+ * Forwards `ref` to the native view, so a parent (such as `DropdownMenuTrigger
145
+ * asChild`) can measure it.
146
+ */
147
+ export const Button = React.forwardRef<React.ElementRef<typeof PrimitiveButton>, ButtonProps>(function Button({
144
148
  onPress,
145
149
  variant = "primary",
146
150
  icon,
@@ -155,7 +159,7 @@ export function Button({
155
159
  shadowType = "flat",
156
160
  className,
157
161
  ...props
158
- }: ButtonProps) {
162
+ }, ref) {
159
163
  const scale = useLargerText() ? "larger" : "regular";
160
164
  const scheme = useScheme();
161
165
  const dialog = useDialogLayout();
@@ -186,6 +190,7 @@ export function Button({
186
190
 
187
191
  return (
188
192
  <PrimitiveButton
193
+ ref={ref}
189
194
  onPress={onPress}
190
195
  variant={PRIMITIVE_VARIANT[variant]}
191
196
  shape={shape}
@@ -239,4 +244,4 @@ export function Button({
239
244
  </View>
240
245
  </PrimitiveButton>
241
246
  );
242
- }
247
+ });
@@ -8,6 +8,7 @@ import {
8
8
  type ComponentRef,
9
9
  type ComponentType,
10
10
  type ReactNode,
11
+ type Ref,
11
12
  } from "react";
12
13
  import {
13
14
  Pressable,
@@ -111,19 +112,55 @@ export type DropdownMenuTriggerProps = PressableProps & {
111
112
  * native view, so the menu can measure it.
112
113
  */
113
114
  asChild?: boolean;
115
+ /** Also receives the native view; the menu keeps its own handle. */
116
+ ref?: Ref<ComponentRef<typeof View>>;
114
117
  };
115
118
 
119
+ /** A measured box is usable when it has a size: Android reports 0, 0, 0, 0 for a view it has not laid out. */
120
+ export function isMeasuredRect(rect: DropdownMenuRect): boolean {
121
+ return rect.width > 0 && rect.height > 0;
122
+ }
123
+
124
+ type Measurable = Pick<ComponentRef<typeof View>, "measureInWindow" | "measure">;
125
+
126
+ /**
127
+ * The view's box in window coordinates, or `null` when it cannot be measured.
128
+ * `measureInWindow` first; when it returns an empty box, `measure` (its
129
+ * `pageX` and `pageY` are window coordinates too) as a second reading.
130
+ */
131
+ export function measureAnchor(view: Measurable, done: (rect: DropdownMenuRect | null) => void) {
132
+ view.measureInWindow((x, y, width, height) => {
133
+ const rect = { x, y, width, height };
134
+ if (isMeasuredRect(rect)) return done(rect);
135
+ view.measure((_x, _y, w, h, pageX, pageY) => {
136
+ const second = { x: pageX, y: pageY, width: w, height: h };
137
+ done(isMeasuredRect(second) ? second : null);
138
+ });
139
+ });
140
+ }
141
+
116
142
  /**
117
143
  * Opens the menu, or closes it when open. On press it measures itself
118
- * (`measureInWindow`) and the menu opens under it. Reports `expanded`.
144
+ * (`measureInWindow`) and the menu opens under it. Reports `expanded`. A
145
+ * caller `ref` is kept: the menu's own handle never replaces it.
119
146
  */
120
- export function DropdownMenuTrigger({ asChild, onPress, accessibilityState, ...props }: DropdownMenuTriggerProps) {
147
+ export function DropdownMenuTrigger({
148
+ asChild,
149
+ onPress,
150
+ accessibilityState,
151
+ ref: callerRef,
152
+ ...props
153
+ }: DropdownMenuTriggerProps) {
121
154
  const { open, setOpen, setTrigger } = useMenu("DropdownMenuTrigger");
122
- const ref = useRef<ComponentRef<typeof View>>(null);
155
+ const ref = useRef<ComponentRef<typeof View> | null>(null);
123
156
  const Component = asChild ? Slot.Pressable : Pressable;
124
157
  return (
125
158
  <Component
126
- ref={ref}
159
+ ref={(view: ComponentRef<typeof View> | null) => {
160
+ ref.current = view;
161
+ if (typeof callerRef === "function") callerRef(view);
162
+ else if (callerRef) callerRef.current = view;
163
+ }}
127
164
  accessibilityRole="button"
128
165
  {...props}
129
166
  accessibilityState={{ ...accessibilityState, expanded: open }}
@@ -132,8 +169,8 @@ export function DropdownMenuTrigger({ asChild, onPress, accessibilityState, ...p
132
169
  if (open) return setOpen(false);
133
170
  const view = ref.current;
134
171
  if (!view) return setOpen(true);
135
- view.measureInWindow((x, y, width, height) => {
136
- setTrigger({ x, y, width, height });
172
+ measureAnchor(view, (rect) => {
173
+ if (rect) setTrigger(rect);
137
174
  setOpen(true);
138
175
  });
139
176
  }}
@@ -1,4 +1,5 @@
1
- import type { ComponentType } from "react";
1
+ import { forwardRef, type ComponentRef, type ComponentType } from "react";
2
+ import { View } from "react-native";
2
3
  import type { IconProps } from "@tabler/icons-react-native";
3
4
  import { touchSlop } from "./controlStyles";
4
5
  import { AnimatedPressable, usePressScale } from "./pressScale";
@@ -54,7 +55,7 @@ export function iconButtonColors(variant: IconButtonVariant, scheme: "light" | "
54
55
  * 32, `md` 40) and 48, each reaching 44 with its hit slop. Not the AI chat
55
56
  * `ChatIconButton`.
56
57
  */
57
- export function IconButton({
58
+ export const IconButton = forwardRef<ComponentRef<typeof View>, IconButtonProps>(function IconButton({
58
59
  icon: Icon,
59
60
  label,
60
61
  onPress,
@@ -63,13 +64,14 @@ export function IconButton({
63
64
  size = "md",
64
65
  testID,
65
66
  iconColor,
66
- }: IconButtonProps) {
67
+ }, ref) {
67
68
  const scheme = useScheme();
68
69
  const largerText = useLargerText();
69
70
  const [diameter, iconSize] = METRICS[largerText ? "larger" : "regular"][size];
70
71
  const { color, ...frame } = iconButtonColors(variant, scheme);
71
72
  const press = usePressScale({ restOpacity: disabled ? 0.5 : 1, disabled });
72
73
  return (
74
+ <View ref={ref} collapsable={false} style={{ width: diameter, height: diameter }}>
73
75
  <AnimatedPressable
74
76
  testID={testID}
75
77
  accessibilityRole="button"
@@ -85,5 +87,6 @@ export function IconButton({
85
87
  >
86
88
  <Icon size={iconSize} color={iconColor ?? color} />
87
89
  </AnimatedPressable>
90
+ </View>
88
91
  );
89
- }
92
+ });
@@ -1,4 +1,4 @@
1
- import type { ComponentType } from "react";
1
+ import { forwardRef, type ComponentType, type ElementRef } from "react";
2
2
  import type { IconProps } from "@tabler/icons-react-native";
3
3
  import { Button, type ButtonProps } from "../Button";
4
4
  import { cn } from "../cn";
@@ -51,7 +51,7 @@ export type ChatIconButtonProps = Omit<ButtonProps, "children" | "size" | "icon"
51
51
  * actions, the composer tools and its send button, and the code copy button.
52
52
  * Round from the `Button` pill default; `shape="rounded"` gives radius 16.
53
53
  */
54
- export function ChatIconButton({
54
+ export const ChatIconButton = forwardRef<ElementRef<typeof Button>, ChatIconButtonProps>(function ChatIconButton({
55
55
  icon: Icon,
56
56
  label,
57
57
  iconColor,
@@ -60,7 +60,7 @@ export function ChatIconButton({
60
60
  slop = "square",
61
61
  className,
62
62
  ...props
63
- }: ChatIconButtonProps) {
63
+ }, ref) {
64
64
  const scheme = useScheme();
65
65
  const largerText = useLargerText();
66
66
  const metrics = largerText
@@ -69,6 +69,7 @@ export function ChatIconButton({
69
69
  const color = iconColor ?? buttonColors(variant, scheme)?.color ?? tokens.color.foreground[scheme];
70
70
  return (
71
71
  <Button
72
+ ref={ref}
72
73
  variant={variant}
73
74
  size="icon"
74
75
  accessibilityLabel={label}
@@ -83,4 +84,4 @@ export function ChatIconButton({
83
84
  <Icon size={metrics.icon} color={color} />
84
85
  </Button>
85
86
  );
86
- }
87
+ });
@@ -1,4 +1,4 @@
1
- import { useContext, useState, type ReactNode } from "react";
1
+ import { forwardRef, useContext, useState, type ElementRef, type ReactNode } from "react";
2
2
  import { Platform, Pressable, Text, View, useWindowDimensions } from "react-native";
3
3
  import { useSafeAreaInsets } from "react-native-safe-area-context";
4
4
  import { IconArrowUp, IconChevronDown, IconPlayerStopFilled } from "@tabler/icons-react-native";
@@ -83,9 +83,11 @@ export function PromptInputSubmit({
83
83
  export type PromptInputButtonProps = ChatIconButtonProps;
84
84
 
85
85
  /** A ghost tool button for the composer `toolbar`, such as attach (web `PromptInputButton`). Give it `icon` and `label`. */
86
- export function PromptInputButton(props: PromptInputButtonProps) {
87
- return <ChatIconButton variant="ghost" {...props} />;
88
- }
86
+ export const PromptInputButton = forwardRef<ElementRef<typeof ChatIconButton>, PromptInputButtonProps>(
87
+ function PromptInputButton(props, ref) {
88
+ return <ChatIconButton ref={ref} variant="ghost" {...props} />;
89
+ },
90
+ );
89
91
 
90
92
  /**
91
93
  * The web `ModelPicker` trigger (`model-picker.tsx` `TRIGGER_CLASS`), the