@onlynative/inertia 0.0.1-alpha.7 → 0.0.1-alpha.8

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.
Files changed (69) hide show
  1. package/README.md +1 -1
  2. package/dist/gestureLayer/index.d.mts +119 -0
  3. package/dist/gestureLayer/index.d.ts +119 -0
  4. package/dist/gestureLayer/index.js +1745 -0
  5. package/dist/gestureLayer/index.js.map +1 -0
  6. package/dist/gestureLayer/index.mjs +1743 -0
  7. package/dist/gestureLayer/index.mjs.map +1 -0
  8. package/dist/index.d.mts +114 -74
  9. package/dist/index.d.ts +114 -74
  10. package/dist/index.js +279 -41
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.mjs +279 -44
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/motion/Image.d.mts +1 -1
  15. package/dist/motion/Image.d.ts +1 -1
  16. package/dist/motion/Image.js +178 -4
  17. package/dist/motion/Image.js.map +1 -1
  18. package/dist/motion/Image.mjs +180 -6
  19. package/dist/motion/Image.mjs.map +1 -1
  20. package/dist/motion/Pressable.d.mts +1 -1
  21. package/dist/motion/Pressable.d.ts +1 -1
  22. package/dist/motion/Pressable.js +178 -4
  23. package/dist/motion/Pressable.js.map +1 -1
  24. package/dist/motion/Pressable.mjs +180 -6
  25. package/dist/motion/Pressable.mjs.map +1 -1
  26. package/dist/motion/ScrollView.d.mts +1 -1
  27. package/dist/motion/ScrollView.d.ts +1 -1
  28. package/dist/motion/ScrollView.js +178 -4
  29. package/dist/motion/ScrollView.js.map +1 -1
  30. package/dist/motion/ScrollView.mjs +180 -6
  31. package/dist/motion/ScrollView.mjs.map +1 -1
  32. package/dist/motion/Text.d.mts +1 -1
  33. package/dist/motion/Text.d.ts +1 -1
  34. package/dist/motion/Text.js +178 -4
  35. package/dist/motion/Text.js.map +1 -1
  36. package/dist/motion/Text.mjs +180 -6
  37. package/dist/motion/Text.mjs.map +1 -1
  38. package/dist/motion/View.d.mts +1 -1
  39. package/dist/motion/View.d.ts +1 -1
  40. package/dist/motion/View.js +178 -4
  41. package/dist/motion/View.js.map +1 -1
  42. package/dist/motion/View.mjs +180 -6
  43. package/dist/motion/View.mjs.map +1 -1
  44. package/dist/touch/index.d.mts +146 -0
  45. package/dist/touch/index.d.ts +146 -0
  46. package/dist/touch/index.js +166 -0
  47. package/dist/touch/index.js.map +1 -0
  48. package/dist/touch/index.mjs +164 -0
  49. package/dist/touch/index.mjs.map +1 -0
  50. package/dist/{types-NmNeJjo1.d.mts → types-BwyvoH2V.d.mts} +24 -4
  51. package/dist/{types-NmNeJjo1.d.ts → types-BwyvoH2V.d.ts} +24 -4
  52. package/dist/useGesture-BPPp9LhV.d.ts +84 -0
  53. package/dist/useGesture-BnBF4OtT.d.mts +84 -0
  54. package/llms.txt +12 -3
  55. package/package.json +15 -1
  56. package/src/gestureLayer/index.ts +21 -0
  57. package/src/gestureLayer/useGestureLayer.ts +285 -0
  58. package/src/index.ts +7 -0
  59. package/src/layout/index.ts +15 -0
  60. package/src/layout/sharedRegistry.ts +108 -0
  61. package/src/layout/useSharedLayout.ts +289 -0
  62. package/src/motion/createMotionComponent.tsx +60 -4
  63. package/src/touch/index.ts +18 -0
  64. package/src/touch/useTouchDrag.ts +289 -0
  65. package/src/types.ts +23 -3
  66. package/src/values/index.ts +11 -0
  67. package/src/values/useBooleanSpring.ts +33 -0
  68. package/src/values/useColorTransition.ts +72 -0
  69. package/src/values/useShadow.ts +116 -0
package/dist/index.d.ts CHANGED
@@ -2,9 +2,10 @@ import * as react from 'react';
2
2
  import { ComponentType, ReactNode } from 'react';
3
3
  import * as react_native from 'react-native';
4
4
  import { NativeSyntheticEvent, NativeScrollEvent } from 'react-native';
