@rootnative/inertia 0.0.9 → 0.0.11
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 +95 -1
- package/README.md +8 -8
- package/dist/{chunk-MFAFB4K7.mjs → chunk-2Q6JMDYZ.mjs} +8 -10
- package/dist/chunk-2UREDR4Z.js +8 -0
- package/dist/{chunk-ZBHQPVWE.js → chunk-3PB27UIE.js} +2 -2
- package/dist/{chunk-IX6SEOSK.mjs → chunk-5EYIZG72.mjs} +60 -45
- package/dist/{chunk-EN4PN7X3.mjs → chunk-7RMSLKQQ.mjs} +1 -1
- package/dist/{chunk-6YIUETBF.mjs → chunk-DT2KVAAO.mjs} +1 -1
- package/dist/{chunk-L4JFECXU.mjs → chunk-FKJLPYGY.mjs} +6 -3
- package/dist/{chunk-E3ALFSH2.js → chunk-HBURWGCZ.js} +86 -71
- package/dist/chunk-JAJHKJC5.js +8 -0
- package/dist/chunk-JBMTTICC.js +8 -0
- package/dist/{chunk-GSUC4HWP.mjs → chunk-JGQ6YRDN.mjs} +1 -1
- package/dist/chunk-KFHZMFAX.js +23 -0
- package/dist/{chunk-M4766VUV.mjs → chunk-LHW4VNWD.mjs} +1 -1
- package/dist/{chunk-MUT6BTZS.js → chunk-NTG6PSGZ.js} +10 -7
- package/dist/chunk-OH46TGEA.mjs +20 -0
- package/dist/{chunk-6AN5X3YE.js → chunk-QDMSFRQR.js} +10 -11
- package/dist/{chunk-W7NTRSPD.mjs → chunk-QIRKPDXA.mjs} +118 -68
- package/dist/{chunk-WNVHPMBI.js → chunk-QX5JHRZ2.js} +118 -66
- package/dist/{chunk-6NOCY764.js → chunk-R7YD6L3D.js} +2 -2
- package/dist/{chunk-JBK5ZLMH.mjs → chunk-RO4XFTQ6.mjs} +1 -1
- package/dist/{chunk-QNLSCOR5.mjs → chunk-UGYBFAVY.mjs} +1 -1
- package/dist/{chunk-IHVMNOS4.js → chunk-XLKI2MSD.js} +2 -2
- 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 +108 -49
- package/dist/index.d.ts +108 -49
- package/dist/index.js +114 -91
- package/dist/index.mjs +66 -59
- package/dist/motion/FlatList.d.mts +2 -1
- package/dist/motion/FlatList.d.ts +2 -1
- package/dist/motion/FlatList.js +5 -5
- package/dist/motion/FlatList.mjs +4 -4
- package/dist/motion/Image.d.mts +2 -1
- package/dist/motion/Image.d.ts +2 -1
- package/dist/motion/Image.js +5 -5
- package/dist/motion/Image.mjs +4 -4
- package/dist/motion/Pressable.d.mts +2 -1
- package/dist/motion/Pressable.d.ts +2 -1
- package/dist/motion/Pressable.js +5 -5
- package/dist/motion/Pressable.mjs +4 -4
- package/dist/motion/ScrollView.d.mts +2 -1
- package/dist/motion/ScrollView.d.ts +2 -1
- package/dist/motion/ScrollView.js +5 -5
- package/dist/motion/ScrollView.mjs +4 -4
- package/dist/motion/Text.d.mts +2 -1
- package/dist/motion/Text.d.ts +2 -1
- package/dist/motion/Text.js +5 -5
- package/dist/motion/Text.mjs +4 -4
- package/dist/motion/View.d.mts +2 -1
- package/dist/motion/View.d.ts +2 -1
- package/dist/motion/View.js +5 -5
- package/dist/motion/View.mjs +4 -4
- package/dist/touch/index.d.mts +5 -3
- package/dist/touch/index.d.ts +5 -3
- package/dist/touch/index.js +16 -31
- package/dist/touch/index.mjs +11 -29
- package/dist/{types-DyJpG64F.d.mts → types-C5Zbs9MC.d.mts} +22 -4
- package/dist/{types-DyJpG64F.d.ts → types-C5Zbs9MC.d.ts} +22 -4
- package/dist/{useGesture-DbH46EBp.d.ts → useGesture-Be0ZhCWj.d.ts} +1 -1
- package/dist/{useGesture-CnZQnYHH.d.mts → useGesture-Ve8EGjTr.d.mts} +1 -1
- package/dist/useTranslateStyle-BDrOD97O.d.mts +58 -0
- package/dist/useTranslateStyle-BDrOD97O.d.ts +58 -0
- package/jest-preset.js +31 -2
- package/llms.txt +2 -1
- package/package.json +15 -12
- 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 +12 -0
- package/src/internal/boxShadow.ts +24 -2
- 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 +18 -46
- 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 +45 -3
- package/src/transitions/runtime.ts +4 -7
- package/src/transitions/spring.ts +7 -2
- package/src/types.ts +23 -3
- package/src/values/extrapolation.ts +21 -0
- package/src/values/index.ts +3 -0
- package/src/values/useColorCascade.ts +3 -3
- package/src/values/useColorTransition.ts +17 -2
- package/src/values/useGesture.ts +9 -2
- package/src/values/useInterpolatedStyle.ts +13 -13
- package/src/values/useShadow.ts +36 -9
- package/src/values/useSpring.ts +34 -25
- package/src/values/useTransform.ts +24 -20
- package/src/values/useTranslateStyle.ts +47 -0
- package/dist/chunk-24NUL23E.js +0 -8
- package/dist/chunk-4XBX7KOD.js +0 -8
- package/dist/chunk-Z5USXWTE.js +0 -8
package/src/values/useSpring.ts
CHANGED
|
@@ -6,7 +6,12 @@ import {
|
|
|
6
6
|
withSpring,
|
|
7
7
|
type SharedValue,
|
|
8
8
|
} from 'react-native-reanimated'
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
lookupNamedTransition,
|
|
11
|
+
useNamedTransitions,
|
|
12
|
+
useShouldReduceMotion,
|
|
13
|
+
} from '../config'
|
|
14
|
+
import { warnOnce } from '../internal/warnOnce'
|
|
10
15
|
import { springToReanimated } from '../transitions/spring'
|
|
11
16
|
import {
|
|
12
17
|
type NamedTransitions,
|
|
@@ -14,8 +19,6 @@ import {
|
|
|
14
19
|
type TransitionName,
|
|
15
20
|
} from '../types'
|
|
16
21
|
|
|
17
|
-
declare const __DEV__: boolean
|
|
18
|
-
|
|
19
22
|
/**
|
|
20
23
|
* Animate a shared value toward `target` with spring physics, using the
|
|
21
24
|
* library's react-spring vocabulary (`tension` / `friction` / `mass`).
|
|
@@ -35,12 +38,16 @@ declare const __DEV__: boolean
|
|
|
35
38
|
* must resolve to a spring config — a name registered as timing / decay /
|
|
36
39
|
* no-animation warns in dev and falls back to the default spring (reach for
|
|
37
40
|
* `useAnimation` when the named transition's type should be honored).
|
|
41
|
+
*
|
|
42
|
+
* Reduced motion (via `<MotionConfig reducedMotion>`) is honoured: the output
|
|
43
|
+
* is assigned the target directly, with no spring, on both paths.
|
|
38
44
|
*/
|
|
39
45
|
export function useSpring(
|
|
40
46
|
target: number | SharedValue<number>,
|
|
41
47
|
config?: SpringTransition | TransitionName,
|
|
42
48
|
): SharedValue<number> {
|
|
43
49
|
const spring = resolveSpringInput(config, useNamedTransitions())
|
|
50
|
+
const shouldReduceMotion = useShouldReduceMotion()
|
|
44
51
|
// Reanimated config is rebuilt only when the public config object changes
|
|
45
52
|
// shape. The worklet path reads this from JS-thread closure capture, which
|
|
46
53
|
// is fine: it's the resolved config that's invariant across UI-thread
|
|
@@ -52,14 +59,7 @@ export function useSpring(
|
|
|
52
59
|
// depending on `config` itself would rebuild the Reanimated config on
|
|
53
60
|
// every render and defeat the memo.
|
|
54
61
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
55
|
-
[
|
|
56
|
-
spring?.tension,
|
|
57
|
-
spring?.friction,
|
|
58
|
-
spring?.mass,
|
|
59
|
-
spring?.velocity,
|
|
60
|
-
spring?.restSpeedThreshold,
|
|
61
|
-
spring?.restDisplacementThreshold,
|
|
62
|
-
],
|
|
62
|
+
[spring?.tension, spring?.friction, spring?.mass, spring?.velocity],
|
|
63
63
|
)
|
|
64
64
|
|
|
65
65
|
const isSharedTarget = isSharedValue(target)
|
|
@@ -72,28 +72,38 @@ export function useSpring(
|
|
|
72
72
|
// a stale closure.
|
|
73
73
|
useEffect(() => {
|
|
74
74
|
if (isSharedTarget) return
|
|
75
|
-
output.value =
|
|
75
|
+
output.value = shouldReduceMotion
|
|
76
|
+
? (target as number)
|
|
77
|
+
: withSpring(target as number, reanimConfig)
|
|
76
78
|
// `output` is identity-stable per hook instance (Reanimated guarantee).
|
|
77
79
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
78
|
-
}, [isSharedTarget, target, reanimConfig])
|
|
80
|
+
}, [isSharedTarget, target, reanimConfig, shouldReduceMotion])
|
|
79
81
|
|
|
80
82
|
// SharedValue path. `useAnimatedReaction` runs the prepare worklet whenever
|
|
81
83
|
// its returned value changes; we read `.value` off the target SV and pipe
|
|
82
84
|
// it through `withSpring` on the UI thread. When the target is a plain
|
|
83
85
|
// number we never declare a source so the reaction is inert (returns
|
|
84
86
|
// `null`, never fires `react`).
|
|
87
|
+
//
|
|
88
|
+
// `source` is in the dependency list on purpose. An explicit list replaces
|
|
89
|
+
// Reanimated's closure-derived one, so a caller that swaps which shared
|
|
90
|
+
// value drives the spring would otherwise keep the reaction wired to the
|
|
91
|
+
// old one — the same stale-closure class `useColorCascade` fixed in 0.0.4.
|
|
92
|
+
// A plain-number target maps to `null`, so a changing number does not
|
|
93
|
+
// re-register the inert reaction.
|
|
94
|
+
const source = isSharedTarget ? target : null
|
|
85
95
|
useAnimatedReaction(
|
|
86
96
|
() => {
|
|
87
97
|
'worklet'
|
|
88
|
-
if (
|
|
89
|
-
return
|
|
98
|
+
if (source === null) return null
|
|
99
|
+
return source.value
|
|
90
100
|
},
|
|
91
101
|
(next, prev) => {
|
|
92
102
|
'worklet'
|
|
93
103
|
if (next === null || next === prev) return
|
|
94
|
-
output.value = withSpring(next, reanimConfig)
|
|
104
|
+
output.value = shouldReduceMotion ? next : withSpring(next, reanimConfig)
|
|
95
105
|
},
|
|
96
|
-
[
|
|
106
|
+
[source, reanimConfig, shouldReduceMotion],
|
|
97
107
|
)
|
|
98
108
|
|
|
99
109
|
// Stop the in-flight spring when the owning component unmounts so its
|
|
@@ -122,14 +132,13 @@ function resolveSpringInput(
|
|
|
122
132
|
if (typeof config !== 'string') return config
|
|
123
133
|
const cfg = lookupNamedTransition(config, registry)
|
|
124
134
|
if (cfg.type === undefined || cfg.type === 'spring') return cfg
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
135
|
+
warnOnce(
|
|
136
|
+
`spring-only:${config}`,
|
|
137
|
+
`[inertia] Named transition "${config}" resolves to type ` +
|
|
138
|
+
`'${cfg.type}', but useSpring / useBooleanSpring are spring-only — ` +
|
|
139
|
+
`falling back to the default spring. Use useAnimation to honor ` +
|
|
140
|
+
`non-spring named transitions.`,
|
|
141
|
+
)
|
|
133
142
|
return undefined
|
|
134
143
|
}
|
|
135
144
|
|
|
@@ -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,47 @@
|
|
|
1
|
+
import type { ViewStyle } from 'react-native'
|
|
2
|
+
import { useAnimatedStyle, type SharedValue } from 'react-native-reanimated'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* What {@link useTranslateStyle} returns: a plain style object that owns
|
|
6
|
+
* `transform`.
|
|
7
|
+
*
|
|
8
|
+
* Deliberately **not** `ReturnType<typeof useAnimatedStyle>`. Reanimated 4.5
|
|
9
|
+
* brands that value (`AnimatedStyleHandle`), and a branded type is rejected
|
|
10
|
+
* inside a `StyleProp<ViewStyle>` array — so every call site would need a cast,
|
|
11
|
+
* which is the exact defect `InterpolatedStyle` was introduced to remove in
|
|
12
|
+
* `0.0.9`. The brand is compile-time only, so the runtime value is unchanged:
|
|
13
|
+
* it is still the animated style Reanimated produced.
|
|
14
|
+
*/
|
|
15
|
+
export type TranslateStyle = {
|
|
16
|
+
transform: NonNullable<ViewStyle['transform']>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Animated style that translates by two shared values:
|
|
21
|
+
* `transform: [{ translateX: x }, { translateY: y }]`.
|
|
22
|
+
*
|
|
23
|
+
* This is the style fragment every drag-style hook returns (`useTouchDrag`,
|
|
24
|
+
* and `useDrag` / `usePan` / `useSwipe` in `@rootnative/inertia-gestures`).
|
|
25
|
+
* Use it directly when a custom gesture owns its own translation values.
|
|
26
|
+
*
|
|
27
|
+
* The style owns the whole `transform` key. Do not stack a second transform
|
|
28
|
+
* style beside it — `transform` is one key in React Native, so the later
|
|
29
|
+
* style replaces this one instead of merging. Nest another animated view, or
|
|
30
|
+
* build one style from `x` / `y` with `useInterpolatedStyle`, to add a
|
|
31
|
+
* transform.
|
|
32
|
+
*
|
|
33
|
+
* ```tsx
|
|
34
|
+
* const x = useMotionValue(0)
|
|
35
|
+
* const y = useMotionValue(0)
|
|
36
|
+
* const style = useTranslateStyle(x, y)
|
|
37
|
+
* return <Motion.View style={style} />
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export function useTranslateStyle(
|
|
41
|
+
x: SharedValue<number>,
|
|
42
|
+
y: SharedValue<number>,
|
|
43
|
+
): TranslateStyle {
|
|
44
|
+
return useAnimatedStyle(() => ({
|
|
45
|
+
transform: [{ translateX: x.value }, { translateY: y.value }],
|
|
46
|
+
})) as unknown as TranslateStyle
|
|
47
|
+
}
|
package/dist/chunk-24NUL23E.js
DELETED
package/dist/chunk-4XBX7KOD.js
DELETED
package/dist/chunk-Z5USXWTE.js
DELETED