@rootnative/inertia 0.0.8 → 0.0.10

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 (101) hide show
  1. package/CHANGELOG.md +81 -1
  2. package/README.md +7 -7
  3. package/dist/applyBounds-BYGiHrYO.d.mts +18 -0
  4. package/dist/applyBounds-BYGiHrYO.d.ts +18 -0
  5. package/dist/{chunk-E3ALFSH2.js → chunk-2UGWAB6N.js} +78 -70
  6. package/dist/{chunk-ZBHQPVWE.js → chunk-3ZNHPT5Z.js} +2 -2
  7. package/dist/{chunk-IHVMNOS4.js → chunk-46766TBM.js} +2 -2
  8. package/dist/{chunk-MUT6BTZS.js → chunk-4EZ5DBL3.js} +10 -7
  9. package/dist/{chunk-MFAFB4K7.mjs → chunk-6FCATUMY.mjs} +8 -10
  10. package/dist/{chunk-6YIUETBF.mjs → chunk-7BH3CAO5.mjs} +1 -1
  11. package/dist/{chunk-JBK5ZLMH.mjs → chunk-CUHOCONB.mjs} +1 -1
  12. package/dist/{chunk-M4766VUV.mjs → chunk-DRA2K53O.mjs} +1 -1
  13. package/dist/{chunk-L4JFECXU.mjs → chunk-F4HMCXAX.mjs} +6 -3
  14. package/dist/{chunk-W7NTRSPD.mjs → chunk-HEAWMZEM.mjs} +105 -66
  15. package/dist/{chunk-IX6SEOSK.mjs → chunk-JENYDTXH.mjs} +52 -44
  16. package/dist/chunk-KFHZMFAX.js +23 -0
  17. package/dist/{chunk-6AN5X3YE.js → chunk-KXU6VH2Y.js} +10 -11
  18. package/dist/{chunk-WNVHPMBI.js → chunk-N33GSDNQ.js} +106 -65
  19. package/dist/chunk-OH46TGEA.mjs +20 -0
  20. package/dist/{chunk-QNLSCOR5.mjs → chunk-OLOSU2BD.mjs} +1 -1
  21. package/dist/chunk-PLKXCJIB.js +8 -0
  22. package/dist/{chunk-GSUC4HWP.mjs → chunk-QXKPIENP.mjs} +1 -1
  23. package/dist/chunk-UBHQJFUW.js +8 -0
  24. package/dist/{chunk-6NOCY764.js → chunk-VKXSL3ZL.js} +2 -2
  25. package/dist/chunk-XKNEQDAT.js +8 -0
  26. package/dist/{chunk-EN4PN7X3.mjs → chunk-Z23AMUSW.mjs} +1 -1
  27. package/dist/gestureLayer/index.d.mts +3 -3
  28. package/dist/gestureLayer/index.d.ts +3 -3
  29. package/dist/gestureLayer/index.js +12 -18
  30. package/dist/gestureLayer/index.mjs +5 -11
  31. package/dist/index.d.mts +105 -47
  32. package/dist/index.d.ts +105 -47
  33. package/dist/index.js +119 -92
  34. package/dist/index.mjs +71 -60
  35. package/dist/motion/FlatList.d.mts +1 -1
  36. package/dist/motion/FlatList.d.ts +1 -1
  37. package/dist/motion/FlatList.js +5 -5
  38. package/dist/motion/FlatList.mjs +4 -4
  39. package/dist/motion/Image.d.mts +1 -1
  40. package/dist/motion/Image.d.ts +1 -1
  41. package/dist/motion/Image.js +5 -5
  42. package/dist/motion/Image.mjs +4 -4
  43. package/dist/motion/Pressable.d.mts +1 -1
  44. package/dist/motion/Pressable.d.ts +1 -1
  45. package/dist/motion/Pressable.js +5 -5
  46. package/dist/motion/Pressable.mjs +4 -4
  47. package/dist/motion/ScrollView.d.mts +1 -1
  48. package/dist/motion/ScrollView.d.ts +1 -1
  49. package/dist/motion/ScrollView.js +5 -5
  50. package/dist/motion/ScrollView.mjs +4 -4
  51. package/dist/motion/Text.d.mts +1 -1
  52. package/dist/motion/Text.d.ts +1 -1
  53. package/dist/motion/Text.js +5 -5
  54. package/dist/motion/Text.mjs +4 -4
  55. package/dist/motion/View.d.mts +1 -1
  56. package/dist/motion/View.d.ts +1 -1
  57. package/dist/motion/View.js +5 -5
  58. package/dist/motion/View.mjs +4 -4
  59. package/dist/touch/index.d.mts +2 -1
  60. package/dist/touch/index.d.ts +2 -1
  61. package/dist/touch/index.js +16 -31
  62. package/dist/touch/index.mjs +11 -29
  63. package/dist/{types-DyJpG64F.d.mts → types-08mG8fNk.d.mts} +10 -3
  64. package/dist/{types-DyJpG64F.d.ts → types-08mG8fNk.d.ts} +10 -3
  65. package/dist/{useGesture-DbH46EBp.d.ts → useGesture-D1lHeQQ6.d.ts} +1 -1
  66. package/dist/{useGesture-CnZQnYHH.d.mts → useGesture-DjszaHWz.d.mts} +1 -1
  67. package/llms.txt +1 -1
  68. package/package.json +4 -2
  69. package/src/config/namedTransitions.ts +7 -9
  70. package/src/gestureLayer/index.ts +3 -0
  71. package/src/gestureLayer/useGestureLayer.ts +6 -9
  72. package/src/gestures/focusVisibility.ts +19 -17
  73. package/src/gestures/index.ts +1 -1
  74. package/src/index.ts +10 -0
  75. package/src/layout/resolveLayout.ts +4 -1
  76. package/src/layout/useSharedLayout.ts +2 -1
  77. package/src/motion/createMotionComponent.tsx +92 -44
  78. package/src/presence/Presence.tsx +5 -7
  79. package/src/touch/applyBounds.ts +30 -0
  80. package/src/touch/index.ts +1 -0
  81. package/src/touch/useTouchDrag.ts +15 -45
  82. package/src/transitions/constants.ts +14 -0
  83. package/src/transitions/easing.ts +23 -11
  84. package/src/transitions/index.ts +5 -0
  85. package/src/transitions/keys.ts +0 -2
  86. package/src/transitions/resolve.ts +86 -11
  87. package/src/transitions/resolveSequence.ts +3 -1
  88. package/src/transitions/runtime.ts +4 -7
  89. package/src/transitions/spring.ts +7 -2
  90. package/src/types.ts +9 -2
  91. package/src/values/extrapolation.ts +21 -0
  92. package/src/values/index.ts +2 -0
  93. package/src/values/useGesture.ts +9 -2
  94. package/src/values/useInterpolatedStyle.ts +42 -19
  95. package/src/values/useShadow.ts +18 -7
  96. package/src/values/useSpring.ts +34 -25
  97. package/src/values/useTransform.ts +24 -20
  98. package/src/values/useTranslateStyle.ts +31 -0
  99. package/dist/chunk-24NUL23E.js +0 -8
  100. package/dist/chunk-4XBX7KOD.js +0 -8
  101. package/dist/chunk-Z5USXWTE.js +0 -8
