@rootnative/inertia 0.0.0-alpha.0 → 0.0.0-alpha.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +2 -0
  3. package/dist/gestureLayer/index.d.mts +6 -5
  4. package/dist/gestureLayer/index.d.ts +6 -5
  5. package/dist/gestureLayer/index.js +89 -27
  6. package/dist/gestureLayer/index.js.map +1 -1
  7. package/dist/gestureLayer/index.mjs +89 -27
  8. package/dist/gestureLayer/index.mjs.map +1 -1
  9. package/dist/index.d.mts +127 -16
  10. package/dist/index.d.ts +127 -16
  11. package/dist/index.js +177 -60
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +175 -61
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/motion/Image.d.mts +1 -1
  16. package/dist/motion/Image.d.ts +1 -1
  17. package/dist/motion/Image.js +90 -48
  18. package/dist/motion/Image.js.map +1 -1
  19. package/dist/motion/Image.mjs +90 -48
  20. package/dist/motion/Image.mjs.map +1 -1
  21. package/dist/motion/Pressable.d.mts +1 -1
  22. package/dist/motion/Pressable.d.ts +1 -1
  23. package/dist/motion/Pressable.js +90 -48
  24. package/dist/motion/Pressable.js.map +1 -1
  25. package/dist/motion/Pressable.mjs +90 -48
  26. package/dist/motion/Pressable.mjs.map +1 -1
  27. package/dist/motion/ScrollView.d.mts +1 -1
  28. package/dist/motion/ScrollView.d.ts +1 -1
  29. package/dist/motion/ScrollView.js +90 -48
  30. package/dist/motion/ScrollView.js.map +1 -1
  31. package/dist/motion/ScrollView.mjs +90 -48
  32. package/dist/motion/ScrollView.mjs.map +1 -1
  33. package/dist/motion/Text.d.mts +1 -1
  34. package/dist/motion/Text.d.ts +1 -1
  35. package/dist/motion/Text.js +90 -48
  36. package/dist/motion/Text.js.map +1 -1
  37. package/dist/motion/Text.mjs +90 -48
  38. package/dist/motion/Text.mjs.map +1 -1
  39. package/dist/motion/View.d.mts +1 -1
  40. package/dist/motion/View.d.ts +1 -1
  41. package/dist/motion/View.js +90 -48
  42. package/dist/motion/View.js.map +1 -1
  43. package/dist/motion/View.mjs +90 -48
  44. package/dist/motion/View.mjs.map +1 -1
  45. package/dist/touch/index.d.mts +1 -1
  46. package/dist/touch/index.d.ts +1 -1
  47. package/dist/{types-cU43dEmH.d.mts → types-BzEgiUdJ.d.mts} +58 -9
  48. package/dist/{types-cU43dEmH.d.ts → types-BzEgiUdJ.d.ts} +58 -9
  49. package/dist/{useGesture-BnY65PlQ.d.ts → useGesture-BRLgiNOC.d.ts} +6 -4
  50. package/dist/{useGesture-DxtXdz-K.d.mts → useGesture-C0GBS7d2.d.mts} +6 -4
  51. package/llms.txt +8 -4
  52. package/package.json +1 -1
  53. package/src/__type-tests__/motion-value.test-d.ts +39 -0
  54. package/src/config/MotionConfig.tsx +55 -9
  55. package/src/config/MotionConfigContext.ts +21 -1
  56. package/src/config/index.ts +7 -1
  57. package/src/config/namedTransitions.ts +80 -0
  58. package/src/gestureLayer/useGestureLayer.ts +32 -8
  59. package/src/index.ts +20 -2
  60. package/src/motion/createMotionComponent.tsx +36 -6
  61. package/src/transitions/cubicBezier.ts +126 -0
  62. package/src/transitions/index.ts +1 -0
  63. package/src/types.ts +63 -8
  64. package/src/values/useAnimation.ts +12 -6
  65. package/src/values/useBooleanSpring.ts +5 -3
  66. package/src/values/useGesture.ts +25 -7
  67. package/src/values/useMotionValue.ts +11 -0
  68. package/src/values/useScroll.ts +8 -1
  69. package/src/values/useSpring.ts +46 -9