5
- import { M as MotionComponent, A as AnimatableValue, T as TransitionConfig, E as EasingInput, G as GestureLayerTransitions, S as SpringTransition, V as VariantController } from './types-NmNeJjo1.js';
6
- export { a as AnimateStyle, b as AnimationCallbackInfo, D as DecayTransition, c as GestureSubStates, d as MotionProps, N as NoAnimationTransition, P as PerPropertyTransition, R as RepeatConfig, e as SequenceStep, f as TimingTransition, g as Transition, h as VariantsMap } from './types-NmNeJjo1.js';
7
- import { SharedValue } from 'react-native-reanimated';
5
+ import { M as MotionComponent, A as AnimatableValue, T as TransitionConfig, E as EasingInput, S as SpringTransition, V as VariantController } from './types-BwyvoH2V.js';
6
+ export { a as AnimateStyle, b as AnimationCallbackInfo, D as DecayTransition, G as GestureSubStates, c as MotionProps, N as NoAnimationTransition, P as PerPropertyTransition, R as RepeatConfig, d as SequenceStep, e as TimingTransition, f as Transition, g as VariantsMap } from './types-BwyvoH2V.js';
7
+ import { SharedValue, useAnimatedStyle } from 'react-native-reanimated';
8
+ export { U as UseGestureHandlers, a as UseGestureResult, u as useGesture } from './useGesture-BPPp9LhV.js';
8
9
  export { MotionImage } from './motion/Image.js';
9
10
  export { MotionPressable } from './motion/Pressable.js';
10
11
  export { MotionScrollView } from './motion/ScrollView.js';
