@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.
- package/CHANGELOG.md +10 -0
- package/README.md +2 -0
- package/dist/gestureLayer/index.d.mts +6 -5
- package/dist/gestureLayer/index.d.ts +6 -5
- package/dist/gestureLayer/index.js +89 -27
- package/dist/gestureLayer/index.js.map +1 -1
- package/dist/gestureLayer/index.mjs +89 -27
- package/dist/gestureLayer/index.mjs.map +1 -1
- package/dist/index.d.mts +127 -16
- package/dist/index.d.ts +127 -16
- package/dist/index.js +177 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +175 -61
- package/dist/index.mjs.map +1 -1
- package/dist/motion/Image.d.mts +1 -1
- package/dist/motion/Image.d.ts +1 -1
- package/dist/motion/Image.js +90 -48
- package/dist/motion/Image.js.map +1 -1
- package/dist/motion/Image.mjs +90 -48
- package/dist/motion/Image.mjs.map +1 -1
- package/dist/motion/Pressable.d.mts +1 -1
- package/dist/motion/Pressable.d.ts +1 -1
- package/dist/motion/Pressable.js +90 -48
- package/dist/motion/Pressable.js.map +1 -1
- package/dist/motion/Pressable.mjs +90 -48
- package/dist/motion/Pressable.mjs.map +1 -1
- package/dist/motion/ScrollView.d.mts +1 -1
- package/dist/motion/ScrollView.d.ts +1 -1
- package/dist/motion/ScrollView.js +90 -48
- package/dist/motion/ScrollView.js.map +1 -1
- package/dist/motion/ScrollView.mjs +90 -48
- package/dist/motion/ScrollView.mjs.map +1 -1
- package/dist/motion/Text.d.mts +1 -1
- package/dist/motion/Text.d.ts +1 -1
- package/dist/motion/Text.js +90 -48
- package/dist/motion/Text.js.map +1 -1
- package/dist/motion/Text.mjs +90 -48
- package/dist/motion/Text.mjs.map +1 -1
- package/dist/motion/View.d.mts +1 -1
- package/dist/motion/View.d.ts +1 -1
- package/dist/motion/View.js +90 -48
- package/dist/motion/View.js.map +1 -1
- package/dist/motion/View.mjs +90 -48
- package/dist/motion/View.mjs.map +1 -1
- package/dist/touch/index.d.mts +1 -1
- package/dist/touch/index.d.ts +1 -1
- package/dist/{types-cU43dEmH.d.mts → types-BzEgiUdJ.d.mts} +58 -9
- package/dist/{types-cU43dEmH.d.ts → types-BzEgiUdJ.d.ts} +58 -9
- package/dist/{useGesture-BnY65PlQ.d.ts → useGesture-BRLgiNOC.d.ts} +6 -4
- package/dist/{useGesture-DxtXdz-K.d.mts → useGesture-C0GBS7d2.d.mts} +6 -4
- package/llms.txt +8 -4
- package/package.json +1 -1
- package/src/__type-tests__/motion-value.test-d.ts +39 -0
- package/src/config/MotionConfig.tsx +55 -9
- package/src/config/MotionConfigContext.ts +21 -1
- package/src/config/index.ts +7 -1
- package/src/config/namedTransitions.ts +80 -0
- package/src/gestureLayer/useGestureLayer.ts +32 -8
- package/src/index.ts +20 -2
- package/src/motion/createMotionComponent.tsx +36 -6
- package/src/transitions/cubicBezier.ts +126 -0
- package/src/transitions/index.ts +1 -0
- package/src/types.ts +63 -8
- package/src/values/useAnimation.ts +12 -6
- package/src/values/useBooleanSpring.ts +5 -3
- package/src/values/useGesture.ts +25 -7
- package/src/values/useMotionValue.ts +11 -0
- package/src/values/useScroll.ts +8 -1
- package/src/values/useSpring.ts +46 -9
package/src/values/useSpring.ts
CHANGED
|
@@ -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 {
|
|
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(
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|