@@ -5,8 +5,15 @@ import {
5
5
  withSpring,
6
6
  type SharedValue,
7
7
  } from 'react-native-reanimated'
8
+ import { lookupNamedTransition, useNamedTransitions } from '../config'
8
9
  import { springToReanimated } from '../transitions/spring'
9
- import { type SpringTransition } from '../types'
10
+ import {
11
+ type NamedTransitions,
12
+ type SpringTransition,
13
+ type TransitionName,
14
+ } from '../types'
15
+
16
+ declare const __DEV__: boolean
10
17
 
11
18
  /**
12
19
  * Animate a shared value toward `target` with spring physics, using the
@@ -21,29 +28,36 @@ import { type SpringTransition } from '../types'
21
28
  *
22
29
  * Both call sites end up at the same `withSpring` invocation; the split is
23
30
  * just about which thread observes the source change.
31
+ *
32
+ * `config` also accepts a `TransitionName` registered on the nearest
33
+ * `<MotionConfig transitions>`. Because this hook is spring-only, the name
34
+ * must resolve to a spring config — a name registered as timing / decay /
35
+ * no-animation warns in dev and falls back to the default spring (reach for
36
+ * `useAnimation` when the named transition's type should be honored).
24
37
  */
25
38
  export function useSpring(
26
39
  target: number | SharedValue<number>,
27
- config?: SpringTransition,
40
+ config?: SpringTransition | TransitionName,
28
41
  ): SharedValue<number> {
42
+ const spring = resolveSpringInput(config, useNamedTransitions())
29
43
  // Reanimated config is rebuilt only when the public config object changes
30
44
  // shape. The worklet path reads this from JS-thread closure capture, which
31
45
  // is fine: it's the resolved config that's invariant across UI-thread
32
46
  // ticks, not a JS-thread reference that would go stale.
33
47
  const reanimConfig = useMemo(
34
- () => springToReanimated(config ?? {}),
48
+ () => springToReanimated(spring ?? {}),
35
49
  // Keyed on the resolved primitive fields rather than the `config` object
36
50
  // identity: callers routinely pass a fresh object literal each render, so
37
51
  // depending on `config` itself would rebuild the Reanimated config on
38
52
  // every render and defeat the memo.
39
53
  // eslint-disable-next-line react-hooks/exhaustive-deps
40
54
  [
41
- config?.tension,
42
- config?.friction,
43
- config?.mass,
44
- config?.velocity,
45
- config?.restSpeedThreshold,
46
- config?.restDisplacementThreshold,
55
+ spring?.tension,
56
+ spring?.friction,
57
+ spring?.mass,
58
+ spring?.velocity,
59
+ spring?.restSpeedThreshold,
60
+ spring?.restDisplacementThreshold,
47
61
  ],
48
62
  )
49
63
 
@@ -84,6 +98,29 @@ export function useSpring(
84
98
  return output
85
99
  }
86
100
 
101
+ /**
102
+ * Narrow the public `config` input to a spring config. Names resolve against
103
+ * the registry; a name whose registered config isn't a spring can't drive
104
+ * this hook, so it degrades to the default spring with a dev warning.
105
+ */
106
+ function resolveSpringInput(
107
+ config: SpringTransition | TransitionName | undefined,
108
+ registry: NamedTransitions,
109
+ ): SpringTransition | undefined {
110
+ if (typeof config !== 'string') return config
111
+ const cfg = lookupNamedTransition(config, registry)
112
+ if (cfg.type === undefined || cfg.type === 'spring') return cfg
113
+ if (__DEV__) {
114
+ console.warn(
115
+ `[inertia] Named transition "${config}" resolves to type ` +
116
+ `'${cfg.type}', but useSpring / useBooleanSpring are spring-only — ` +
117
+ `falling back to the default spring. Use useAnimation to honor ` +
118
+ `non-spring named transitions.`,
119
+ )
120
+ }
121
+ return undefined
122
+ }
123
+
87
124
  function isSharedValue(v: unknown): v is SharedValue<number> {
88
125
  // SharedValues are plain objects with a single `value` accessor — there is
89
126
  // no public constructor or instanceof check. Reading `'value' in v` on any