@rootnative/inertia 0.0.0-alpha.0
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 +33 -0
- package/LICENSE +21 -0
- package/README.md +131 -0
- package/dist/gestureLayer/index.d.mts +119 -0
- package/dist/gestureLayer/index.d.ts +119 -0
- package/dist/gestureLayer/index.js +346 -0
- package/dist/gestureLayer/index.js.map +1 -0
- package/dist/gestureLayer/index.mjs +344 -0
- package/dist/gestureLayer/index.mjs.map +1 -0
- package/dist/index.d.mts +507 -0
- package/dist/index.d.ts +507 -0
- package/dist/index.js +1546 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1515 -0
- package/dist/index.mjs.map +1 -0
- package/dist/motion/Image.d.mts +12 -0
- package/dist/motion/Image.d.ts +12 -0
- package/dist/motion/Image.js +1138 -0
- package/dist/motion/Image.js.map +1 -0
- package/dist/motion/Image.mjs +1132 -0
- package/dist/motion/Image.mjs.map +1 -0
- package/dist/motion/Pressable.d.mts +15 -0
- package/dist/motion/Pressable.d.ts +15 -0
- package/dist/motion/Pressable.js +1138 -0
- package/dist/motion/Pressable.js.map +1 -0
- package/dist/motion/Pressable.mjs +1132 -0
- package/dist/motion/Pressable.mjs.map +1 -0
- package/dist/motion/ScrollView.d.mts +12 -0
- package/dist/motion/ScrollView.d.ts +12 -0
- package/dist/motion/ScrollView.js +1138 -0
- package/dist/motion/ScrollView.js.map +1 -0
- package/dist/motion/ScrollView.mjs +1132 -0
- package/dist/motion/ScrollView.mjs.map +1 -0
- package/dist/motion/Text.d.mts +11 -0
- package/dist/motion/Text.d.ts +11 -0
- package/dist/motion/Text.js +1138 -0
- package/dist/motion/Text.js.map +1 -0
- package/dist/motion/Text.mjs +1132 -0
- package/dist/motion/Text.mjs.map +1 -0
- package/dist/motion/View.d.mts +11 -0
- package/dist/motion/View.d.ts +11 -0
- package/dist/motion/View.js +1138 -0
- package/dist/motion/View.js.map +1 -0
- package/dist/motion/View.mjs +1132 -0
- package/dist/motion/View.mjs.map +1 -0
- package/dist/testing/index.d.mts +57 -0
- package/dist/testing/index.d.ts +57 -0
- package/dist/testing/index.js +19 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/index.mjs +16 -0
- package/dist/testing/index.mjs.map +1 -0
- package/dist/touch/index.d.mts +146 -0
- package/dist/touch/index.d.ts +146 -0
- package/dist/touch/index.js +166 -0
- package/dist/touch/index.js.map +1 -0
- package/dist/touch/index.mjs +164 -0
- package/dist/touch/index.mjs.map +1 -0
- package/dist/types-cU43dEmH.d.mts +339 -0
- package/dist/types-cU43dEmH.d.ts +339 -0
- package/dist/useGesture-BnY65PlQ.d.ts +84 -0
- package/dist/useGesture-DxtXdz-K.d.mts +84 -0
- package/jest-preset.js +33 -0
- package/jest-setup.js +213 -0
- package/llms.txt +142 -0
- package/package.json +151 -0
- package/src/__type-tests__/animate.test-d.tsx +88 -0
- package/src/__type-tests__/variants.test-d.tsx +67 -0
- package/src/config/MotionConfig.tsx +30 -0
- package/src/config/MotionConfigContext.ts +53 -0
- package/src/config/index.ts +9 -0
- package/src/gestureLayer/index.ts +21 -0
- package/src/gestureLayer/useGestureLayer.ts +285 -0
- package/src/gestures/focusVisibility.ts +61 -0
- package/src/gestures/index.ts +1 -0
- package/src/index.ts +72 -0
- package/src/layout/index.ts +16 -0
- package/src/layout/resolveLayout.ts +54 -0
- package/src/layout/sharedRegistry.ts +111 -0
- package/src/layout/useSharedLayout.ts +289 -0
- package/src/motion/Image.tsx +9 -0
- package/src/motion/Pressable.tsx +12 -0
- package/src/motion/ScrollView.tsx +9 -0
- package/src/motion/Text.tsx +8 -0
- package/src/motion/View.tsx +8 -0
- package/src/motion/createMotionComponent.tsx +1306 -0
- package/src/motion/index.ts +26 -0
- package/src/motion/installCheck.ts +65 -0
- package/src/presence/Presence.tsx +165 -0
- package/src/presence/PresenceContext.ts +28 -0
- package/src/presence/index.ts +6 -0
- package/src/testing/index.ts +78 -0
- package/src/touch/index.ts +18 -0
- package/src/touch/useTouchDrag.ts +289 -0
- package/src/transitions/easing.ts +53 -0
- package/src/transitions/index.ts +7 -0
- package/src/transitions/keys.ts +32 -0
- package/src/transitions/resolve.ts +169 -0
- package/src/transitions/resolveSequence.ts +87 -0
- package/src/transitions/runtime.ts +63 -0
- package/src/transitions/sig.ts +40 -0
- package/src/transitions/spring.ts +42 -0
- package/src/types.ts +383 -0
- package/src/values/index.ts +26 -0
- package/src/values/useAnimation.ts +69 -0
- package/src/values/useBooleanSpring.ts +33 -0
- package/src/values/useColorTransition.ts +72 -0
- package/src/values/useGesture.ts +144 -0
- package/src/values/useMotionValue.ts +33 -0
- package/src/values/useScroll.ts +72 -0
- package/src/values/useShadow.ts +116 -0
- package/src/values/useSpring.ts +98 -0
- package/src/values/useTransform.ts +132 -0
- package/src/values/useVariants.ts +60 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentType, ReactNode } from 'react';
|
|
3
|
+
import * as react_native from 'react-native';
|
|
4
|
+
import { NativeSyntheticEvent, NativeScrollEvent } from 'react-native';
|
|
5
|
+
import { M as MotionComponent, T as TransitionConfig, A as AnimatableValue, E as EasingInput, S as SpringTransition, V as VariantController } from './types-cU43dEmH.js';
|
|
6
|
+
export { a as AnimateStyle, b as AnimationCallbackInfo, D as DecayTransition, G as GestureSubStates, c as MotionProps, N as NoAnimationTransition, P as PerPropertyTransition, R as RepeatConfig, d as SequenceStep, e as TimingTransition, f as Transition, g as VariantsMap } from './types-cU43dEmH.js';
|
|
7
|
+
import { SharedValue, useAnimatedStyle } from 'react-native-reanimated';
|
|
8
|
+
export { U as UseGestureHandlers, a as UseGestureResult, u as useGesture } from './useGesture-BnY65PlQ.js';
|
|
9
|
+
export { MotionImage } from './motion/Image.js';
|
|
10
|
+
export { MotionPressable } from './motion/Pressable.js';
|
|
11
|
+
export { MotionScrollView } from './motion/ScrollView.js';
|
|
12
|
+
export { MotionText } from './motion/Text.js';
|
|
13
|
+
export { MotionView } from './motion/View.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Factory that wraps a React Native primitive as a `Motion.*` component.
|
|
17
|
+
*
|
|
18
|
+
* The generic `C` flows through `MotionProps`, so `animate` / `initial` /
|
|
19
|
+
* `exit` / `transition` all infer from `C`'s `style` prop. There is no
|
|
20
|
+
* shared `ViewStyle & TextStyle & ImageStyle` fallback.
|
|
21
|
+
*
|
|
22
|
+
* Alpha scope: numeric properties (transforms, opacity, width, height,
|
|
23
|
+
* borderRadius) and color properties (backgroundColor, borderColor, color,
|
|
24
|
+
* tintColor) applied via Reanimated shared values + `useAnimatedStyle`.
|
|
25
|
+
*/
|
|
26
|
+
declare function createMotionComponent<C extends ComponentType<any>>(Component: C): MotionComponent<C>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The `Motion.*` namespace. Each property is a primitive with its style prop
|
|
30
|
+
* inferred from the underlying RN component. There is no shared style fallback.
|
|
31
|
+
*/
|
|
32
|
+
declare const Motion: {
|
|
33
|
+
readonly View: MotionComponent<typeof react_native.View>;
|
|
34
|
+
readonly Text: MotionComponent<typeof react_native.Text>;
|
|
35
|
+
readonly Image: MotionComponent<typeof react_native.Image>;
|
|
36
|
+
readonly Pressable: MotionComponent<react.ForwardRefExoticComponent<react_native.PressableProps & react.RefAttributes<react_native.View>>>;
|
|
37
|
+
readonly ScrollView: MotionComponent<typeof react_native.ScrollView>;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* How descendant Motion primitives should treat reduced-motion preferences.
|
|
42
|
+
*
|
|
43
|
+
* - `'user'` (default): defer to the OS accessibility setting via
|
|
44
|
+
* Reanimated's `useReducedMotion()`. This is the only value that respects
|
|
45
|
+
* user choice and is the right default for app-level wrappers.
|
|
46
|
+
* - `'never'`: animate regardless of OS setting. Use sparingly — e.g. for
|
|
47
|
+
* onboarding transitions you've decided are essential.
|
|
48
|
+
* - `'always'`: never animate, regardless of OS setting. Useful for tests
|
|
49
|
+
* and snapshots.
|
|
50
|
+
*/
|
|
51
|
+
type ReducedMotion = 'user' | 'never' | 'always';
|
|
52
|
+
interface MotionConfigValue {
|
|
53
|
+
reducedMotion: ReducedMotion;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Read the active `<MotionConfig>` from a descendant. Returns the default
|
|
57
|
+
* (`'user'`) when no provider is present.
|
|
58
|
+
*/
|
|
59
|
+
declare function useMotionConfig(): MotionConfigValue;
|
|
60
|
+
/**
|
|
61
|
+
* Resolve the active reduced-motion mode to a boolean. `'user'` consults
|
|
62
|
+
* Reanimated's OS-backed hook; `'always'` / `'never'` shortcut. Motion
|
|
63
|
+
* primitives call this to decide whether to swap transitions for
|
|
64
|
+
* `no-animation`.
|
|
65
|
+
*/
|
|
66
|
+
declare function useShouldReduceMotion(): boolean;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Provider that controls how descendant Motion primitives respond to
|
|
70
|
+
* reduced-motion preferences. Wrap the root of your app once with the
|
|
71
|
+
* default (`reducedMotion="user"`) to respect the OS accessibility setting,
|
|
72
|
+
* or scope a subtree with `'always'` / `'never'` for specific use cases.
|
|
73
|
+
*/
|
|
74
|
+
declare function MotionConfig({ reducedMotion, children, }: {
|
|
75
|
+
reducedMotion?: ReducedMotion;
|
|
76
|
+
children: ReactNode;
|
|
77
|
+
}): react.JSX.Element;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Wrap a list of children with mount / unmount transitions. When a child is
|
|
81
|
+
* removed from the incoming list it stays in the snapshot until its exit
|
|
82
|
+
* animation completes; descendants consume the per-child `<PresenceContext>`
|
|
83
|
+
* to coordinate.
|
|
84
|
+
*
|
|
85
|
+
* Children must be `<Motion.*>` primitives (or any component that consumes
|
|
86
|
+
* `usePresence()` and calls `safeToRemove`). Plain elements without that
|
|
87
|
+
* contract will linger in the snapshot once removed; document that and pick
|
|
88
|
+
* the right primitive.
|
|
89
|
+
*
|
|
90
|
+
* Children also need explicit `key`s so removal is detectable across
|
|
91
|
+
* renders. Without a key, React falls back to positional identity and
|
|
92
|
+
* removal looks like a prop change — Presence has nothing to mark exiting.
|
|
93
|
+
*/
|
|
94
|
+
declare function Presence({ children }: {
|
|
95
|
+
children: ReactNode;
|
|
96
|
+
}): react.JSX.Element;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Per-child contract between `<Presence>` and its descendant Motion
|
|
100
|
+
* primitives. `<Presence>` provides a fresh value to each rendered child;
|
|
101
|
+
* Motion primitives consume it to gate exit animations.
|
|
102
|
+
*
|
|
103
|
+
* - `isPresent`: `true` while the child is in the incoming children list.
|
|
104
|
+
* Flips to `false` when the parent removes it; the child remains rendered
|
|
105
|
+
* until `safeToRemove` is called.
|
|
106
|
+
* - `safeToRemove`: callback the child invokes when its exit animation has
|
|
107
|
+
* settled. `<Presence>` then drops the snapshot entry and unmounts.
|
|
108
|
+
*/
|
|
109
|
+
interface PresenceContextValue {
|
|
110
|
+
isPresent: boolean;
|
|
111
|
+
safeToRemove: () => void;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Read the surrounding `<Presence>` contract from a child component. Returns
|
|
115
|
+
* `null` when there is no `<Presence>` ancestor — useful for components that
|
|
116
|
+
* want to support both standalone and Presence-wrapped use without branching.
|
|
117
|
+
*/
|
|
118
|
+
declare function usePresence(): PresenceContextValue | null;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* UI-thread callback Reanimated invokes when an animation settles. Must be a
|
|
122
|
+
* worklet — callers either author one with `'worklet'` or build one via
|
|
123
|
+
* `runOnJS(...)` to bridge to JS-thread code.
|
|
124
|
+
*/
|
|
125
|
+
type AnimationCallback = (finished?: boolean, current?: number | string) => void;
|
|
126
|
+
/**
|
|
127
|
+
* Per-step callback factory. Resolvers call this with the step's phase and
|
|
128
|
+
* sequence index (or `undefined` for non-sequence animations) and attach the
|
|
129
|
+
* resulting callback to the underlying `withSpring` / `withTiming` /
|
|
130
|
+
* `withDecay` call.
|
|
131
|
+
*/
|
|
132
|
+
type CallbackFactory = (phase: 'step' | 'animation', step: number | undefined) => AnimationCallback | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* Build a Reanimated animation for a single property. Runs on the JS thread
|
|
135
|
+
* once per change and produces a baked `withSpring` / `withTiming` /
|
|
136
|
+
* `withDecay` (optionally wrapped in `withDelay` / `withRepeat`) call. The
|
|
137
|
+
* worklet body only consumes the result.
|
|
138
|
+
*
|
|
139
|
+
* `callback`, when provided, fires once when the underlying single-shot
|
|
140
|
+
* animation settles. Repeat-wrapped animations forward the callback to
|
|
141
|
+
* `withRepeat`, so it fires once per iteration as Reanimated does.
|
|
142
|
+
*/
|
|
143
|
+
declare function resolveTransition(config: TransitionConfig | undefined, toValue: number | string, callback?: AnimationCallback): unknown;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Resolve a per-property `animate` value into a Reanimated animation.
|
|
147
|
+
*
|
|
148
|
+
* Handles the three shapes of `AnimatableValue`:
|
|
149
|
+
* 1. plain value → single `resolveTransition` call
|
|
150
|
+
* 2. `{ to, ...over }` → single step with the override merged into `base`
|
|
151
|
+
* 3. array of either → `withSequence` of resolved steps, with the
|
|
152
|
+
* top-level `repeat` applied at the **sequence level** (not per step).
|
|
153
|
+
* Per-step `repeat` overrides remain step-local.
|
|
154
|
+
*/
|
|
155
|
+
declare function resolveAnimatableValue<V extends number | string>(value: AnimatableValue<V>, base: TransitionConfig | undefined, factory?: CallbackFactory): unknown;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Reanimated 3.9+ validates that easing functions used in nested-transition
|
|
159
|
+
* contexts (variants, sequences, per-property maps) are worklets, and crashes
|
|
160
|
+
* with `[Reanimated] The easing function is not a worklet` otherwise. The
|
|
161
|
+
* library accepts plain functions on the public surface; this helper wraps
|
|
162
|
+
* them so consumers don't have to think about the worklet boundary.
|
|
163
|
+
*
|
|
164
|
+
* If the input is already a worklet (has been processed by the worklets babel
|
|
165
|
+
* plugin), it's returned as-is. Otherwise it's wrapped in a function whose
|
|
166
|
+
* body declares the `'worklet'` directive — when our source is processed by
|
|
167
|
+
* the consumer's worklets babel plugin (the default Expo/RN setup), the
|
|
168
|
+
* wrapper becomes a real worklet that captures the user fn via closure.
|
|
169
|
+
*
|
|
170
|
+
* Reanimated 4 changed `Easing.bezier(...)` to return an
|
|
171
|
+
* `EasingFunctionFactory` (`{ factory: () => EasingFunction }`) rather than
|
|
172
|
+
* the function itself. The helper accepts both shapes — `EasingFunction` and
|
|
173
|
+
* `EasingFunctionFactory` — and unwraps the factory automatically so
|
|
174
|
+
* consumers don't have to call `.factory()` manually.
|
|
175
|
+
*
|
|
176
|
+
* The user fn must be pure: no JS-thread captured refs, no shared mutable
|
|
177
|
+
* state, no calls to non-worklet APIs.
|
|
178
|
+
*/
|
|
179
|
+
declare function ensureWorkletEasing(easing: EasingInput | undefined): ((t: number) => number) | undefined;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Worklet-safe single-step animation builder. Mirrors a subset of
|
|
183
|
+
* `resolveTransition` for the UI-thread path where the transition config is
|
|
184
|
+
* picked at gesture-release time, not at render time.
|
|
185
|
+
*
|
|
186
|
+
* Supported: spring / timing / decay / no-animation, single-step only.
|
|
187
|
+
* Not supported: sequences, top-level repeat, easing-function
|
|
188
|
+
* auto-worklet-wrapping (pass an already-worklet easing if you need a custom
|
|
189
|
+
* one — most release transitions don't).
|
|
190
|
+
*
|
|
191
|
+
* Use this from gesture worklets (`useDrag` / `usePan` release callbacks, or
|
|
192
|
+
* any custom `Gesture.Pan().onEnd(() => ...)` worklet) to animate a shared
|
|
193
|
+
* value with an Inertia transition without the JS round-trip that would lose
|
|
194
|
+
* the release velocity.
|
|
195
|
+
*
|
|
196
|
+
* For decay transitions, `toValue` is ignored — decay decelerates from the
|
|
197
|
+
* SV's current position via its own physics. Pass `0` if you don't have one.
|
|
198
|
+
*/
|
|
199
|
+
declare function buildReleaseAnimation(transition: TransitionConfig, toValue: number): unknown;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Drive a `SharedValue<number>` toward `target` with **any** transition shape
|
|
203
|
+
* — spring, timing, decay, or no-animation. The general-purpose value-layer
|
|
204
|
+
* hook: reach for it when you need raw `useSharedValue + useEffect + withX`
|
|
205
|
+
* outside the declarative `animate` flow.
|
|
206
|
+
*
|
|
207
|
+
* Re-runs whenever `target` changes shape (`target` is in the dep array) or
|
|
208
|
+
* the transition signature changes (kept stable via JSON-style hashing).
|
|
209
|
+
* Reduced motion (via `<MotionConfig reducedMotion>`) collapses the
|
|
210
|
+
* transition to `no-animation` so the value snaps instead of interpolating.
|
|
211
|
+
*
|
|
212
|
+
* **Spring shorthand.** Prefer [`useSpring`](./useSpring) when you only want
|
|
213
|
+
* spring physics — it accepts the same `tension`/`friction`/`mass` config and
|
|
214
|
+
* also supports a `SharedValue<number>` as the target (UI-thread reactive
|
|
215
|
+
* source). `useAnimation` is JS-thread-driven only.
|
|
216
|
+
*
|
|
217
|
+
* **Loops.** Repeat is part of `TransitionConfig` and flows through
|
|
218
|
+
* untouched — `useAnimation(1, { type: 'timing', duration: 1800, repeat: {
|
|
219
|
+
* count: 'infinite', alternate: false } })` produces an indeterminate-style
|
|
220
|
+
* progress driver.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* // Toggle progress (Switch / Checkbox / Radio).
|
|
225
|
+
* const progress = useAnimation(isChecked ? 1 : 0, {
|
|
226
|
+
* type: 'spring',
|
|
227
|
+
* tension: 380,
|
|
228
|
+
* friction: 33,
|
|
229
|
+
* })
|
|
230
|
+
*
|
|
231
|
+
* // Float a TextField label when the value becomes non-empty.
|
|
232
|
+
* const floated = useAnimation(hasValue ? 1 : 0, {
|
|
233
|
+
* type: 'timing',
|
|
234
|
+
* duration: 150,
|
|
235
|
+
* })
|
|
236
|
+
*
|
|
237
|
+
* // Indeterminate progress slider (loops forever, snaps back).
|
|
238
|
+
* const slide = useAnimation(1, {
|
|
239
|
+
* type: 'timing',
|
|
240
|
+
* duration: 1800,
|
|
241
|
+
* repeat: { count: 'infinite', alternate: false },
|
|
242
|
+
* })
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
declare function useAnimation(target: number, transition?: TransitionConfig): SharedValue<number>;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Toggle a 0↔1 progress value with a spring whenever `active` flips.
|
|
249
|
+
*
|
|
250
|
+
* This is the recurring shape behind checkbox checks, accordion expansions,
|
|
251
|
+
* drawer open/closed states, focus rings, and every other binary UI flip
|
|
252
|
+
* that wants spring physics rather than a hard cut. The returned shared
|
|
253
|
+
* value sits at `0` when `active` is `false` and animates toward `1` when
|
|
254
|
+
* `active` flips to `true` (and back again on the reverse flip). Feed it to
|
|
255
|
+
* a `useTransform`, `useShadow`, or a hand-rolled `useAnimatedStyle` to
|
|
256
|
+
* drive whatever the boolean controls visually.
|
|
257
|
+
*
|
|
258
|
+
* ```tsx
|
|
259
|
+
* const progress = useBooleanSpring(isChecked)
|
|
260
|
+
* const indicatorStyle = useAnimatedStyle(() => ({
|
|
261
|
+
* opacity: progress.value,
|
|
262
|
+
* transform: [{ scale: progress.value }],
|
|
263
|
+
* }))
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
266
|
+
* The spring config follows the same react-spring vocabulary as the rest of
|
|
267
|
+
* the library (`tension` / `friction` / `mass`); omit it to take the
|
|
268
|
+
* library's defaults.
|
|
269
|
+
*/
|
|
270
|
+
declare function useBooleanSpring(active: boolean, springConfig?: SpringTransition): SharedValue<number>;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Color style keys understood by React Native that this hook can target.
|
|
274
|
+
* Sticks to the keys that exist on the v0.1 animatable surface so the
|
|
275
|
+
* returned style fragment is always a legal RN style.
|
|
276
|
+
*/
|
|
277
|
+
type ColorStyleKey = 'backgroundColor' | 'color' | 'borderColor' | 'borderTopColor' | 'borderRightColor' | 'borderBottomColor' | 'borderLeftColor' | 'tintColor' | 'shadowColor';
|
|
278
|
+
interface UseColorTransitionOptions {
|
|
279
|
+
/**
|
|
280
|
+
* Which style slot the interpolated color is emitted under. Defaults to
|
|
281
|
+
* `backgroundColor` — the dominant case for state-layer haloes, card
|
|
282
|
+
* fills, and chip surfaces. Override for ring colors (`borderColor`),
|
|
283
|
+
* text colors (`color`), image tints (`tintColor`), etc.
|
|
284
|
+
*/
|
|
285
|
+
key?: ColorStyleKey;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Interpolate a single color channel between `from` and `to` as `progress`
|
|
289
|
+
* moves 0→1, returning an animated style fragment that can be spread onto
|
|
290
|
+
* any Reanimated-aware view.
|
|
291
|
+
*
|
|
292
|
+
* ```tsx
|
|
293
|
+
* const progress = useBooleanSpring(isPressed)
|
|
294
|
+
* const fillStyle = useColorTransition(progress, [colors.surface, colors.pressed])
|
|
295
|
+
* const ringStyle = useColorTransition(progress, [colors.outline, colors.primary], {
|
|
296
|
+
* key: 'borderColor',
|
|
297
|
+
* })
|
|
298
|
+
*
|
|
299
|
+
* return <Motion.View style={[styles.chip, fillStyle, ringStyle]} />
|
|
300
|
+
* ```
|
|
301
|
+
*
|
|
302
|
+
* This is a pure interpolator: it does not animate on its own. Drive
|
|
303
|
+
* `progress` upstream with a `useSpring`, `useBooleanSpring`, gesture
|
|
304
|
+
* progress, or scroll-derived `useTransform`. Values outside `[0, 1]`
|
|
305
|
+
* clamp. For a raw `SharedValue<string>` (e.g. to feed a gradient or
|
|
306
|
+
* compose into a hand-rolled `useAnimatedStyle`), use `useTransform`
|
|
307
|
+
* directly with a color output range.
|
|
308
|
+
*/
|
|
309
|
+
declare function useColorTransition(progress: SharedValue<number>, range: readonly [string, string], options?: UseColorTransitionOptions): ReturnType<typeof useAnimatedStyle>;
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Create an animatable value owned by JS but readable from worklets.
|
|
313
|
+
*
|
|
314
|
+
* This is the escape-hatch primitive that the rest of the value-layer hooks
|
|
315
|
+
* (`useSpring`, `useTransform`, `useScroll`) compose against. It is a thin
|
|
316
|
+
* pass-through over Reanimated's `useSharedValue`: a `SharedValue<T>` with
|
|
317
|
+
* `.value` for direct reads/writes (UI-thread reads in worklets, JS-thread
|
|
318
|
+
* writes from event handlers / effects).
|
|
319
|
+
*
|
|
320
|
+
* We intentionally do not introduce a `MotionValue` wrapper class around the
|
|
321
|
+
* shared value. The simplest object that interops with `useAnimatedStyle`,
|
|
322
|
+
* `useDerivedValue`, and every other Reanimated API _is_ the shared value
|
|
323
|
+
* itself; adding a `{ get, set, value }` shell would force consumers to
|
|
324
|
+
* unwrap it at every Reanimated boundary and break worklet capture.
|
|
325
|
+
*
|
|
326
|
+
* Worklet read:
|
|
327
|
+
* ```ts
|
|
328
|
+
* const x = useMotionValue(0)
|
|
329
|
+
* useAnimatedStyle(() => ({ transform: [{ translateX: x.value }] }))
|
|
330
|
+
* ```
|
|
331
|
+
*
|
|
332
|
+
* JS write:
|
|
333
|
+
* ```ts
|
|
334
|
+
* onPress={() => { x.value = 100 }}
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
declare function useMotionValue<T extends number | string>(initial: T): SharedValue<T>;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Animate a shared value toward `target` with spring physics, using the
|
|
341
|
+
* library's react-spring vocabulary (`tension` / `friction` / `mass`).
|
|
342
|
+
*
|
|
343
|
+
* `target` may be a plain number or a `SharedValue<number>`. The plain-number
|
|
344
|
+
* path drives the spring from a JS `useEffect`, so the animation re-runs on
|
|
345
|
+
* every render where `target` changes. The shared-value path drives the
|
|
346
|
+
* spring from a Reanimated reaction on the UI thread, so values produced by
|
|
347
|
+
* gestures, scroll handlers, or other worklets flow through without bouncing
|
|
348
|
+
* back to JS.
|
|
349
|
+
*
|
|
350
|
+
* Both call sites end up at the same `withSpring` invocation; the split is
|
|
351
|
+
* just about which thread observes the source change.
|
|
352
|
+
*/
|
|
353
|
+
declare function useSpring(target: number | SharedValue<number>, config?: SpringTransition): SharedValue<number>;
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Extrapolation behavior at the edges of the input range. Mirrors
|
|
357
|
+
* Reanimated's enum so consumers don't need a separate import.
|
|
358
|
+
*
|
|
359
|
+
* - `'clamp'` (default) — output stays pinned at the first/last value
|
|
360
|
+
* outside the input range. Matches Framer Motion's default.
|
|
361
|
+
* - `'identity'` — return the input unchanged outside the range.
|
|
362
|
+
* - `'extend'` — continue the linear slope beyond the range.
|
|
363
|
+
*/
|
|
364
|
+
type ExtrapolationMode = 'clamp' | 'identity' | 'extend';
|
|
365
|
+
interface UseTransformOptions {
|
|
366
|
+
extrapolateLeft?: ExtrapolationMode;
|
|
367
|
+
extrapolateRight?: ExtrapolationMode;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Derive a value from one or more shared values via a transformer worklet.
|
|
371
|
+
*
|
|
372
|
+
* ```ts
|
|
373
|
+
* const x = useMotionValue(0)
|
|
374
|
+
* const y = useMotionValue(0)
|
|
375
|
+
* const distance = useTransform(() => Math.sqrt(x.value ** 2 + y.value ** 2))
|
|
376
|
+
* ```
|
|
377
|
+
*
|
|
378
|
+
* The transformer must be a worklet (or a plain function we auto-wrap —
|
|
379
|
+
* see the easing wrapper for the rationale). It runs on the UI thread on
|
|
380
|
+
* every frame where any read shared value changes.
|
|
381
|
+
*/
|
|
382
|
+
declare function useTransform<T>(transformer: () => T): SharedValue<T>;
|
|
383
|
+
/**
|
|
384
|
+
* Interpolate a numeric shared value onto a range of numbers or colors.
|
|
385
|
+
*
|
|
386
|
+
* ```ts
|
|
387
|
+
* const scroll = useMotionValue(0)
|
|
388
|
+
* const headerOpacity = useTransform(scroll, [0, 100], [1, 0])
|
|
389
|
+
* const headerColor = useTransform(scroll, [0, 100], ['#fff', '#000'])
|
|
390
|
+
* ```
|
|
391
|
+
*
|
|
392
|
+
* When `outputRange` is numeric, this maps to Reanimated's `interpolate`;
|
|
393
|
+
* when it's a tuple of color strings, it maps to `interpolateColor`. The
|
|
394
|
+
* input range must be monotonically increasing.
|
|
395
|
+
*/
|
|
396
|
+
declare function useTransform(value: SharedValue<number>, inputRange: readonly number[], outputRange: readonly number[], options?: UseTransformOptions): SharedValue<number>;
|
|
397
|
+
declare function useTransform(value: SharedValue<number>, inputRange: readonly number[], outputRange: readonly string[], options?: UseTransformOptions): SharedValue<string>;
|
|
398
|
+
|
|
399
|
+
interface UseScrollResult {
|
|
400
|
+
/** Horizontal scroll offset in points. */
|
|
401
|
+
scrollX: SharedValue<number>;
|
|
402
|
+
/** Vertical scroll offset in points. */
|
|
403
|
+
scrollY: SharedValue<number>;
|
|
404
|
+
/**
|
|
405
|
+
* Handler to pass to a `Motion.ScrollView`'s `onScroll` prop (or any other
|
|
406
|
+
* Reanimated `Animated.ScrollView`). The handler is opaque to JS — it runs
|
|
407
|
+
* as a worklet — but the type narrows to the same shape RN's native
|
|
408
|
+
* `onScroll` prop expects so it composes cleanly.
|
|
409
|
+
*/
|
|
410
|
+
onScroll: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Track the scroll offset of a `Motion.ScrollView` as shared values.
|
|
414
|
+
*
|
|
415
|
+
* ```tsx
|
|
416
|
+
* const { scrollY, onScroll } = useScroll()
|
|
417
|
+
* const headerOpacity = useTransform(scrollY, [0, 100], [1, 0])
|
|
418
|
+
*
|
|
419
|
+
* return (
|
|
420
|
+
* <>
|
|
421
|
+
* <Motion.View animate={{ opacity: headerOpacity }} />
|
|
422
|
+
* <Motion.ScrollView onScroll={onScroll} scrollEventThrottle={16}>
|
|
423
|
+
* …
|
|
424
|
+
* </Motion.ScrollView>
|
|
425
|
+
* </>
|
|
426
|
+
* )
|
|
427
|
+
* ```
|
|
428
|
+
*
|
|
429
|
+
* Scroll events fire on the UI thread, so `scrollX` / `scrollY` are safe to
|
|
430
|
+
* read from any worklet (`useAnimatedStyle`, `useDerivedValue`,
|
|
431
|
+
* `useTransform`) without a JS-thread bounce.
|
|
432
|
+
*
|
|
433
|
+
* Remember to set `scrollEventThrottle={16}` on the `ScrollView` for 60Hz
|
|
434
|
+
* updates — RN's default is to dispatch on every event, which on iOS still
|
|
435
|
+
* means one per frame, but Android benefits from the explicit cap.
|
|
436
|
+
*/
|
|
437
|
+
declare function useScroll(): UseScrollResult;
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Shape accepted on either end of a `useShadow` tween. Every field is
|
|
441
|
+
* optional — only keys present on at least one side participate in the
|
|
442
|
+
* output style. Mirrors the flat shadow keys on `Motion.View`'s `animate`
|
|
443
|
+
* surface, plus the nested `shadowOffset` source.
|
|
444
|
+
*/
|
|
445
|
+
interface ShadowConfig {
|
|
446
|
+
shadowOpacity?: number;
|
|
447
|
+
shadowRadius?: number;
|
|
448
|
+
shadowOffset?: {
|
|
449
|
+
width?: number;
|
|
450
|
+
height?: number;
|
|
451
|
+
};
|
|
452
|
+
/** Android elevation. iOS shadow consumers can leave this off. */
|
|
453
|
+
elevation?: number;
|
|
454
|
+
shadowColor?: string;
|
|
455
|
+
}
|
|
456
|
+
interface UseShadowOptions {
|
|
457
|
+
/** Shadow state at `progress === 0`. */
|
|
458
|
+
from: ShadowConfig;
|
|
459
|
+
/** Shadow state at `progress === 1`. */
|
|
460
|
+
to: ShadowConfig;
|
|
461
|
+
/**
|
|
462
|
+
* Driver — typically 0→1. Whatever produces it (a `useSpring`, a gesture
|
|
463
|
+
* progress value, a scroll-derived `useTransform`) is the caller's
|
|
464
|
+
* concern. The hook is a pure interpolator; it does not animate on its
|
|
465
|
+
* own. Values outside `[0, 1]` clamp.
|
|
466
|
+
*/
|
|
467
|
+
progress: SharedValue<number>;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Interpolate between two shadow configs as `progress` moves 0→1, returning
|
|
471
|
+
* an animated style fragment that can be spread onto any Reanimated-aware
|
|
472
|
+
* view (including `Motion.*` primitives and a hand-rolled `Animated.View`).
|
|
473
|
+
*
|
|
474
|
+
* ```tsx
|
|
475
|
+
* const progress = useSpring(isElevated ? 1 : 0)
|
|
476
|
+
* const shadowStyle = useShadow({
|
|
477
|
+
* from: { shadowOpacity: 0.08, shadowRadius: 2, shadowOffset: { width: 0, height: 1 }, elevation: 1 },
|
|
478
|
+
* to: { shadowOpacity: 0.24, shadowRadius: 12, shadowOffset: { width: 0, height: 8 }, elevation: 8 },
|
|
479
|
+
* progress,
|
|
480
|
+
* })
|
|
481
|
+
*
|
|
482
|
+
* return <Motion.View style={[styles.card, shadowStyle]} />
|
|
483
|
+
* ```
|
|
484
|
+
*
|
|
485
|
+
* Only keys present on either `from` or `to` are emitted. A key present on
|
|
486
|
+
* one side and absent on the other tweens from the present value to the
|
|
487
|
+
* absent side's natural zero (`0` for numbers, `'transparent'` for
|
|
488
|
+
* `shadowColor`, `{ width: 0, height: 0 }` for `shadowOffset`). This is a
|
|
489
|
+
* pure interpolator — to "animate" the shadow, drive `progress` with a
|
|
490
|
+
* spring, timing, or gesture upstream.
|
|
491
|
+
*/
|
|
492
|
+
declare function useShadow({ from, to, progress, }: UseShadowOptions): ReturnType<typeof useAnimatedStyle>;
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Build a controller for a variants map. The controller is the imperative
|
|
496
|
+
* escape hatch — pass it to a Motion primitive via `controller={...}` and
|
|
497
|
+
* call `controller.transitionTo('open')` from event handlers, async chains,
|
|
498
|
+
* etc. The hook name mirrors the prop name (`variants`) so the relationship
|
|
499
|
+
* is obvious.
|
|
500
|
+
*
|
|
501
|
+
* The controller is identity-stable across renders. State changes are
|
|
502
|
+
* delivered to subscribers via `subscribe` — Motion primitives subscribe
|
|
503
|
+
* internally and re-resolve `animate` on each transition.
|
|
504
|
+
*/
|
|
505
|
+
declare function useVariants<V extends Readonly<Record<string, object>>>(variants: V, initial?: keyof V & string): VariantController<keyof V & string>;
|
|
506
|
+
|
|
507
|
+
export { AnimatableValue, type ColorStyleKey, type ExtrapolationMode, Motion, MotionComponent, MotionConfig, type MotionConfigValue, Presence, type PresenceContextValue, type ReducedMotion, type ShadowConfig, SpringTransition, TransitionConfig, type UseColorTransitionOptions, type UseScrollResult, type UseShadowOptions, type UseTransformOptions, VariantController, buildReleaseAnimation, createMotionComponent, ensureWorkletEasing, resolveAnimatableValue, resolveTransition, useAnimation, useBooleanSpring, useColorTransition, useMotionConfig, useMotionValue, usePresence, useScroll, useShadow, useShouldReduceMotion, useSpring, useTransform, useVariants };
|