@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.
- package/CHANGELOG.md +81 -1
- package/README.md +7 -7
- package/dist/applyBounds-BYGiHrYO.d.mts +18 -0
- package/dist/applyBounds-BYGiHrYO.d.ts +18 -0
- package/dist/{chunk-E3ALFSH2.js → chunk-2UGWAB6N.js} +78 -70
- package/dist/{chunk-ZBHQPVWE.js → chunk-3ZNHPT5Z.js} +2 -2
- package/dist/{chunk-IHVMNOS4.js → chunk-46766TBM.js} +2 -2
- package/dist/{chunk-MUT6BTZS.js → chunk-4EZ5DBL3.js} +10 -7
- package/dist/{chunk-MFAFB4K7.mjs → chunk-6FCATUMY.mjs} +8 -10
- package/dist/{chunk-6YIUETBF.mjs → chunk-7BH3CAO5.mjs} +1 -1
- package/dist/{chunk-JBK5ZLMH.mjs → chunk-CUHOCONB.mjs} +1 -1
- package/dist/{chunk-M4766VUV.mjs → chunk-DRA2K53O.mjs} +1 -1
- package/dist/{chunk-L4JFECXU.mjs → chunk-F4HMCXAX.mjs} +6 -3
- package/dist/{chunk-W7NTRSPD.mjs → chunk-HEAWMZEM.mjs} +105 -66
- package/dist/{chunk-IX6SEOSK.mjs → chunk-JENYDTXH.mjs} +52 -44
- package/dist/chunk-KFHZMFAX.js +23 -0
- package/dist/{chunk-6AN5X3YE.js → chunk-KXU6VH2Y.js} +10 -11
- package/dist/{chunk-WNVHPMBI.js → chunk-N33GSDNQ.js} +106 -65
- package/dist/chunk-OH46TGEA.mjs +20 -0
- package/dist/{chunk-QNLSCOR5.mjs → chunk-OLOSU2BD.mjs} +1 -1
- package/dist/chunk-PLKXCJIB.js +8 -0
- package/dist/{chunk-GSUC4HWP.mjs → chunk-QXKPIENP.mjs} +1 -1
- package/dist/chunk-UBHQJFUW.js +8 -0
- package/dist/{chunk-6NOCY764.js → chunk-VKXSL3ZL.js} +2 -2
- package/dist/chunk-XKNEQDAT.js +8 -0
- package/dist/{chunk-EN4PN7X3.mjs → chunk-Z23AMUSW.mjs} +1 -1
- package/dist/gestureLayer/index.d.mts +3 -3
- package/dist/gestureLayer/index.d.ts +3 -3
- package/dist/gestureLayer/index.js +12 -18
- package/dist/gestureLayer/index.mjs +5 -11
- package/dist/index.d.mts +105 -47
- package/dist/index.d.ts +105 -47
- package/dist/index.js +119 -92
- package/dist/index.mjs +71 -60
- package/dist/motion/FlatList.d.mts +1 -1
- package/dist/motion/FlatList.d.ts +1 -1
- package/dist/motion/FlatList.js +5 -5
- package/dist/motion/FlatList.mjs +4 -4
- package/dist/motion/Image.d.mts +1 -1
- package/dist/motion/Image.d.ts +1 -1
- package/dist/motion/Image.js +5 -5
- package/dist/motion/Image.mjs +4 -4
- package/dist/motion/Pressable.d.mts +1 -1
- package/dist/motion/Pressable.d.ts +1 -1
- package/dist/motion/Pressable.js +5 -5
- package/dist/motion/Pressable.mjs +4 -4
- package/dist/motion/ScrollView.d.mts +1 -1
- package/dist/motion/ScrollView.d.ts +1 -1
- package/dist/motion/ScrollView.js +5 -5
- package/dist/motion/ScrollView.mjs +4 -4
- package/dist/motion/Text.d.mts +1 -1
- package/dist/motion/Text.d.ts +1 -1
- package/dist/motion/Text.js +5 -5
- package/dist/motion/Text.mjs +4 -4
- package/dist/motion/View.d.mts +1 -1
- package/dist/motion/View.d.ts +1 -1
- package/dist/motion/View.js +5 -5
- package/dist/motion/View.mjs +4 -4
- package/dist/touch/index.d.mts +2 -1
- package/dist/touch/index.d.ts +2 -1
- package/dist/touch/index.js +16 -31
- package/dist/touch/index.mjs +11 -29
- package/dist/{types-DyJpG64F.d.mts → types-08mG8fNk.d.mts} +10 -3
- package/dist/{types-DyJpG64F.d.ts → types-08mG8fNk.d.ts} +10 -3
- package/dist/{useGesture-DbH46EBp.d.ts → useGesture-D1lHeQQ6.d.ts} +1 -1
- package/dist/{useGesture-CnZQnYHH.d.mts → useGesture-DjszaHWz.d.mts} +1 -1
- package/llms.txt +1 -1
- package/package.json +4 -2
- package/src/config/namedTransitions.ts +7 -9
- package/src/gestureLayer/index.ts +3 -0
- package/src/gestureLayer/useGestureLayer.ts +6 -9
- package/src/gestures/focusVisibility.ts +19 -17
- package/src/gestures/index.ts +1 -1
- package/src/index.ts +10 -0
- package/src/layout/resolveLayout.ts +4 -1
- package/src/layout/useSharedLayout.ts +2 -1
- package/src/motion/createMotionComponent.tsx +92 -44
- package/src/presence/Presence.tsx +5 -7
- package/src/touch/applyBounds.ts +30 -0
- package/src/touch/index.ts +1 -0
- package/src/touch/useTouchDrag.ts +15 -45
- package/src/transitions/constants.ts +14 -0
- package/src/transitions/easing.ts +23 -11
- package/src/transitions/index.ts +5 -0
- package/src/transitions/keys.ts +0 -2
- package/src/transitions/resolve.ts +86 -11
- package/src/transitions/resolveSequence.ts +3 -1
- package/src/transitions/runtime.ts +4 -7
- package/src/transitions/spring.ts +7 -2
- package/src/types.ts +9 -2
- package/src/values/extrapolation.ts +21 -0
- package/src/values/index.ts +2 -0
- package/src/values/useGesture.ts +9 -2
- package/src/values/useInterpolatedStyle.ts +42 -19
- package/src/values/useShadow.ts +18 -7
- package/src/values/useSpring.ts +34 -25
- package/src/values/useTransform.ts +24 -20
- package/src/values/useTranslateStyle.ts +31 -0
- package/dist/chunk-24NUL23E.js +0 -8
- package/dist/chunk-4XBX7KOD.js +0 -8
- 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(() =>
|
|
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 =
|
|
114
|
-
const output =
|
|
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
|
+
}
|
package/dist/chunk-24NUL23E.js
DELETED
package/dist/chunk-4XBX7KOD.js
DELETED
package/dist/chunk-Z5USXWTE.js
DELETED