@vvedantb/native-ui 0.24.1 → 0.24.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.
@@ -1,11 +1,12 @@
1
1
  import { c as _c } from "react/compiler-runtime";
2
2
  import * as Slot from "@rn-primitives/slot";
3
3
  import { createContext, Fragment, useContext, useEffect, useState } from "react";
4
- import { Modal, Pressable, StyleSheet, View } from "react-native";
5
- import Animated from "react-native-reanimated";
4
+ import { Modal, Pressable, StyleSheet } from "react-native";
5
+ import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
6
6
  import { useSafeAreaInsets } from "react-native-safe-area-context";
7
7
  import { palette } from "../palette";
8
8
  import { KeyboardAvoidingView, KeyboardLiftContext } from "./keyboard-parts";
9
+ import { DIALOG_ENTER, DIALOG_EXIT, PANEL_SCALE_FROM } from "../motion";
9
10
  import { useReduceMotion } from "../useReduceMotion";
10
11
  import { useScheme } from "../useScheme";
11
12
  import { SheetDragProvider, SheetGestureContext, slideSheetIn, slideSheetOut, useSheetBackdropStyle, useSheetDragState } from "./sheet-drag";
@@ -152,7 +153,9 @@ export function OverlayClose(props) {
152
153
  * RN `Modal` with a tinted backdrop, safe-area padding and keyboard avoidance
153
154
  * (`KeyboardAvoidingView`: frame by frame with `KeyboardControllerProvider`).
154
155
  * `placement="center"` centres the child (dialogs) inside the insets on every
155
- * side, and the `Modal` fades in and out. `"bottom"` pins it to the bottom
156
+ * side: the backdrop fades while the panel scales from 0.96 and fades in (200
157
+ * ms on open, 150 ms on close), and the `Modal` stays up until it is out of
158
+ * sight. `"bottom"` pins it to the bottom
156
159
  * edge (sheets), which pad their own bottom inset: the sheet slides up on
157
160
  * open and back down on close, however it closes, and may be dragged down to
158
161
  * close (`SheetDragView`); the backdrop fades with the sheet's position. The
@@ -179,11 +182,12 @@ export function OverlayModal(t0) {
179
182
  } = useOverlay(part);
180
183
  const reduceMotion = useReduceMotion();
181
184
  const slides = placement === "bottom" && !reduceMotion;
185
+ const scales = placement === "center" && !reduceMotion;
182
186
  const [shown, setShown] = useState(open);
183
187
  if (open && !shown) {
184
188
  setShown(true);
185
189
  }
186
- if (!open && shown && !slides) {
190
+ if (!open && shown && !slides && !scales) {
187
191
  setShown(false);
188
192
  }
189
193
  let t1;
@@ -196,61 +200,61 @@ export function OverlayModal(t0) {
196
200
  }
197
201
  const close = t1;
198
202
  const ModalRoot = useContext(SheetGestureContext)?.ModalRoot ?? Fragment;
199
- const t2 = slides || reduceMotion ? "none" : "fade";
200
- let t3;
203
+ let t2;
201
204
  if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
202
- t3 = () => setShown(false);
203
- $[2] = t3;
205
+ t2 = () => setShown(false);
206
+ $[2] = t2;
204
207
  } else {
205
- t3 = $[2];
208
+ t2 = $[2];
206
209
  }
207
- let t4;
208
- if ($[3] !== children || $[4] !== close || $[5] !== dismissible || $[6] !== open || $[7] !== part || $[8] !== placement || $[9] !== slides) {
209
- t4 = <OverlayModalBody placement={placement} dismissible={dismissible} open={open} slides={slides} close={close} onHidden={t3} part={part}>{children}</OverlayModalBody>;
210
+ let t3;
211
+ if ($[3] !== children || $[4] !== close || $[5] !== dismissible || $[6] !== open || $[7] !== part || $[8] !== placement || $[9] !== scales || $[10] !== slides) {
212
+ t3 = <OverlayModalBody placement={placement} dismissible={dismissible} open={open} slides={slides} scales={scales} close={close} onHidden={t2} part={part}>{children}</OverlayModalBody>;
210
213
  $[3] = children;
211
214
  $[4] = close;
212
215
  $[5] = dismissible;
213
216
  $[6] = open;
214
217
  $[7] = part;
215
218
  $[8] = placement;
216
- $[9] = slides;
217
- $[10] = t4;
219
+ $[9] = scales;
220
+ $[10] = slides;
221
+ $[11] = t3;
218
222
  } else {
219
- t4 = $[10];
223
+ t3 = $[11];
220
224
  }
221
- let t5;
222
- if ($[11] !== ModalRoot || $[12] !== t4) {
223
- t5 = <ModalRoot>{t4}</ModalRoot>;
224
- $[11] = ModalRoot;
225
- $[12] = t4;
226
- $[13] = t5;
225
+ let t4;
226
+ if ($[12] !== ModalRoot || $[13] !== t3) {
227
+ t4 = <ModalRoot>{t3}</ModalRoot>;
228
+ $[12] = ModalRoot;
229
+ $[13] = t3;
230
+ $[14] = t4;
227
231
  } else {
228
- t5 = $[13];
232
+ t4 = $[14];
229
233
  }
230
- let t6;
231
- if ($[14] !== close || $[15] !== onShow || $[16] !== shown || $[17] !== t2 || $[18] !== t5) {
232
- t6 = <Modal visible={shown} transparent={true} animationType={t2} statusBarTranslucent={true} onRequestClose={close} onShow={onShow}>{t5}</Modal>;
233
- $[14] = close;
234
- $[15] = onShow;
235
- $[16] = shown;
236
- $[17] = t2;
237
- $[18] = t5;
238
- $[19] = t6;
234
+ let t5;
235
+ if ($[15] !== close || $[16] !== onShow || $[17] !== shown || $[18] !== t4) {
236
+ t5 = <Modal visible={shown} transparent={true} animationType="none" statusBarTranslucent={true} onRequestClose={close} onShow={onShow}>{t4}</Modal>;
237
+ $[15] = close;
238
+ $[16] = onShow;
239
+ $[17] = shown;
240
+ $[18] = t4;
241
+ $[19] = t5;
239
242
  } else {
240
- t6 = $[19];
243
+ t5 = $[19];
241
244
  }
242
- return t6;
245
+ return t5;
243
246
  }
244
247
 
245
248
  /** The `Modal`'s content: mounted with each opening, so a sheet starts below the screen (or at rest). */
246
249
  function OverlayModalBody(t0) {
247
- const $ = _c(37);
250
+ const $ = _c(48);
248
251
  const {
249
252
  part,
250
253
  placement,
251
254
  dismissible,
252
255
  open,
253
256
  slides,
257
+ scales,
254
258
  close,
255
259
  onHidden,
256
260
  children
@@ -258,7 +262,18 @@ function OverlayModalBody(t0) {
258
262
  const scheme = useScheme();
259
263
  const insets = useSafeAreaInsets();
260
264
  const drag = useSheetDragState(close, slides);
261
- const backdropStyle = useSheetBackdropStyle(drag);
265
+ const sheetBackdropStyle = useSheetBackdropStyle(drag);
266
+ const progress = useSharedValue(scales ? 0 : 1);
267
+ const centreBackdropStyle = useAnimatedStyle(() => ({
268
+ opacity: progress.get()
269
+ }));
270
+ const centrePanelStyle = useAnimatedStyle(() => ({
271
+ opacity: progress.get(),
272
+ transform: [{
273
+ scale: PANEL_SCALE_FROM + (1 - PANEL_SCALE_FROM) * progress.get()
274
+ }]
275
+ }));
276
+ const backdropStyle = placement === "center" ? centreBackdropStyle : sheetBackdropStyle;
262
277
  let t1;
263
278
  if ($[0] !== drag || $[1] !== onHidden || $[2] !== open || $[3] !== slides) {
264
279
  t1 = () => {
@@ -289,51 +304,87 @@ function OverlayModalBody(t0) {
289
304
  t2 = $[7];
290
305
  }
291
306
  useEffect(t1, t2);
292
- const t3 = palette.backdrop[scheme];
293
- let t4;
294
- if ($[8] !== t3) {
295
- t4 = {
296
- backgroundColor: t3
307
+ let t3;
308
+ if ($[8] !== onHidden || $[9] !== open || $[10] !== progress || $[11] !== scales) {
309
+ t3 = () => {
310
+ if (!scales) {
311
+ return;
312
+ }
313
+ if (open) {
314
+ progress.set(withTiming(1, DIALOG_ENTER));
315
+ } else {
316
+ progress.set(withTiming(0, DIALOG_EXIT, finished => {
317
+ "worklet";
318
+
319
+ if (finished) {
320
+ runOnJS(onHidden)();
321
+ }
322
+ }));
323
+ }
297
324
  };
298
- $[8] = t3;
299
- $[9] = t4;
325
+ $[8] = onHidden;
326
+ $[9] = open;
327
+ $[10] = progress;
328
+ $[11] = scales;
329
+ $[12] = t3;
300
330
  } else {
301
- t4 = $[9];
331
+ t3 = $[12];
302
332
  }
303
- let t5;
304
- if ($[10] !== backdropStyle || $[11] !== t4) {
305
- t5 = [StyleSheet.absoluteFill, t4, backdropStyle];
306
- $[10] = backdropStyle;
307
- $[11] = t4;
308
- $[12] = t5;
333
+ let t4;
334
+ if ($[13] !== open || $[14] !== scales) {
335
+ t4 = [open, scales];
336
+ $[13] = open;
337
+ $[14] = scales;
338
+ $[15] = t4;
309
339
  } else {
310
- t5 = $[12];
340
+ t4 = $[15];
311
341
  }
312
- const t6 = `${part}-backdrop`;
313
- const t7 = !dismissible;
314
- let t8;
315
- if ($[13] !== close || $[14] !== dismissible || $[15] !== t6 || $[16] !== t7) {
316
- t8 = <Pressable testID={t6} accessible={dismissible} accessibilityRole="button" accessibilityLabel="Close" disabled={t7} onPress={close} style={StyleSheet.absoluteFill} />;
317
- $[13] = close;
318
- $[14] = dismissible;
319
- $[15] = t6;
320
- $[16] = t7;
321
- $[17] = t8;
342
+ useEffect(t3, t4);
343
+ const t5 = palette.backdrop[scheme];
344
+ let t6;
345
+ if ($[16] !== t5) {
346
+ t6 = {
347
+ backgroundColor: t5
348
+ };
349
+ $[16] = t5;
350
+ $[17] = t6;
322
351
  } else {
323
- t8 = $[17];
352
+ t6 = $[17];
324
353
  }
325
- let t9;
326
- if ($[18] !== t5 || $[19] !== t8) {
327
- t9 = <Animated.View pointerEvents="box-none" style={t5}>{t8}</Animated.View>;
328
- $[18] = t5;
329
- $[19] = t8;
330
- $[20] = t9;
354
+ let t7;
355
+ if ($[18] !== backdropStyle || $[19] !== t6) {
356
+ t7 = [StyleSheet.absoluteFill, t6, backdropStyle];
357
+ $[18] = backdropStyle;
358
+ $[19] = t6;
359
+ $[20] = t7;
331
360
  } else {
332
- t9 = $[20];
361
+ t7 = $[20];
333
362
  }
363
+ const t8 = `${part}-backdrop`;
364
+ const t9 = !dismissible;
334
365
  let t10;
335
- if ($[21] !== insets.bottom || $[22] !== insets.left || $[23] !== insets.right || $[24] !== insets.top || $[25] !== placement) {
336
- t10 = [styles.fill, placement === "bottom" ? {
366
+ if ($[21] !== close || $[22] !== dismissible || $[23] !== t8 || $[24] !== t9) {
367
+ t10 = <Pressable testID={t8} accessible={dismissible} accessibilityRole="button" accessibilityLabel="Close" disabled={t9} onPress={close} style={StyleSheet.absoluteFill} />;
368
+ $[21] = close;
369
+ $[22] = dismissible;
370
+ $[23] = t8;
371
+ $[24] = t9;
372
+ $[25] = t10;
373
+ } else {
374
+ t10 = $[25];
375
+ }
376
+ let t11;
377
+ if ($[26] !== t10 || $[27] !== t7) {
378
+ t11 = <Animated.View pointerEvents="box-none" style={t7}>{t10}</Animated.View>;
379
+ $[26] = t10;
380
+ $[27] = t7;
381
+ $[28] = t11;
382
+ } else {
383
+ t11 = $[28];
384
+ }
385
+ let t12;
386
+ if ($[29] !== insets.bottom || $[30] !== insets.left || $[31] !== insets.right || $[32] !== insets.top || $[33] !== placement) {
387
+ t12 = placement === "bottom" ? {
337
388
  justifyContent: "flex-end",
338
389
  paddingTop: insets.top + 16,
339
390
  paddingLeft: insets.left,
@@ -344,45 +395,55 @@ function OverlayModalBody(t0) {
344
395
  paddingBottom: insets.bottom + 16,
345
396
  paddingLeft: insets.left + 16,
346
397
  paddingRight: insets.right + 16
347
- }];
348
- $[21] = insets.bottom;
349
- $[22] = insets.left;
350
- $[23] = insets.right;
351
- $[24] = insets.top;
352
- $[25] = placement;
353
- $[26] = t10;
398
+ };
399
+ $[29] = insets.bottom;
400
+ $[30] = insets.left;
401
+ $[31] = insets.right;
402
+ $[32] = insets.top;
403
+ $[33] = placement;
404
+ $[34] = t12;
354
405
  } else {
355
- t10 = $[26];
406
+ t12 = $[34];
356
407
  }
357
- let t11;
358
- if ($[27] !== children || $[28] !== close || $[29] !== t10) {
359
- t11 = <View pointerEvents="box-none" onAccessibilityEscape={close} style={t10}>{children}</View>;
360
- $[27] = children;
361
- $[28] = close;
362
- $[29] = t10;
363
- $[30] = t11;
408
+ const t13 = placement === "center" ? centrePanelStyle : null;
409
+ let t14;
410
+ if ($[35] !== t12 || $[36] !== t13) {
411
+ t14 = [styles.fill, t12, t13];
412
+ $[35] = t12;
413
+ $[36] = t13;
414
+ $[37] = t14;
364
415
  } else {
365
- t11 = $[30];
416
+ t14 = $[37];
366
417
  }
367
- let t12;
368
- if ($[31] !== t11 || $[32] !== t9) {
369
- t12 = <KeyboardAvoidingView style={styles.fill}><KeyboardLiftContext.Provider value={false}>{t9}{t11}</KeyboardLiftContext.Provider></KeyboardAvoidingView>;
370
- $[31] = t11;
371
- $[32] = t9;
372
- $[33] = t12;
418
+ let t15;
419
+ if ($[38] !== children || $[39] !== close || $[40] !== t14) {
420
+ t15 = <Animated.View pointerEvents="box-none" onAccessibilityEscape={close} style={t14}>{children}</Animated.View>;
421
+ $[38] = children;
422
+ $[39] = close;
423
+ $[40] = t14;
424
+ $[41] = t15;
373
425
  } else {
374
- t12 = $[33];
426
+ t15 = $[41];
375
427
  }
376
- let t13;
377
- if ($[34] !== drag || $[35] !== t12) {
378
- t13 = <SheetDragProvider value={drag}>{t12}</SheetDragProvider>;
379
- $[34] = drag;
380
- $[35] = t12;
381
- $[36] = t13;
428
+ let t16;
429
+ if ($[42] !== t11 || $[43] !== t15) {
430
+ t16 = <KeyboardAvoidingView style={styles.fill}><KeyboardLiftContext.Provider value={false}>{t11}{t15}</KeyboardLiftContext.Provider></KeyboardAvoidingView>;
431
+ $[42] = t11;
432
+ $[43] = t15;
433
+ $[44] = t16;
434
+ } else {
435
+ t16 = $[44];
436
+ }
437
+ let t17;
438
+ if ($[45] !== drag || $[46] !== t16) {
439
+ t17 = <SheetDragProvider value={drag}>{t16}</SheetDragProvider>;
440
+ $[45] = drag;
441
+ $[46] = t16;
442
+ $[47] = t17;
382
443
  } else {
383
- t13 = $[36];
444
+ t17 = $[47];
384
445
  }
385
- return t13;
446
+ return t17;
386
447
  }
387
448
  const styles = StyleSheet.create({
388
449
  fill: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vvedantb/native-ui",
3
- "version": "0.24.1",
3
+ "version": "0.24.2",
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",
@@ -1,5 +1,5 @@
1
1
  import * as Slot from "@rn-primitives/slot";
2
- import { createContext, useContext, useRef, useState, type ComponentType, type ReactNode } from "react";
2
+ import { createContext, useContext, useEffect, useRef, useState, type ComponentType, type ReactNode } from "react";
3
3
  import {
4
4
  Modal,
5
5
  Pressable,
@@ -12,12 +12,14 @@ import {
12
12
  type PressableProps,
13
13
  type ViewProps,
14
14
  } from "react-native";
15
+ import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
15
16
  import { useSafeAreaInsets } from "react-native-safe-area-context";
16
17
  import { IconCheck, type IconProps } from "@tabler/icons-react-native";
17
18
  import { FloatingSurface } from "./FloatingSurface";
18
19
  import { cn } from "./cn";
19
20
  import { sizeStyle, typeStyle } from "./controlStyles";
20
21
  import { selectionHaptic } from "./haptics";
22
+ import { PANEL_SCALE_FROM, POPOVER_ENTER, POPOVER_EXIT } from "./motion";
21
23
  import { palette } from "./palette";
22
24
  import { useLargerText } from "./theme";
23
25
  import { tokens } from "./tokens";
@@ -195,7 +197,9 @@ export type DropdownMenuContentProps = ViewProps & {
195
197
  * `Dialog` and `Sheet` (`FloatingSurface` without blur, with the floating
196
198
  * shadow) at radius 16, at least 192 wide, `p-1.5`, scrolling when taller than
197
199
  * the room. A tap outside, Android back and the VoiceOver escape gesture close
198
- * it. With Reduce Motion on, the fade is off.
200
+ * it. The panel (not the backdrop) fades in and scales from 0.96 over 150 ms
201
+ * once it is measured, from the corner nearest the trigger, and fades out in
202
+ * 100 ms. With Reduce Motion on, it appears and leaves at once.
199
203
  */
200
204
  export function DropdownMenuContent({
201
205
  align = "start",
@@ -212,13 +216,60 @@ export function DropdownMenuContent({
212
216
  // `null` until the content is measured: only then is it known whether the
213
217
  // menu fits below the trigger or flips above, so it stays hidden till then.
214
218
  const [contentHeight, setContentHeight] = useState<number | null>(null);
219
+ // Up while open, and after a close until the panel has faded out.
220
+ const [shown, setShown] = useState(open);
221
+ if (open && !shown) setShown(true);
222
+ if (!open && shown && reduceMotion) setShown(false);
223
+ const openRef = useRef(open);
224
+ useEffect(() => {
225
+ openRef.current = open;
226
+ }, [open]);
227
+ // The panel's motion, on the UI thread. At rest (1, 1) under Reduce Motion.
228
+ const opacity = useSharedValue(reduceMotion ? 1 : 0);
229
+ const scale = useSharedValue(reduceMotion ? 1 : PANEL_SCALE_FROM);
230
+ const measured = contentHeight !== null;
231
+ const hide = () => {
232
+ // Opened again in the moment the fade ended: stay up.
233
+ if (openRef.current) return;
234
+ setShown(false);
235
+ setContentHeight(null);
236
+ scale.set(PANEL_SCALE_FROM);
237
+ };
238
+ useEffect(() => {
239
+ if (reduceMotion) {
240
+ opacity.set(1);
241
+ scale.set(1);
242
+ return;
243
+ }
244
+ if (open) {
245
+ if (!measured) return;
246
+ opacity.set(withTiming(1, POPOVER_ENTER));
247
+ scale.set(withTiming(1, POPOVER_ENTER));
248
+ } else if (shown) {
249
+ // A fade only: the scale stays where it is.
250
+ opacity.set(
251
+ withTiming(0, POPOVER_EXIT, (finished) => {
252
+ "worklet";
253
+ if (finished) runOnJS(hide)();
254
+ }),
255
+ );
256
+ }
257
+ // Only opening, measuring and closing start the motion.
258
+ }, [open, measured, reduceMotion]);
259
+ const panelStyle = useAnimatedStyle(() => ({
260
+ opacity: opacity.get(),
261
+ transform: [{ scale: scale.get() }],
262
+ }));
215
263
  const close = () => setOpen(false);
216
264
  const position = dropdownMenuPosition({ trigger, window, insets, align, sideOffset, contentHeight: contentHeight ?? 0 });
265
+ // The scale grows from the corner nearest the trigger: its edge on the
266
+ // trigger's (`align`), and the top, or the bottom when the menu flipped above.
267
+ const transformOrigin = `${align === "end" ? 100 : 0}% ${position.bottom === undefined ? 0 : 100}%`;
217
268
  return (
218
269
  <Modal
219
- visible={open}
270
+ visible={shown}
220
271
  transparent
221
- animationType={reduceMotion ? "none" : "fade"}
272
+ animationType="none"
222
273
  statusBarTranslucent
223
274
  onRequestClose={close}
224
275
  >
@@ -237,6 +288,8 @@ export function DropdownMenuContent({
237
288
  accessibilityRole="menu"
238
289
  accessibilityViewIsModal
239
290
  onAccessibilityEscape={close}
291
+ // Leaving: a late tap on a row must not select twice.
292
+ pointerEvents={open ? "auto" : "none"}
240
293
  style={{
241
294
  position: "absolute",
242
295
  ...position,
@@ -245,18 +298,20 @@ export function DropdownMenuContent({
245
298
  opacity: contentHeight === null ? 0 : 1,
246
299
  }}
247
300
  >
248
- <FloatingSurface blur={false} radius={DROPDOWN_MENU.radius} style={{ maxHeight: position.maxHeight }}>
249
- <ScrollView
250
- bounces={false}
251
- showsVerticalScrollIndicator={false}
252
- onContentSizeChange={(_width, height) => setContentHeight(height)}
253
- contentContainerStyle={{ padding: DROPDOWN_MENU.padding }}
254
- >
255
- <View className={cn(className)} style={style} {...props}>
256
- {children}
257
- </View>
258
- </ScrollView>
259
- </FloatingSurface>
301
+ <Animated.View style={[{ transformOrigin }, panelStyle]}>
302
+ <FloatingSurface blur={false} radius={DROPDOWN_MENU.radius} style={{ maxHeight: position.maxHeight }}>
303
+ <ScrollView
304
+ bounces={false}
305
+ showsVerticalScrollIndicator={false}
306
+ onContentSizeChange={(_width, height) => setContentHeight(height)}
307
+ contentContainerStyle={{ padding: DROPDOWN_MENU.padding }}
308
+ >
309
+ <View className={cn(className)} style={style} {...props}>
310
+ {children}
311
+ </View>
312
+ </ScrollView>
313
+ </FloatingSurface>
314
+ </Animated.View>
260
315
  </View>
261
316
  </View>
262
317
  </Modal>