@@ -1,5 +1,5 @@
1
+ import { useMemo } from 'react'
1
2
  import {
2
- Extrapolation,
3
3
  interpolate,
4
4
  interpolateColor,
5
5
  useDerivedValue,
@@ -11,17 +11,10 @@ import {
11
11
  // import is always available wherever Inertia is.
12
12
  import { isWorkletFunction } from 'react-native-worklets'
13
13
  import { warnNonWorkletOnce } from '../internal/nonWorkletWarning'
14
+ import { stableSig } from '../transitions/sig'
15
+ import { mapExtrapolation, type ExtrapolationMode } from './extrapolation'
14
16
 
15
- /**
16
- * Extrapolation behavior at the edges of the input range. Mirrors
17
- * Reanimated's enum so consumers don't need a separate import.
18
- *
19
- * - `'clamp'` (default) — output stays pinned at the first/last value
20
- * outside the input range. Matches Framer Motion's default.
21
- * - `'identity'` — return the input unchanged outside the range.
22
- * - `'extend'` — continue the linear slope beyond the range.
23
- */
24
- export type ExtrapolationMode = 'clamp' | 'identity' | 'extend'
17
+ export type { ExtrapolationMode }
25
18
 
26
19
  export interface UseTransformOptions {
27
20
  extrapolateLeft?: ExtrapolationMode
@@ -34,7 +27,10 @@ export interface UseTransformOptions {
34
27
  * ```ts
35
28
  * const x = useMotionValue(0)
36
29
  * const y = useMotionValue(0)
37
- * const distance = useTransform(() => Math.sqrt(x.value ** 2 + y.value ** 2))
30
+ * const distance = useTransform(() => {
31
+ * 'worklet'
32
+ * return Math.sqrt(x.value ** 2 + y.value ** 2)
33
+ * })
38
34
  * ```
39
35
  *
40
36
  * The transformer MUST be a worklet — put the `'worklet'` directive as its
@@ -87,6 +83,20 @@ export function useTransform<T>(
87
83
  // `useDerivedValue` exactly once. Keeping the hook call unconditional
88
84
  // satisfies rules-of-hooks; per-call branching (transformer vs
89
85
  // interpolation) is decided once at JS time, never at frame time.
86
+ // Range arrays are memoised on their contents: callers routinely write
87
+ // `useTransform(x, [0, 1], [0, 100])` inline, and a fresh array each render
88
+ // would otherwise change the producer's closure and rebuild the derived
89
+ // value's worklet every render.
90
+ const rangeSig = stableSig([inputRange, outputRange])
91
+ const ranges = useMemo(
92
+ () => ({
93
+ input: (inputRange ?? []) as readonly number[],
94
+ output: (outputRange ?? []) as readonly (number | string)[],
95
+ }),
96
+ // eslint-disable-next-line react-hooks/exhaustive-deps
97
+ [rangeSig],
98
+ )
99
+
90
100
  let producer: () => unknown
91
101
  if (typeof arg1 === 'function') {
92
102
  // Transformer overload. Must be a worklet — the directive-wrapped
@@ -110,8 +120,8 @@ export function useTransform<T>(
110
120
  // Interpolation overload. We pre-resolve everything JS-side so the
111
121
  // worklet body only consumes flat values.
112
122
  const source = arg1
113
- const input = inputRange as readonly number[]
114
- const output = outputRange as readonly (number | string)[]
123
+ const input = ranges.input
124
+ const output = ranges.output
115
125
  const isColor = output.length > 0 && typeof output[0] === 'string'
116
126
  const extrapolateLeft = mapExtrapolation(options?.extrapolateLeft)
117
127
  const extrapolateRight = mapExtrapolation(options?.extrapolateRight)
@@ -140,9 +150,3 @@ export function useTransform<T>(
140
150
  | SharedValue<number>
141
151
  | SharedValue<string>
142
152
  }
143
-
144
- function mapExtrapolation(mode: ExtrapolationMode | undefined): Extrapolation {
145
- if (mode === 'identity') return Extrapolation.IDENTITY
146
- if (mode === 'extend') return Extrapolation.EXTEND
147
- return Extrapolation.CLAMP
148
- }
@@ -0,0 +1,31 @@
1
+ import { useAnimatedStyle, type SharedValue } from 'react-native-reanimated'
2
+
3
+ /**
4
+ * Animated style that translates by two shared values:
5
+ * `transform: [{ translateX: x }, { translateY: y }]`.
6
+ *
7
+ * This is the style fragment every drag-style hook returns (`useTouchDrag`,
8
+ * and `useDrag` / `usePan` / `useSwipe` in `@rootnative/inertia-gestures`).
9
+ * Use it directly when a custom gesture owns its own translation values.
10
+ *
11
+ * The style owns the whole `transform` key. Do not stack a second transform
12
+ * style beside it — `transform` is one key in React Native, so the later
13
+ * style replaces this one instead of merging. Nest another animated view, or
14
+ * build one style from `x` / `y` with `useInterpolatedStyle`, to add a
15
+ * transform.
16
+ *
17
+ * ```tsx
18
+ * const x = useMotionValue(0)
19
+ * const y = useMotionValue(0)
20
+ * const style = useTranslateStyle(x, y)
21
+ * return <Motion.View style={style} />
22
+ * ```
23
+ */
24
+ export function useTranslateStyle(
25
+ x: SharedValue<number>,
26
+ y: SharedValue<number>,
27
+ ): ReturnType<typeof useAnimatedStyle> {
28
+ return useAnimatedStyle(() => ({
29
+ transform: [{ translateX: x.value }, { translateY: y.value }],
30
+ }))
31
+ }
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkE3ALFSH2_js = require('./chunk-E3ALFSH2.js');
4
- var reactNative = require('react-native');
5
-
6
- var MotionView = chunkE3ALFSH2_js.createMotionComponent(reactNative.View);
7
-
8
- exports.MotionView = MotionView;
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkE3ALFSH2_js = require('./chunk-E3ALFSH2.js');
4
- var reactNative = require('react-native');
5
-
6
- var MotionText = chunkE3ALFSH2_js.createMotionComponent(reactNative.Text);
7
-
8
- exports.MotionText = MotionText;
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkE3ALFSH2_js = require('./chunk-E3ALFSH2.js');
4
- var reactNative = require('react-native');
5
-
6
- var MotionImage = chunkE3ALFSH2_js.createMotionComponent(reactNative.Image);
7
-
8
- exports.MotionImage = MotionImage;