@@ -243,84 +244,68 @@ declare function buildReleaseAnimation(transition: TransitionConfig, toValue: nu
243
244
  declare function useAnimation(target: number, transition?: TransitionConfig): SharedValue<number>;
244
245
 
245
246
  /**
246
- * Handler bag returned by `useGesture`. Spread on a `Pressable` to drive the
247
- * shared values returned alongside.
247
+ * Toggle a 0↔1 progress value with a spring whenever `active` flips.
248
248
  *
249
- * Hover handlers use `Pressable`'s own `onHoverIn` / `onHoverOut` names (web
250
- * only no-ops on native). `onFocus` consults `isFocusVisible()` before
251
- * raising the keyboard-only `focusVisible` layer; `focused` always raises.
249
+ * This is the recurring shape behind checkbox checks, accordion expansions,
250
+ * drawer open/closed states, focus rings, and every other binary UI flip
251
+ * that wants spring physics rather than a hard cut. The returned shared
252
+ * value sits at `0` when `active` is `false` and animates toward `1` when
253
+ * `active` flips to `true` (and back again on the reverse flip). Feed it to
254
+ * a `useTransform`, `useShadow`, or a hand-rolled `useAnimatedStyle` to
255
+ * drive whatever the boolean controls visually.
256
+ *
257
+ * ```tsx
258
+ * const progress = useBooleanSpring(isChecked)
259
+ * const indicatorStyle = useAnimatedStyle(() => ({
260
+ * opacity: progress.value,
261
+ * transform: [{ scale: progress.value }],
262
+ * }))
263
+ * ```
264
+ *
265
+ * The spring config follows the same react-spring vocabulary as the rest of
266
+ * the library (`tension` / `friction` / `mass`); omit it to take the
267
+ * library's defaults.
252
268
  */
253
- interface UseGestureHandlers {
254
- onPressIn: () => void;
255
- onPressOut: () => void;
256
- onHoverIn: () => void;
257
- onHoverOut: () => void;
258
- onFocus: () => void;
259
- onBlur: () => void;
260
- }
261
- interface UseGestureResult {
262
- /** 0↔1 progress for the pressed layer. */
263
- pressed: SharedValue<number>;
264
- /** 0↔1 progress for the focused layer (any focus modality). */
265
- focused: SharedValue<number>;
266
- /** 0↔1 progress for the focusVisible layer (keyboard focus only). */
267
- focusVisible: SharedValue<number>;
268
- /** 0↔1 progress for the hovered layer (web only — stays at 0 on native). */
269
- hovered: SharedValue<number>;
270
- /** Handlers to spread on the receiving `Pressable`. */
271
- handlers: UseGestureHandlers;
269
+ declare function useBooleanSpring(active: boolean, springConfig?: SpringTransition): SharedValue<number>;
270
+
271
+ /**
272
+ * Color style keys understood by React Native that this hook can target.
273
+ * Sticks to the keys that exist on the v0.1 animatable surface so the
274
+ * returned style fragment is always a legal RN style.
275
+ */
276
+ type ColorStyleKey = 'backgroundColor' | 'color' | 'borderColor' | 'borderTopColor' | 'borderRightColor' | 'borderBottomColor' | 'borderLeftColor' | 'tintColor' | 'shadowColor';
277
+ interface UseColorTransitionOptions {
278
+ /**
279
+ * Which style slot the interpolated color is emitted under. Defaults to
280
+ * `backgroundColor` the dominant case for state-layer haloes, card
281
+ * fills, and chip surfaces. Override for ring colors (`borderColor`),
282
+ * text colors (`color`), image tints (`tintColor`), etc.
283
+ */
284
+ key?: ColorStyleKey;
272
285
  }
273
286
  /**
274
- * Build a gesture-layer controller. The hook-form of the `gesture` prop
275
- * reach for it when you need to drive multiple animated views from the same
276
- * gesture state (a focus ring + state-layer halo + content tint all on one
277
- * Pressable), which the prop-form's "animate the receiver's own style" model
278
- * can't express.
279
- *
280
- * Returns four 0↔1 shared values (one per layer) and a handler bag to spread
281
- * on a `Pressable`. The shared values are stable across renders — feed them
282
- * into any number of `useAnimatedStyle` blocks anywhere in the tree.
283
- *
284
- * Transitions follow the same shape as the `gesture` prop's accompanying
285
- * `transition`: pass a single `TransitionConfig` to use for every layer, or a
286
- * `GestureLayerTransitions` map to give each layer its own. Layers without an
287
- * explicit transition fall back to the library default spring.
287
+ * Interpolate a single color channel between `from` and `to` as `progress`
288
+ * moves 0→1, returning an animated style fragment that can be spread onto
289
+ * any Reanimated-aware view.
288
290
  *
289
- * Reduced motion (via `<MotionConfig reducedMotion>`) collapses every
290
- * transition to `no-animation` so state changes snap instead of interpolating
291
- * — same behaviour the gesture prop applies.
292
- *
293
- * @example
294
291
  * ```tsx
295
- * import { useAnimatedStyle } from 'react-native-reanimated'
296
- * import { useGesture } from '@onlynative/inertia'
297
- *
298
- * function Card() {
299
- * const { pressed, focused, hovered, handlers } = useGesture({
300
- * pressed: { type: 'timing', duration: 100 },
301
- * hovered: { type: 'timing', duration: 150 },
302
- * focused: { type: 'timing', duration: 200 },
303
- * })
304
- *
305
- * const ringStyle = useAnimatedStyle(() => ({ opacity: focused.value }))
306
- * const haloStyle = useAnimatedStyle(() => ({
307
- * opacity: Math.max(
308
- * hovered.value * 0.08,
309
- * focused.value * 0.10,
310
- * pressed.value * 0.10,
311
- * ),
312
- * }))
313
- *
314
- * return (
315
- * <Pressable {...handlers}>
316
- * <Animated.View style={ringStyle} />
317
- * <Animated.View style={haloStyle} />
318
- * </Pressable>
319
- * )
320
- * }
292
+ * const progress = useBooleanSpring(isPressed)
293
+ * const fillStyle = useColorTransition(progress, [colors.surface, colors.pressed])
294
+ * const ringStyle = useColorTransition(progress, [colors.outline, colors.primary], {
295
+ * key: 'borderColor',
296
+ * })
297
+ *
298
+ * return <Motion.View style={[styles.chip, fillStyle, ringStyle]} />
321
299
  * ```
300
+ *
301
+ * This is a pure interpolator: it does not animate on its own. Drive
302
+ * `progress` upstream with a `useSpring`, `useBooleanSpring`, gesture
303
+ * progress, or scroll-derived `useTransform`. Values outside `[0, 1]`
304
+ * clamp. For a raw `SharedValue<string>` (e.g. to feed a gradient or
305
+ * compose into a hand-rolled `useAnimatedStyle`), use `useTransform`
306
+ * directly with a color output range.
322
307
  */
323
- declare function useGesture(transition?: TransitionConfig | GestureLayerTransitions): UseGestureResult;
308
+ declare function useColorTransition(progress: SharedValue<number>, range: readonly [string, string], options?: UseColorTransitionOptions): ReturnType<typeof useAnimatedStyle>;
324
309
 
325
310
  /**
326
311
  * Create an animatable value owned by JS but readable from worklets.
@@ -450,6 +435,61 @@ interface UseScrollResult {
450
435
  */
451
436
  declare function useScroll(): UseScrollResult;
452
437
 
438
+ /**
439
+ * Shape accepted on either end of a `useShadow` tween. Every field is
440
+ * optional — only keys present on at least one side participate in the
441
+ * output style. Mirrors the flat shadow keys on `Motion.View`'s `animate`
442
+ * surface, plus the nested `shadowOffset` source.
443
+ */
444
+ interface ShadowConfig {
445
+ shadowOpacity?: number;
446
+ shadowRadius?: number;
447
+ shadowOffset?: {
448
+ width?: number;
449
+ height?: number;
450
+ };
451
+ /** Android elevation. iOS shadow consumers can leave this off. */
452
+ elevation?: number;
453
+ shadowColor?: string;
454
+ }
455
+ interface UseShadowOptions {
456
+ /** Shadow state at `progress === 0`. */
457
+ from: ShadowConfig;
458
+ /** Shadow state at `progress === 1`. */
459
+ to: ShadowConfig;
460
+ /**
461
+ * Driver — typically 0→1. Whatever produces it (a `useSpring`, a gesture
462
+ * progress value, a scroll-derived `useTransform`) is the caller's
463
+ * concern. The hook is a pure interpolator; it does not animate on its
464
+ * own. Values outside `[0, 1]` clamp.
465
+ */
466
+ progress: SharedValue<number>;
467
+ }
468
+ /**
469
+ * Interpolate between two shadow configs as `progress` moves 0→1, returning
470
+ * an animated style fragment that can be spread onto any Reanimated-aware
471
+ * view (including `Motion.*` primitives and a hand-rolled `Animated.View`).
472
+ *
473
+ * ```tsx
474
+ * const progress = useSpring(isElevated ? 1 : 0)
475
+ * const shadowStyle = useShadow({
476
+ * from: { shadowOpacity: 0.08, shadowRadius: 2, shadowOffset: { width: 0, height: 1 }, elevation: 1 },
477
+ * to: { shadowOpacity: 0.24, shadowRadius: 12, shadowOffset: { width: 0, height: 8 }, elevation: 8 },
478
+ * progress,
479
+ * })
480
+ *
481
+ * return <Motion.View style={[styles.card, shadowStyle]} />
482
+ * ```
483
+ *
484
+ * Only keys present on either `from` or `to` are emitted. A key present on
485
+ * one side and absent on the other tweens from the present value to the
486
+ * absent side's natural zero (`0` for numbers, `'transparent'` for
487
+ * `shadowColor`, `{ width: 0, height: 0 }` for `shadowOffset`). This is a
488
+ * pure interpolator — to "animate" the shadow, drive `progress` with a
489
+ * spring, timing, or gesture upstream.
490
+ */
491
+ declare function useShadow({ from, to, progress, }: UseShadowOptions): ReturnType<typeof useAnimatedStyle>;
492
+
453
493
  /**
454
494
  * Build a controller for a variants map. The controller is the imperative
455
495
  * escape hatch — pass it to a Motion primitive via `controller={...}` and
@@ -463,4 +503,4 @@ declare function useScroll(): UseScrollResult;
463
503
  */
464
504
  declare function useVariants<V extends Readonly<Record<string, object>>>(variants: V, initial?: keyof V & string): VariantController<keyof V & string>;
465
505
 
466
- export { AnimatableValue, type ExtrapolationMode, Motion, MotionComponent, MotionConfig, type MotionConfigValue, Presence, type PresenceContextValue, type ReducedMotion, SpringTransition, TransitionConfig, type UseGestureHandlers, type UseGestureResult, type UseScrollResult, type UseTransformOptions, VariantController, buildReleaseAnimation, createMotionComponent, ensureWorkletEasing, resolveAnimatableValue, resolveTransition, useAnimation, useGesture, useMotionConfig, useMotionValue, usePresence, useScroll, useShouldReduceMotion, useSpring, useTransform, useVariants };
506
+ export { AnimatableValue, type ColorStyleKey, type ExtrapolationMode, Motion, MotionComponent, MotionConfig, type MotionConfigValue, Presence, type PresenceContextValue, type ReducedMotion, type ShadowConfig, SpringTransition, TransitionConfig, type UseColorTransitionOptions, type UseScrollResult, type UseShadowOptions, type UseTransformOptions, VariantController, buildReleaseAnimation, createMotionComponent, ensureWorkletEasing, resolveAnimatableValue, resolveTransition, useAnimation, useBooleanSpring, useColorTransition, useMotionConfig, useMotionValue, usePresence, useScroll, useShadow, useShouldReduceMotion, useSpring, useTransform, useVariants };
package/dist/index.js CHANGED
@@ -1217,8 +1217,8 @@ function setupSetTimeout() {
1217
1217
  const start = performance.now();
1218
1218
  let timeoutHandle = 0;
1219
1219
  const rafCallback = () => {
1220
- const now = performance.now();
1221
- if (now - start >= delay) {
1220
+ const now2 = performance.now();
1221
+ if (now2 - start >= delay) {
1222
1222
  callback(...args);
1223
1223
  timeoutHandleToRafHandle.delete(timeoutHandle);
1224
1224
  } else {
@@ -1512,6 +1512,157 @@ function resolveLayoutTransition(layout) {
1512
1512
  if ("delay" in spring && spring.delay) builder = builder.delay(spring.delay);
1513
1513
  return builder;
1514
1514
  }
1515
+
1516
+ // src/layout/sharedRegistry.ts
1517
+ var REGISTRY = /* @__PURE__ */ new Map();
1518
+ var SHARED_LAYOUT_TTL_MS = 1e3;
1519
+ var now = () => Date.now();
1520
+ function registerLayout(id, rect) {
1521
+ REGISTRY.set(id, { rect, expiresAt: now() + SHARED_LAYOUT_TTL_MS });
1522
+ }
1523
+ function releaseLayout(id, rect) {
1524
+ REGISTRY.set(id, { rect, expiresAt: now() + SHARED_LAYOUT_TTL_MS });
1525
+ }
1526
+ function consumeLayout(id) {
1527
+ const entry = REGISTRY.get(id);
1528
+ if (!entry) return void 0;
1529
+ REGISTRY.delete(id);
1530
+ if (entry.expiresAt < now()) return void 0;
1531
+ return entry.rect;
1532
+ }
1533
+ function useSharedLayout(options) {
1534
+ const { layoutId, userRef, transition, shouldReduceMotion, userOnLayout } = options;
1535
+ const dx = Animated.useSharedValue(0);
1536
+ const dy = Animated.useSharedValue(0);
1537
+ const sx = Animated.useSharedValue(1);
1538
+ const sy = Animated.useSharedValue(1);
1539
+ const lastRectRef = react.useRef(null);
1540
+ const consumedRef = react.useRef(false);
1541
+ const transitionRef = react.useRef(transition);
1542
+ transitionRef.current = transition;
1543
+ const reducedMotionRef = react.useRef(shouldReduceMotion);
1544
+ reducedMotionRef.current = shouldReduceMotion;
1545
+ const setRef = react.useCallback(
1546
+ (node) => {
1547
+ if (typeof userRef === "function") userRef(node);
1548
+ else if (userRef) userRef.current = node;
1549
+ },
1550
+ [userRef]
1551
+ );
1552
+ const onLayout = react.useCallback(
1553
+ (event) => {
1554
+ userOnLayout?.(event);
1555
+ if (!layoutId) return;
1556
+ const { x, y, width, height } = event.nativeEvent.layout;
1557
+ const rect = { x, y, width, height };
1558
+ lastRectRef.current = rect;
1559
+ let source;
1560
+ if (!consumedRef.current) {
1561
+ consumedRef.current = true;
1562
+ source = consumeLayout(layoutId);
1563
+ }
1564
+ registerLayout(layoutId, rect);
1565
+ if (source) {
1566
+ applyFlip({
1567
+ source,
1568
+ target: rect,
1569
+ dx,
1570
+ dy,
1571
+ sx,
1572
+ sy,
1573
+ transition: transitionRef.current,
1574
+ shouldReduceMotion: reducedMotionRef.current
1575
+ });
1576
+ }
1577
+ },
1578
+ // dx/dy/sx/sy are stable refs from useSharedValue, but eslint's
1579
+ // exhaustive-deps would flag them — including them is harmless and
1580
+ // silences the warning.
1581
+ [layoutId, userOnLayout, dx, dy, sx, sy]
1582
+ );
1583
+ react.useEffect(() => {
1584
+ consumedRef.current = false;
1585
+ }, [layoutId]);
1586
+ react.useEffect(() => {
1587
+ return () => {
1588
+ if (!layoutId) return;
1589
+ const rect = lastRectRef.current;
1590
+ if (!rect) return;
1591
+ releaseLayout(layoutId, rect);
1592
+ };
1593
+ }, [layoutId]);
1594
+ return react.useMemo(
1595
+ () => ({
1596
+ flip: { dx, dy, sx, sy },
1597
+ setRef,
1598
+ onLayout
1599
+ }),
1600
+ [dx, dy, sx, sy, setRef, onLayout]
1601
+ );
1602
+ }
1603
+ function applyFlip(args) {
1604
+ const { source, target, dx, dy, sx, sy, transition, shouldReduceMotion } = args;
1605
+ const sourceCenterX = source.x + source.width / 2;
1606
+ const sourceCenterY = source.y + source.height / 2;
1607
+ const targetCenterX = target.x + target.width / 2;
1608
+ const targetCenterY = target.y + target.height / 2;
1609
+ const deltaX = sourceCenterX - targetCenterX;
1610
+ const deltaY = sourceCenterY - targetCenterY;
1611
+ const scaleX = target.width > 0 ? source.width / target.width : 1;
1612
+ const scaleY = target.height > 0 ? source.height / target.height : 1;
1613
+ if (shouldReduceMotion) {
1614
+ dx.value = 0;
1615
+ dy.value = 0;
1616
+ sx.value = 1;
1617
+ sy.value = 1;
1618
+ return;
1619
+ }
1620
+ if (transition?.type === "no-animation") {
1621
+ dx.value = 0;
1622
+ dy.value = 0;
1623
+ sx.value = 1;
1624
+ sy.value = 1;
1625
+ return;
1626
+ }
1627
+ if (transition?.type === "timing") {
1628
+ const duration = transition.duration ?? 300;
1629
+ dx.value = Animated.withSequence(
1630
+ Animated.withTiming(deltaX, { duration: 0 }),
1631
+ Animated.withTiming(0, { duration })
1632
+ );
1633
+ dy.value = Animated.withSequence(
1634
+ Animated.withTiming(deltaY, { duration: 0 }),
1635
+ Animated.withTiming(0, { duration })
1636
+ );
1637
+ sx.value = Animated.withSequence(
1638
+ Animated.withTiming(scaleX, { duration: 0 }),
1639
+ Animated.withTiming(1, { duration })
1640
+ );
1641
+ sy.value = Animated.withSequence(
1642
+ Animated.withTiming(scaleY, { duration: 0 }),
1643
+ Animated.withTiming(1, { duration })
1644
+ );
1645
+ return;
1646
+ }
1647
+ const springCfg = transition?.type === "spring" ? { ...DEFAULT_SPRING, ...transition } : { ...DEFAULT_SPRING };
1648
+ const springParams = springToReanimated(springCfg);
1649
+ dx.value = Animated.withSequence(
1650
+ Animated.withTiming(deltaX, { duration: 0 }),
1651
+ Animated.withSpring(0, springParams)
1652
+ );
1653
+ dy.value = Animated.withSequence(
1654
+ Animated.withTiming(deltaY, { duration: 0 }),
1655
+ Animated.withSpring(0, springParams)
1656
+ );
1657
+ sx.value = Animated.withSequence(
1658
+ Animated.withTiming(scaleX, { duration: 0 }),
1659
+ Animated.withSpring(1, springParams)
1660
+ );
1661
+ sy.value = Animated.withSequence(
1662
+ Animated.withTiming(scaleY, { duration: 0 }),
1663
+ Animated.withSpring(1, springParams)
1664
+ );
1665
+ }
1515
1666
  var PresenceContext = react.createContext(null);
1516
1667
  function usePresence() {
1517
1668
  return react.useContext(PresenceContext);
@@ -1913,10 +2064,17 @@ function createMotionComponent(Component) {
1913
2064
  controller,
1914
2065
  gesture,
1915
2066
  layout,
2067
+ layoutId,
1916
2068
  onAnimationEnd,
1917
2069
  style,
2070
+ onLayout: userOnLayout,
1918
2071
  ...rest
1919
2072
  } = props;
2073
+ if (__DEV__ && typeof style === "function") {
2074
+ throw new Error(
2075
+ "[inertia] `style` must be a style object or array of style objects, not a function. The function-form `style={(state) => ...}` Pressable API is not supported \u2014 use `gesture.pressed` (or `gesture.focused`, etc.) to drive state-dependent styling instead."
2076
+ );
2077
+ }
1920
2078
  const presence = usePresence();
1921
2079
  const isExiting = presence !== null && presence.isPresent === false;
1922
2080
  const shouldReduceMotion = useShouldReduceMotion();
@@ -2090,6 +2248,15 @@ function createMotionComponent(Component) {
2090
2248
  isExiting,
2091
2249
  shouldReduceMotion
2092
2250
  );
2251
+ const sharedLayout = useSharedLayout({
2252
+ layoutId,
2253
+ userRef: ref,
2254
+ transition: isTopLevelTransition(transition) ? transition : void 0,
2255
+ shouldReduceMotion,
2256
+ userOnLayout
2257
+ });
2258
+ const flip = sharedLayout.flip;
2259
+ const hasLayoutId = layoutId !== void 0;
2093
2260
  const animatedStyle = Animated.useAnimatedStyle(() => {
2094
2261
  const activeKeys = activeKeysRef.current;
2095
2262
  const hasTransform = hasTransformRef.current;
@@ -2138,7 +2305,13 @@ function createMotionComponent(Component) {
2138
2305
  out[key] = v;
2139
2306
  }
2140
2307
  }
2141
- if (hasTransform) out.transform = transform;
2308
+ if (hasLayoutId) {
2309
+ transform.push({ translateX: flip.dx.value });
2310
+ transform.push({ translateY: flip.dy.value });
2311
+ transform.push({ scaleX: flip.sx.value });
2312
+ transform.push({ scaleY: flip.sy.value });
2313
+ }
2314
+ if (hasTransform || hasLayoutId) out.transform = transform;
2142
2315
  if (hasShadowOffset) {
2143
2316
  out.shadowOffset = { width: shadowOffsetW, height: shadowOffsetH };
2144
2317
  }
@@ -2165,9 +2338,10 @@ function createMotionComponent(Component) {
2165
2338
  return /* @__PURE__ */ jsxRuntime.jsx(
2166
2339
  AnimatedComponent,
2167
2340
  {
2168
- ref,
2341
+ ref: sharedLayout.setRef,
2169
2342
  ...rest,
2170
2343
  ...gestureHandlers,
2344
+ onLayout: sharedLayout.onLayout,
2171
2345
  layout: layoutTransition,
2172
2346
  style: mergedStyle
2173
2347
  }
@@ -2496,6 +2670,57 @@ function useAnimation(target, transition) {
2496
2670
  }, [target, cfgSig, shouldReduceMotion]);
2497
2671
  return output;
2498
2672
  }
2673
+ function useSpring(target, config) {
2674
+ const reanimConfig = react.useMemo(
2675
+ () => springToReanimated(config ?? {}),
2676
+ [
2677
+ config?.tension,
2678
+ config?.friction,
2679
+ config?.mass,
2680
+ config?.velocity,
2681
+ config?.restSpeedThreshold,
2682
+ config?.restDisplacementThreshold
2683
+ ]
2684
+ );
2685
+ const isSharedTarget = isSharedValue(target);
2686
+ const initial = isSharedTarget ? target.value : target;
2687
+ const output = Animated.useSharedValue(initial);
2688
+ react.useEffect(() => {
2689
+ if (isSharedTarget) return;
2690
+ output.value = Animated.withSpring(target, reanimConfig);
2691
+ }, [isSharedTarget, target, reanimConfig]);
2692
+ Animated.useAnimatedReaction(
2693
+ () => {
2694
+ "worklet";
2695
+ if (!isSharedTarget) return null;
2696
+ return target.value;
2697
+ },
2698
+ (next, prev) => {
2699
+ "worklet";
2700
+ if (next === null || next === prev) return;
2701
+ output.value = Animated.withSpring(next, reanimConfig);
2702
+ },
2703
+ [isSharedTarget, reanimConfig]
2704
+ );
2705
+ return output;
2706
+ }
2707
+ function isSharedValue(v) {
2708
+ return typeof v === "object" && v !== null && "value" in v;
2709
+ }
2710
+
2711
+ // src/values/useBooleanSpring.ts
2712
+ function useBooleanSpring(active, springConfig) {
2713
+ return useSpring(active ? 1 : 0, springConfig);
2714
+ }
2715
+ function useColorTransition(progress, range, options) {
2716
+ const key = options?.key ?? "backgroundColor";
2717
+ const from = range[0];
2718
+ const to = range[1];
2719
+ return Animated.useAnimatedStyle(() => {
2720
+ "worklet";
2721
+ return { [key]: Animated.interpolateColor(progress.value, [0, 1], [from, to]) };
2722
+ });
2723
+ }
2499
2724
  function useGesture(transition) {
2500
2725
  const pressed = Animated.useSharedValue(0);
2501
2726
  const focused = Animated.useSharedValue(0);
@@ -2543,43 +2768,6 @@ function layerTransition(layer, transition) {
2543
2768
  function useMotionValue(initial) {
2544
2769
  return Animated.useSharedValue(initial);
2545
2770
  }
2546
- function useSpring(target, config) {
2547
- const reanimConfig = react.useMemo(
2548
- () => springToReanimated(config ?? {}),
2549
- [
2550
- config?.tension,
2551
- config?.friction,
2552
- config?.mass,
2553
- config?.velocity,
2554
- config?.restSpeedThreshold,
2555
- config?.restDisplacementThreshold
2556
- ]
2557
- );
2558
- const isSharedTarget = isSharedValue(target);
2559
- const initial = isSharedTarget ? target.value : target;
2560
- const output = Animated.useSharedValue(initial);
2561
- react.useEffect(() => {
2562
- if (isSharedTarget) return;
2563
- output.value = Animated.withSpring(target, reanimConfig);
2564
- }, [isSharedTarget, target, reanimConfig]);
2565
- Animated.useAnimatedReaction(
2566
- () => {
2567
- "worklet";
2568
- if (!isSharedTarget) return null;
2569
- return target.value;
2570
- },
2571
- (next, prev) => {
2572
- "worklet";
2573
- if (next === null || next === prev) return;
2574
- output.value = Animated.withSpring(next, reanimConfig);
2575
- },
2576
- [isSharedTarget, reanimConfig]
2577
- );
2578
- return output;
2579
- }
2580
- function isSharedValue(v) {
2581
- return typeof v === "object" && v !== null && "value" in v;
2582
- }
2583
2771
  function useTransform(arg1, inputRange, outputRange, options) {
2584
2772
  let producer;
2585
2773
  if (typeof arg1 === "function") {
@@ -2635,6 +2823,53 @@ function useScroll() {
2635
2823
  onScroll: handler
2636
2824
  };
2637
2825
  }
2826
+ function useShadow({
2827
+ from,
2828
+ to,
2829
+ progress
2830
+ }) {
2831
+ const hasOpacity = from.shadowOpacity !== void 0 || to.shadowOpacity !== void 0;
2832
+ const hasRadius = from.shadowRadius !== void 0 || to.shadowRadius !== void 0;
2833
+ const hasElevation = from.elevation !== void 0 || to.elevation !== void 0;
2834
+ const hasColor = from.shadowColor !== void 0 || to.shadowColor !== void 0;
2835
+ const hasOffset = from.shadowOffset !== void 0 || to.shadowOffset !== void 0;
2836
+ const opacityFrom = from.shadowOpacity ?? 0;
2837
+ const opacityTo = to.shadowOpacity ?? 0;
2838
+ const radiusFrom = from.shadowRadius ?? 0;
2839
+ const radiusTo = to.shadowRadius ?? 0;
2840
+ const elevationFrom = from.elevation ?? 0;
2841
+ const elevationTo = to.elevation ?? 0;
2842
+ const colorFrom = from.shadowColor ?? "transparent";
2843
+ const colorTo = to.shadowColor ?? "transparent";
2844
+ const offsetWFrom = from.shadowOffset?.width ?? 0;
2845
+ const offsetWTo = to.shadowOffset?.width ?? 0;
2846
+ const offsetHFrom = from.shadowOffset?.height ?? 0;
2847
+ const offsetHTo = to.shadowOffset?.height ?? 0;
2848
+ return Animated.useAnimatedStyle(() => {
2849
+ "worklet";
2850
+ const t = progress.value;
2851
+ const out = {};
2852
+ if (hasOpacity) {
2853
+ out.shadowOpacity = Animated.interpolate(t, [0, 1], [opacityFrom, opacityTo]);
2854
+ }
2855
+ if (hasRadius) {
2856
+ out.shadowRadius = Animated.interpolate(t, [0, 1], [radiusFrom, radiusTo]);
2857
+ }
2858
+ if (hasElevation) {
2859
+ out.elevation = Animated.interpolate(t, [0, 1], [elevationFrom, elevationTo]);
2860
+ }
2861
+ if (hasColor) {
2862
+ out.shadowColor = Animated.interpolateColor(t, [0, 1], [colorFrom, colorTo]);
2863
+ }
2864
+ if (hasOffset) {
2865
+ out.shadowOffset = {
2866
+ width: Animated.interpolate(t, [0, 1], [offsetWFrom, offsetWTo]),
2867
+ height: Animated.interpolate(t, [0, 1], [offsetHFrom, offsetHTo])
2868
+ };
2869
+ }
2870
+ return out;
2871
+ });
2872
+ }
2638
2873
  function useVariants(variants, initial) {
2639
2874
  const variantsRef = react.useRef(variants);
2640
2875
  return react.useMemo(() => {
@@ -2682,11 +2917,14 @@ exports.ensureWorkletEasing = ensureWorkletEasing;
2682
2917
  exports.resolveAnimatableValue = resolveAnimatableValue;
2683
2918
  exports.resolveTransition = resolveTransition;
2684
2919
  exports.useAnimation = useAnimation;
2920
+ exports.useBooleanSpring = useBooleanSpring;
2921
+ exports.useColorTransition = useColorTransition;
2685
2922
  exports.useGesture = useGesture;
2686
2923
  exports.useMotionConfig = useMotionConfig;
2687
2924
  exports.useMotionValue = useMotionValue;
2688
2925
  exports.usePresence = usePresence;
2689
2926
  exports.useScroll = useScroll;
2927
+ exports.useShadow = useShadow;
2690
2928
  exports.useShouldReduceMotion = useShouldReduceMotion;
2691
2929
  exports.useSpring = useSpring;
2692
2930
  exports.useTransform = useTransform;