react-native-gtkx 0.2.0-alpha.2 → 0.3.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/README.md +5 -2
- package/dist/aliases/index.d.ts +84 -0
- package/dist/aliases/index.js +208 -0
- package/dist/aliases/index.js.map +1 -0
- package/dist/animated/index.d.ts +2 -0
- package/dist/animated/index.js +5 -0
- package/dist/animated/index.js.map +1 -1
- package/dist/animated/types.d.ts +1 -0
- package/dist/animated/types.js.map +1 -1
- package/dist/animated/value-animation.js +17 -4
- package/dist/animated/value-animation.js.map +1 -1
- package/dist/apis/host.gtkx.js +9 -12
- package/dist/apis/host.gtkx.js.map +1 -1
- package/dist/apis/index.d.ts +4 -2
- package/dist/apis/index.js +2 -0
- package/dist/apis/index.js.map +1 -1
- package/dist/apis/keyboard.d.ts +60 -0
- package/dist/apis/keyboard.js +63 -0
- package/dist/apis/keyboard.js.map +1 -0
- package/dist/apis/log-box.d.ts +15 -0
- package/dist/apis/log-box.js +46 -0
- package/dist/apis/log-box.js.map +1 -0
- package/dist/apis/platform.d.ts +18 -1
- package/dist/apis/platform.js.map +1 -1
- package/dist/common/index.d.ts +0 -1
- package/dist/common/index.js +24 -1
- package/dist/common/index.js.map +1 -1
- package/dist/components/animated.d.ts +70 -6
- package/dist/components/animated.js +559 -46
- package/dist/components/animated.js.map +1 -1
- package/dist/components/driven-size.d.ts +27 -0
- package/dist/components/driven-size.js +85 -0
- package/dist/components/driven-size.js.map +1 -0
- package/dist/components/find-node-handle.d.ts +11 -0
- package/dist/components/find-node-handle.js +53 -0
- package/dist/components/find-node-handle.js.map +1 -0
- package/dist/components/flat-list.d.ts +3 -2
- package/dist/components/flat-list.js.map +1 -1
- package/dist/components/frame-scheduler.d.ts +16 -0
- package/dist/components/frame-scheduler.js +37 -0
- package/dist/components/frame-scheduler.js.map +1 -0
- package/dist/components/image.d.ts +6 -1
- package/dist/components/image.js +15 -4
- package/dist/components/image.js.map +1 -1
- package/dist/components/index.d.ts +7 -5
- package/dist/components/index.js +5 -3
- package/dist/components/index.js.map +1 -1
- package/dist/components/measure.d.ts +51 -1
- package/dist/components/measure.js +101 -2
- package/dist/components/measure.js.map +1 -1
- package/dist/components/pressable.d.ts +61 -1
- package/dist/components/pressable.js +151 -4
- package/dist/components/pressable.js.map +1 -1
- package/dist/components/rect-store.d.ts +58 -0
- package/dist/components/rect-store.js +124 -3
- package/dist/components/rect-store.js.map +1 -1
- package/dist/components/root.js +6 -1
- package/dist/components/root.js.map +1 -1
- package/dist/components/scroll-phase.d.ts +35 -0
- package/dist/components/scroll-phase.js +26 -0
- package/dist/components/scroll-phase.js.map +1 -0
- package/dist/components/scroll-view.d.ts +39 -3
- package/dist/components/scroll-view.js +378 -43
- package/dist/components/scroll-view.js.map +1 -1
- package/dist/components/text-input.js +9 -25
- package/dist/components/text-input.js.map +1 -1
- package/dist/components/text.d.ts +6 -2
- package/dist/components/text.js +43 -8
- package/dist/components/text.js.map +1 -1
- package/dist/components/use-focus.d.ts +27 -0
- package/dist/components/use-focus.js +116 -0
- package/dist/components/use-focus.js.map +1 -0
- package/dist/components/use-layout-child.d.ts +13 -1
- package/dist/components/use-layout-child.js +188 -5
- package/dist/components/use-layout-child.js.map +1 -1
- package/dist/components/view.d.ts +5 -2
- package/dist/components/view.js +18 -13
- package/dist/components/view.js.map +1 -1
- package/dist/components/virtualized-list.d.ts +45 -5
- package/dist/components/virtualized-list.js +90 -24
- package/dist/components/virtualized-list.js.map +1 -1
- package/dist/components/wheel-scroll-session.d.ts +7 -0
- package/dist/components/wheel-scroll-session.js +53 -0
- package/dist/components/wheel-scroll-session.js.map +1 -0
- package/dist/components/widget-retention.d.ts +35 -0
- package/dist/components/widget-retention.js +169 -0
- package/dist/components/widget-retention.js.map +1 -0
- package/dist/contracts.d.ts +4 -0
- package/dist/contracts.js.map +1 -1
- package/dist/dnd/context.d.ts +69 -0
- package/dist/dnd/context.js +149 -0
- package/dist/dnd/context.js.map +1 -0
- package/dist/dnd/draggable.d.ts +59 -0
- package/dist/dnd/draggable.js +149 -0
- package/dist/dnd/draggable.js.map +1 -0
- package/dist/dnd/droppable.d.ts +24 -0
- package/dist/dnd/droppable.js +74 -0
- package/dist/dnd/droppable.js.map +1 -0
- package/dist/dnd/gtk-controllers.d.ts +39 -0
- package/dist/dnd/gtk-controllers.js +110 -0
- package/dist/dnd/gtk-controllers.js.map +1 -0
- package/dist/dnd/index.d.ts +6 -0
- package/dist/dnd/index.js +31 -0
- package/dist/dnd/index.js.map +1 -0
- package/dist/dnd/order.d.ts +7 -0
- package/dist/dnd/order.js +20 -0
- package/dist/dnd/order.js.map +1 -0
- package/dist/dnd/payload.d.ts +14 -0
- package/dist/dnd/payload.js +41 -0
- package/dist/dnd/payload.js.map +1 -0
- package/dist/dnd/sortable.d.ts +49 -0
- package/dist/dnd/sortable.js +307 -0
- package/dist/dnd/sortable.js.map +1 -0
- package/dist/dnd/types.d.ts +290 -0
- package/dist/dnd/types.js +25 -0
- package/dist/dnd/types.js.map +1 -0
- package/dist/gesture-handler-compat/builder.d.ts +251 -0
- package/dist/gesture-handler-compat/builder.js +513 -0
- package/dist/gesture-handler-compat/builder.js.map +1 -0
- package/dist/gesture-handler-compat/composition.d.ts +23 -0
- package/dist/gesture-handler-compat/composition.js +111 -0
- package/dist/gesture-handler-compat/composition.js.map +1 -0
- package/dist/gesture-handler-compat/deciders.d.ts +3 -0
- package/dist/gesture-handler-compat/deciders.js +47 -0
- package/dist/gesture-handler-compat/deciders.js.map +1 -0
- package/dist/gesture-handler-compat/detector-runtime.d.ts +44 -0
- package/dist/gesture-handler-compat/detector-runtime.js +374 -0
- package/dist/gesture-handler-compat/detector-runtime.js.map +1 -0
- package/dist/gesture-handler-compat/detector.d.ts +22 -0
- package/dist/gesture-handler-compat/detector.js +104 -0
- package/dist/gesture-handler-compat/detector.js.map +1 -0
- package/dist/gesture-handler-compat/fling.d.ts +24 -0
- package/dist/gesture-handler-compat/fling.js +123 -0
- package/dist/gesture-handler-compat/fling.js.map +1 -0
- package/dist/gesture-handler-compat/force-touch.d.ts +13 -0
- package/dist/gesture-handler-compat/force-touch.js +40 -0
- package/dist/gesture-handler-compat/force-touch.js.map +1 -0
- package/dist/gesture-handler-compat/hooks.d.ts +157 -0
- package/dist/gesture-handler-compat/hooks.js +268 -0
- package/dist/gesture-handler-compat/hooks.js.map +1 -0
- package/dist/gesture-handler-compat/hover.d.ts +2 -0
- package/dist/gesture-handler-compat/hover.js +22 -0
- package/dist/gesture-handler-compat/hover.js.map +1 -0
- package/dist/gesture-handler-compat/index.d.ts +98 -0
- package/dist/gesture-handler-compat/index.js +255 -0
- package/dist/gesture-handler-compat/index.js.map +1 -0
- package/dist/gesture-handler-compat/long-press.d.ts +6 -0
- package/dist/gesture-handler-compat/long-press.js +21 -0
- package/dist/gesture-handler-compat/long-press.js.map +1 -0
- package/dist/gesture-handler-compat/manual.d.ts +2 -0
- package/dist/gesture-handler-compat/manual.js +18 -0
- package/dist/gesture-handler-compat/manual.js.map +1 -0
- package/dist/gesture-handler-compat/native.d.ts +7 -0
- package/dist/gesture-handler-compat/native.js +34 -0
- package/dist/gesture-handler-compat/native.js.map +1 -0
- package/dist/gesture-handler-compat/orchestrator.d.ts +77 -0
- package/dist/gesture-handler-compat/orchestrator.js +284 -0
- package/dist/gesture-handler-compat/orchestrator.js.map +1 -0
- package/dist/gesture-handler-compat/pan.d.ts +23 -0
- package/dist/gesture-handler-compat/pan.js +116 -0
- package/dist/gesture-handler-compat/pan.js.map +1 -0
- package/dist/gesture-handler-compat/recognizer.d.ts +268 -0
- package/dist/gesture-handler-compat/recognizer.js +1056 -0
- package/dist/gesture-handler-compat/recognizer.js.map +1 -0
- package/dist/gesture-handler-compat/relations.d.ts +43 -0
- package/dist/gesture-handler-compat/relations.js +128 -0
- package/dist/gesture-handler-compat/relations.js.map +1 -0
- package/dist/gesture-handler-compat/tap.d.ts +6 -0
- package/dist/gesture-handler-compat/tap.js +29 -0
- package/dist/gesture-handler-compat/tap.js.map +1 -0
- package/dist/gesture-handler-compat/touchpad.d.ts +41 -0
- package/dist/gesture-handler-compat/touchpad.js +64 -0
- package/dist/gesture-handler-compat/touchpad.js.map +1 -0
- package/dist/gesture-handler-compat/types.d.ts +441 -0
- package/dist/gesture-handler-compat/types.js +167 -0
- package/dist/gesture-handler-compat/types.js.map +1 -0
- package/dist/gtk/controllers.d.ts +39 -0
- package/dist/gtk/controllers.js +92 -0
- package/dist/gtk/controllers.js.map +1 -0
- package/dist/gtk/index.d.ts +2 -1
- package/dist/gtk/index.js +7 -1
- package/dist/gtk/index.js.map +1 -1
- package/dist/gtkx/bridge/geometry.js +6 -4
- package/dist/gtkx/bridge/geometry.js.map +1 -1
- package/dist/gtkx/bridge/index.d.ts +5 -3
- package/dist/gtkx/bridge/index.js +6 -3
- package/dist/gtkx/bridge/index.js.map +1 -1
- package/dist/gtkx/bridge/slot-portal.js.map +1 -1
- package/dist/gtkx/bridge/use-signal.js +1 -1
- package/dist/gtkx/bridge/use-signal.js.map +1 -1
- package/dist/gtkx/bridge/view-box.d.ts +56 -0
- package/dist/gtkx/bridge/view-box.js +394 -9
- package/dist/gtkx/bridge/view-box.js.map +1 -1
- package/dist/gtkx/bridge/widget-css.d.ts +17 -0
- package/dist/gtkx/bridge/widget-css.js +72 -0
- package/dist/gtkx/bridge/widget-css.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/layout/driven-size.d.ts +12 -0
- package/dist/layout/driven-size.js +70 -0
- package/dist/layout/driven-size.js.map +1 -0
- package/dist/layout/engine.d.ts +17 -1
- package/dist/layout/engine.js +3 -20
- package/dist/layout/engine.js.map +1 -1
- package/dist/layout/node.d.ts +13 -0
- package/dist/layout/node.js +14 -0
- package/dist/layout/node.js.map +1 -1
- package/dist/layout/yoga.d.ts +3 -2
- package/dist/layout/yoga.js +5 -2
- package/dist/layout/yoga.js.map +1 -1
- package/dist/mcp/data/generated.d.ts +257 -60
- package/dist/mcp/data/generated.js +306 -62
- package/dist/mcp/data/generated.js.map +1 -1
- package/dist/metro/index.d.ts +10 -0
- package/dist/metro/index.js +21 -12
- package/dist/metro/index.js.map +1 -1
- package/dist/navigation/sidebar.d.ts +16 -0
- package/dist/navigation/sidebar.js +65 -1
- package/dist/navigation/sidebar.js.map +1 -1
- package/dist/reanimated-compat/animated-ref.d.ts +32 -0
- package/dist/reanimated-compat/animated-ref.js +57 -0
- package/dist/reanimated-compat/animated-ref.js.map +1 -0
- package/dist/reanimated-compat/animation.d.ts +177 -0
- package/dist/reanimated-compat/animation.js +540 -0
- package/dist/reanimated-compat/animation.js.map +1 -0
- package/dist/reanimated-compat/color.d.ts +28 -0
- package/dist/reanimated-compat/color.js +249 -0
- package/dist/reanimated-compat/color.js.map +1 -0
- package/dist/reanimated-compat/decay.d.ts +39 -0
- package/dist/reanimated-compat/decay.js +96 -0
- package/dist/reanimated-compat/decay.js.map +1 -0
- package/dist/reanimated-compat/easing.d.ts +30 -0
- package/dist/reanimated-compat/easing.js +76 -0
- package/dist/reanimated-compat/easing.js.map +1 -0
- package/dist/reanimated-compat/hooks.d.ts +14 -0
- package/dist/reanimated-compat/hooks.js +217 -0
- package/dist/reanimated-compat/hooks.js.map +1 -0
- package/dist/reanimated-compat/index.d.ts +258 -0
- package/dist/reanimated-compat/index.js +464 -0
- package/dist/reanimated-compat/index.js.map +1 -0
- package/dist/reanimated-compat/interpolation.d.ts +18 -0
- package/dist/reanimated-compat/interpolation.js +122 -0
- package/dist/reanimated-compat/interpolation.js.map +1 -0
- package/dist/reanimated-compat/layout-animation-config.d.ts +43 -0
- package/dist/reanimated-compat/layout-animation-config.js +78 -0
- package/dist/reanimated-compat/layout-animation-config.js.map +1 -0
- package/dist/reanimated-compat/layout-animation-presets.d.ts +117 -0
- package/dist/reanimated-compat/layout-animation-presets.js +498 -0
- package/dist/reanimated-compat/layout-animation-presets.js.map +1 -0
- package/dist/reanimated-compat/layout-animation-runtime.d.ts +21 -0
- package/dist/reanimated-compat/layout-animation-runtime.js +311 -0
- package/dist/reanimated-compat/layout-animation-runtime.js.map +1 -0
- package/dist/reanimated-compat/layout-animation-view.d.ts +27 -0
- package/dist/reanimated-compat/layout-animation-view.js +266 -0
- package/dist/reanimated-compat/layout-animation-view.js.map +1 -0
- package/dist/reanimated-compat/layout-animation.d.ts +171 -0
- package/dist/reanimated-compat/layout-animation.js +469 -0
- package/dist/reanimated-compat/layout-animation.js.map +1 -0
- package/dist/reanimated-compat/layout-transitions.d.ts +83 -0
- package/dist/reanimated-compat/layout-transitions.js +350 -0
- package/dist/reanimated-compat/layout-transitions.js.map +1 -0
- package/dist/reanimated-compat/mutable.d.ts +29 -0
- package/dist/reanimated-compat/mutable.js +139 -0
- package/dist/reanimated-compat/mutable.js.map +1 -0
- package/dist/reanimated-compat/props.d.ts +18 -0
- package/dist/reanimated-compat/props.js +111 -0
- package/dist/reanimated-compat/props.js.map +1 -0
- package/dist/reanimated-compat/scroll-handler.d.ts +119 -0
- package/dist/reanimated-compat/scroll-handler.js +274 -0
- package/dist/reanimated-compat/scroll-handler.js.map +1 -0
- package/dist/reanimated-compat/scroll-offset.d.ts +12 -0
- package/dist/reanimated-compat/scroll-offset.js +104 -0
- package/dist/reanimated-compat/scroll-offset.js.map +1 -0
- package/dist/reanimated-compat/style.d.ts +90 -0
- package/dist/reanimated-compat/style.js +452 -0
- package/dist/reanimated-compat/style.js.map +1 -0
- package/dist/reanimated-compat/test-timers.d.ts +28 -0
- package/dist/reanimated-compat/test-timers.js +136 -0
- package/dist/reanimated-compat/test-timers.js.map +1 -0
- package/dist/reanimated-compat/threads.d.ts +13 -0
- package/dist/reanimated-compat/threads.js +41 -0
- package/dist/reanimated-compat/threads.js.map +1 -0
- package/dist/reanimated-compat/tracking.d.ts +41 -0
- package/dist/reanimated-compat/tracking.js +106 -0
- package/dist/reanimated-compat/tracking.js.map +1 -0
- package/dist/reanimated-compat/updater-animations.d.ts +36 -0
- package/dist/reanimated-compat/updater-animations.js +273 -0
- package/dist/reanimated-compat/updater-animations.js.map +1 -0
- package/dist/responder/system.d.ts +80 -7
- package/dist/responder/system.js +143 -23
- package/dist/responder/system.js.map +1 -1
- package/dist/responder/use-responder.d.ts +11 -0
- package/dist/responder/use-responder.js +225 -6
- package/dist/responder/use-responder.js.map +1 -1
- package/dist/runner/host-dev.js +1 -1
- package/dist/runner/host-dev.js.map +1 -1
- package/dist/runner/host.js +1 -1
- package/dist/runner/host.js.map +1 -1
- package/dist/runner/index.js +3 -3
- package/dist/runner/index.js.map +1 -1
- package/dist/sea/gtkx-config-module.js +1 -1
- package/dist/sea/gtkx-config-module.js.map +1 -1
- package/dist/style/absolute-insets.d.ts +26 -0
- package/dist/style/absolute-insets.js +113 -0
- package/dist/style/absolute-insets.js.map +1 -0
- package/dist/style/animated-size.d.ts +25 -0
- package/dist/style/animated-size.js +225 -0
- package/dist/style/animated-size.js.map +1 -0
- package/dist/style/colors.d.ts +17 -0
- package/dist/style/colors.js +25 -6
- package/dist/style/colors.js.map +1 -1
- package/dist/style/imperative-css.d.ts +21 -0
- package/dist/style/imperative-css.js +63 -0
- package/dist/style/imperative-css.js.map +1 -0
- package/dist/style/index.d.ts +2 -1
- package/dist/style/index.js +2 -1
- package/dist/style/index.js.map +1 -1
- package/dist/style/split-style.js +5 -0
- package/dist/style/split-style.js.map +1 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/unsupported-export.d.ts +8 -0
- package/dist/unsupported-export.js +66 -0
- package/dist/unsupported-export.js.map +1 -0
- package/dist/vite/index.d.ts +21 -8
- package/dist/vite/index.js +127 -82
- package/dist/vite/index.js.map +1 -1
- package/dist/vitest/index.d.ts +2 -2
- package/dist/vitest/index.js.map +1 -1
- package/dist/worklets-compat/index.d.ts +4 -0
- package/dist/worklets-compat/index.js +28 -0
- package/dist/worklets-compat/index.js.map +1 -0
- package/dist/worklets-compat/surface.d.ts +110 -0
- package/dist/worklets-compat/surface.js +153 -0
- package/dist/worklets-compat/surface.js.map +1 -0
- package/package.json +25 -9
- package/types.d.ts +9 -0
- package/dist/common/list.d.ts +0 -82
- package/dist/common/list.js +0 -166
- package/dist/common/list.js.map +0 -1
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
// `withTiming` / `withSpring` / `withDelay` / `withSequence` / `withRepeat`.
|
|
2
|
+
//
|
|
3
|
+
// Upstream types these as returning the animated type itself
|
|
4
|
+
// (`withTiming(100)` is a `number`), because what starts the animation is
|
|
5
|
+
// ASSIGNING the result to a shared value. The cast at each return mirrors
|
|
6
|
+
// that trick rather than inventing a different API — see `mutable.ts`, which
|
|
7
|
+
// recognises the descriptor in its setter.
|
|
8
|
+
//
|
|
9
|
+
// The descriptors are plain data. Turning one into a running animation is
|
|
10
|
+
// `buildAnimation`, and it builds on the platform's own `src/animated/`
|
|
11
|
+
// engine: same frame scheduler, same closed-form solvers, same preemption
|
|
12
|
+
// rules. This layer adds no clock.
|
|
13
|
+
//
|
|
14
|
+
// It does NOT reuse `Animated.timing`/`Animated.spring`'s DEFAULTS, and that
|
|
15
|
+
// distinction is load-bearing. Reanimated's defaults are materially
|
|
16
|
+
// different animations:
|
|
17
|
+
//
|
|
18
|
+
// | config | RN Animated | Reanimated 4 |
|
|
19
|
+
// | --------------- | ------------------------ | -------------------------- |
|
|
20
|
+
// | timing duration | 500 ms | 300 ms |
|
|
21
|
+
// | timing easing | inOut(ease) | inOut(quad) |
|
|
22
|
+
// | spring | damping 10, mass 1, k 100 | damping 120, mass 4, k 900 |
|
|
23
|
+
//
|
|
24
|
+
// The spring row is not a tuning difference: RN's default has damping ratio
|
|
25
|
+
// 0.5 and visibly bounces, Reanimated 4's is exactly critically damped and
|
|
26
|
+
// does not. Every config below is therefore passed explicitly.
|
|
27
|
+
import { createValueAnimation, } from "../animated/index";
|
|
28
|
+
import { decayStep, resolveDecayConfig } from "./decay";
|
|
29
|
+
import { Easing, resolveEasing } from "./easing";
|
|
30
|
+
const MARKER = "__rnGtkxReanimatedAnimation";
|
|
31
|
+
const mark = (spec) => Object.assign(spec, { [MARKER]: true });
|
|
32
|
+
export const isAnimationSpec = (value) => typeof value === "object" &&
|
|
33
|
+
value !== null &&
|
|
34
|
+
value[MARKER] === true;
|
|
35
|
+
// --- the initial run ----------------------------------------------------
|
|
36
|
+
//
|
|
37
|
+
// Upstream's `IN_STYLE_UPDATER`, and it is not a detail: the FIRST evaluation
|
|
38
|
+
// of a `useDerivedValue`/`useAnimatedStyle`/`useAnimatedProps` updater has no
|
|
39
|
+
// value to animate FROM, so every `with*` builder returns its target instead
|
|
40
|
+
// of an animation. `defineAnimation` does it in one line —
|
|
41
|
+
// `if (IN_STYLE_UPDATER.current) return starting` — and that line is what
|
|
42
|
+
// makes the documented pattern
|
|
43
|
+
//
|
|
44
|
+
// const v = useDerivedValue(() => withSpring(active.value ? 1 : 0))
|
|
45
|
+
//
|
|
46
|
+
// work at all. Without it the shared value is SEEDED with the animation
|
|
47
|
+
// object itself and every later write finds a value that is not a number.
|
|
48
|
+
// Found by building `react-native-draggable-flatlist`, whose `ScaleDecorator`
|
|
49
|
+
// is exactly that pattern (`hooks/useOnCellActiveAnimation.ts`).
|
|
50
|
+
let inInitialRun = false;
|
|
51
|
+
/**
|
|
52
|
+
* Runs an updater in "seed the value" mode, where every animation collapses
|
|
53
|
+
* to the value it would have finished at.
|
|
54
|
+
*/
|
|
55
|
+
export const initialUpdaterRun = (updater) => {
|
|
56
|
+
inInitialRun = true;
|
|
57
|
+
try {
|
|
58
|
+
return updater();
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
inInitialRun = false;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
// Upstream's own defaults, quoted in the table at the top of this file.
|
|
65
|
+
const DEFAULT_TIMING_DURATION = 300;
|
|
66
|
+
const defaultTimingEasing = Easing.inOut(Easing.quad);
|
|
67
|
+
// GentleSpringConfig + energyThreshold, react-native-reanimated 4.5.3
|
|
68
|
+
// (src/animation/spring/springConfigs.ts).
|
|
69
|
+
const DEFAULT_SPRING_MASS = 4;
|
|
70
|
+
const DEFAULT_SPRING_STIFFNESS = 900;
|
|
71
|
+
const DEFAULT_SPRING_DAMPING = 120;
|
|
72
|
+
const DEFAULT_SPRING_DURATION = 550;
|
|
73
|
+
const DEFAULT_SPRING_DAMPING_RATIO = 1;
|
|
74
|
+
const DEFAULT_ENERGY_THRESHOLD = 6e-9;
|
|
75
|
+
const assertAnimatable = (value, api) => {
|
|
76
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
77
|
+
throw new Error(`react-native-reanimated: ${api}() on this platform animates finite numbers only, got ${typeof value === "string" ? `"${value}"` : String(value)}. ` +
|
|
78
|
+
"Colors and layout properties cannot be driven imperatively here yet — see docs/api.md.");
|
|
79
|
+
}
|
|
80
|
+
return value;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Lets you animate a value over a duration with an easing curve. Assign the
|
|
84
|
+
* result to a shared value to start it.
|
|
85
|
+
*/
|
|
86
|
+
export const withTiming = (toValue, config, callback) => inInitialRun
|
|
87
|
+
? assertAnimatable(toValue, "withTiming")
|
|
88
|
+
: mark({
|
|
89
|
+
kind: "timing",
|
|
90
|
+
toValue: assertAnimatable(toValue, "withTiming"),
|
|
91
|
+
config: config ?? {},
|
|
92
|
+
callback,
|
|
93
|
+
});
|
|
94
|
+
/** Lets you animate a value with spring physics. */
|
|
95
|
+
export const withSpring = (toValue, config, callback) => inInitialRun
|
|
96
|
+
? assertAnimatable(toValue, "withSpring")
|
|
97
|
+
: mark({
|
|
98
|
+
kind: "spring",
|
|
99
|
+
toValue: assertAnimatable(toValue, "withSpring"),
|
|
100
|
+
config: config ?? {},
|
|
101
|
+
callback,
|
|
102
|
+
});
|
|
103
|
+
/** Delays another animation by `delayMs`. */
|
|
104
|
+
export const withDelay = (delayMs, animation) => {
|
|
105
|
+
// Upstream's `starting` for every composite is the animation it wraps,
|
|
106
|
+
// which the initial run has already collapsed to a plain value.
|
|
107
|
+
if (inInitialRun) {
|
|
108
|
+
return animation;
|
|
109
|
+
}
|
|
110
|
+
if (!isAnimationSpec(animation)) {
|
|
111
|
+
throw new Error("react-native-reanimated: withDelay() takes an animation, e.g. withDelay(500, withTiming(1))");
|
|
112
|
+
}
|
|
113
|
+
return mark({
|
|
114
|
+
kind: "delay",
|
|
115
|
+
delayMs,
|
|
116
|
+
animation,
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
/** Runs animations one after another on the same shared value. */
|
|
120
|
+
export const withSequence = (...animations) => {
|
|
121
|
+
if (inInitialRun) {
|
|
122
|
+
return animations[0] ?? 0;
|
|
123
|
+
}
|
|
124
|
+
const specs = [];
|
|
125
|
+
for (const animation of animations) {
|
|
126
|
+
if (!isAnimationSpec(animation)) {
|
|
127
|
+
throw new Error("react-native-reanimated: withSequence() takes animations, e.g. withSequence(withTiming(1), withTiming(0))");
|
|
128
|
+
}
|
|
129
|
+
specs.push(animation);
|
|
130
|
+
}
|
|
131
|
+
return mark({ kind: "sequence", animations: specs });
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Repeats an animation. `numberOfReps <= 0` repeats forever; `reverse` plays
|
|
135
|
+
* every other repetition backwards.
|
|
136
|
+
*/
|
|
137
|
+
export const withRepeat = (animation, numberOfReps = 2, reverse = false, callback) => {
|
|
138
|
+
if (inInitialRun) {
|
|
139
|
+
return animation;
|
|
140
|
+
}
|
|
141
|
+
if (!isAnimationSpec(animation)) {
|
|
142
|
+
throw new Error("react-native-reanimated: withRepeat() takes an animation, e.g. withRepeat(withTiming(1), 3)");
|
|
143
|
+
}
|
|
144
|
+
return mark({
|
|
145
|
+
kind: "repeat",
|
|
146
|
+
animation,
|
|
147
|
+
numberOfReps,
|
|
148
|
+
reverse,
|
|
149
|
+
callback,
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Coasts to a stop from an initial velocity — the release half of a fling.
|
|
154
|
+
* Unlike every other animation here it has no target: where it lands is the
|
|
155
|
+
* result of the velocity and the friction, which is exactly what makes it the
|
|
156
|
+
* one an inertial gesture needs.
|
|
157
|
+
*
|
|
158
|
+
* ```tsx
|
|
159
|
+
* onPanResponderRelease: (_, g) => {
|
|
160
|
+
* x.value = withDecay({ velocity: g.vx * 1000, clamp: [0, width] })
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* `velocity` is in units per SECOND, as upstream — `PanResponder`'s
|
|
165
|
+
* `gestureState.vx` is per millisecond, so it wants the ×1000 above.
|
|
166
|
+
*/
|
|
167
|
+
export const withDecay = (config, callback) => inInitialRun
|
|
168
|
+
? // Upstream seeds a decay with 0: it has no target to collapse to.
|
|
169
|
+
0
|
|
170
|
+
: mark({
|
|
171
|
+
kind: "decay",
|
|
172
|
+
config: resolveDecayConfig(config),
|
|
173
|
+
callback,
|
|
174
|
+
});
|
|
175
|
+
/**
|
|
176
|
+
* Confines another animation to a range: the inner animation runs its own
|
|
177
|
+
* un-truncated course and what reaches the value is clipped to `[min, max]`.
|
|
178
|
+
* That distinction is upstream's and it is observable — a spring clamped at
|
|
179
|
+
* 100 that would have overshot to 120 sits at 100 and then comes back down,
|
|
180
|
+
* rather than settling at 100 the moment it first arrives.
|
|
181
|
+
*/
|
|
182
|
+
export const withClamp = (config, animation) => {
|
|
183
|
+
if (inInitialRun) {
|
|
184
|
+
return animation;
|
|
185
|
+
}
|
|
186
|
+
if (!isAnimationSpec(animation)) {
|
|
187
|
+
throw new Error("react-native-reanimated: withClamp() takes an animation, e.g. withClamp({ min: 0 }, withSpring(1))");
|
|
188
|
+
}
|
|
189
|
+
if (config.min !== undefined &&
|
|
190
|
+
config.max !== undefined &&
|
|
191
|
+
config.max < config.min) {
|
|
192
|
+
throw new Error(`react-native-reanimated: withClamp() was given min ${config.min} above max ${config.max}.`);
|
|
193
|
+
}
|
|
194
|
+
return mark({
|
|
195
|
+
kind: "clamp",
|
|
196
|
+
min: config.min,
|
|
197
|
+
max: config.max,
|
|
198
|
+
animation,
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
// --- spring config normalisation ----------------------------------------
|
|
202
|
+
const bisect = (min, max, fn, precision, maxIterations = 100) => {
|
|
203
|
+
let low = min;
|
|
204
|
+
let high = max;
|
|
205
|
+
const direction = fn(high) >= fn(low) ? 1 : -1;
|
|
206
|
+
let current = (low + high) / 2;
|
|
207
|
+
for (let i = 0; i < maxIterations && Math.abs(fn(current)) > precision; i++) {
|
|
208
|
+
if (fn(current) * direction < 0) {
|
|
209
|
+
low = current;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
high = current;
|
|
213
|
+
}
|
|
214
|
+
current = (low + high) / 2;
|
|
215
|
+
}
|
|
216
|
+
return current;
|
|
217
|
+
};
|
|
218
|
+
const energyOf = (displacement, velocity, stiffness, mass) => 0.5 * stiffness * displacement ** 2 + 0.5 * mass * velocity ** 2;
|
|
219
|
+
/**
|
|
220
|
+
* Solves for the stiffness whose settling time matches a requested perceptual
|
|
221
|
+
* duration, by bisection on the fraction of the initial energy left after
|
|
222
|
+
* 1.5 × that duration. Ported from upstream's
|
|
223
|
+
* `calculateNewStiffnessToMatchDuration` — the perceptual-duration spring is
|
|
224
|
+
* a Reanimated concept with no RN equivalent, so there is nothing on the
|
|
225
|
+
* platform side to reuse.
|
|
226
|
+
*/
|
|
227
|
+
const stiffnessForDuration = (x0, v0, durationMs, dampingRatio, mass, energyThreshold) => {
|
|
228
|
+
const PERCEPTUAL_COEFFICIENT = 1.5;
|
|
229
|
+
const settlingSeconds = (durationMs * PERCEPTUAL_COEFFICIENT) / 1000;
|
|
230
|
+
const initialEnergyFor = (stiffness) => energyOf(x0, v0, stiffness, mass);
|
|
231
|
+
const energyFractionLeft = (stiffness) => {
|
|
232
|
+
const decay = Math.sqrt(stiffness / mass) * dampingRatio;
|
|
233
|
+
const envelope = Math.exp(-decay * settlingSeconds);
|
|
234
|
+
const displacement = (x0 + (v0 + x0 * decay) * settlingSeconds) * envelope;
|
|
235
|
+
const velocity = displacement * -decay + (v0 + x0 * decay) * envelope;
|
|
236
|
+
const initial = initialEnergyFor(stiffness);
|
|
237
|
+
if (initial === 0) {
|
|
238
|
+
return -energyThreshold;
|
|
239
|
+
}
|
|
240
|
+
return (energyOf(displacement, velocity, stiffness, mass) / initial -
|
|
241
|
+
energyThreshold);
|
|
242
|
+
};
|
|
243
|
+
return bisect(Number.EPSILON,
|
|
244
|
+
// Upstream's bound: even an 8 ms spring stays under 2e3, with margin.
|
|
245
|
+
8e3, energyFractionLeft, energyThreshold * 1e-3);
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* Keeps the overshoot inside `clamp` by raising the damping ratio, using
|
|
249
|
+
* upstream's approximation: the first two extrema of a damped oscillation sit
|
|
250
|
+
* at `exp(-zeta * PI)` and `exp(-zeta * 2 * PI)` of the initial displacement,
|
|
251
|
+
* so the zeta that puts them on the bound is a logarithm away.
|
|
252
|
+
*/
|
|
253
|
+
const zetaForClamp = (zeta, startDisplacement, toValue, clamp) => {
|
|
254
|
+
if (startDisplacement === 0) {
|
|
255
|
+
return zeta;
|
|
256
|
+
}
|
|
257
|
+
const [firstBound, secondBound] = startDisplacement <= 0 ? [clamp.min, clamp.max] : [clamp.max, clamp.min];
|
|
258
|
+
const candidates = [zeta];
|
|
259
|
+
if (secondBound !== undefined) {
|
|
260
|
+
const extremum = Math.abs((secondBound - toValue) / startDisplacement);
|
|
261
|
+
candidates.push(Math.abs(Math.log(extremum) / Math.PI));
|
|
262
|
+
}
|
|
263
|
+
if (firstBound !== undefined) {
|
|
264
|
+
const extremum = Math.abs((firstBound - toValue) / startDisplacement);
|
|
265
|
+
candidates.push(Math.abs(Math.log(extremum) / (2 * Math.PI)));
|
|
266
|
+
}
|
|
267
|
+
// Bigger zeta means smaller bounces, so the strictest candidate wins.
|
|
268
|
+
return Math.max(...candidates);
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* Turns a Reanimated spring config into the platform solver's config.
|
|
272
|
+
*
|
|
273
|
+
* The rest condition is the one place the two genuinely differ. Upstream
|
|
274
|
+
* stops when the oscillator's remaining energy falls to `energyThreshold` of
|
|
275
|
+
* its initial energy — a RELATIVE criterion; the platform's solver stops on
|
|
276
|
+
* absolute displacement and speed thresholds. Rather than accept RN's
|
|
277
|
+
* absolute defaults (which would end a 400px spring at a different point than
|
|
278
|
+
* a 4px one), the thresholds are derived per animation from the same energy
|
|
279
|
+
* budget, so the stopping point tracks upstream's to well under a pixel.
|
|
280
|
+
*/
|
|
281
|
+
export const toPlatformSpringConfig = (config, toValue, from) => {
|
|
282
|
+
const mass = config.mass ?? DEFAULT_SPRING_MASS;
|
|
283
|
+
const velocity = config.velocity ?? 0;
|
|
284
|
+
const energyThreshold = config.energyThreshold ?? DEFAULT_ENERGY_THRESHOLD;
|
|
285
|
+
const useDuration = config.duration !== undefined || config.dampingRatio !== undefined;
|
|
286
|
+
const displacement = from - toValue;
|
|
287
|
+
let stiffness;
|
|
288
|
+
let zeta;
|
|
289
|
+
if (useDuration) {
|
|
290
|
+
const duration = config.duration ?? DEFAULT_SPRING_DURATION;
|
|
291
|
+
zeta = config.dampingRatio ?? DEFAULT_SPRING_DAMPING_RATIO;
|
|
292
|
+
stiffness =
|
|
293
|
+
duration <= 0
|
|
294
|
+
? Number.POSITIVE_INFINITY
|
|
295
|
+
: stiffnessForDuration(displacement, velocity, duration, zeta, mass, energyThreshold);
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
stiffness = config.stiffness ?? DEFAULT_SPRING_STIFFNESS;
|
|
299
|
+
const damping = config.damping ?? DEFAULT_SPRING_DAMPING;
|
|
300
|
+
zeta = damping / (2 * Math.sqrt(stiffness * mass));
|
|
301
|
+
}
|
|
302
|
+
if (config.clamp) {
|
|
303
|
+
zeta = zetaForClamp(zeta, displacement, toValue, config.clamp);
|
|
304
|
+
}
|
|
305
|
+
// A zero/degenerate duration means "be there already"; the platform solver
|
|
306
|
+
// rejects a non-finite stiffness, so collapse it to a 0 ms timing instead.
|
|
307
|
+
const resolvedStiffness = Number.isFinite(stiffness)
|
|
308
|
+
? Math.max(stiffness, Number.EPSILON)
|
|
309
|
+
: 1e6;
|
|
310
|
+
const initialEnergy = energyOf(displacement, velocity, resolvedStiffness, mass);
|
|
311
|
+
const restEnergy = energyThreshold * initialEnergy;
|
|
312
|
+
return {
|
|
313
|
+
toValue,
|
|
314
|
+
mass,
|
|
315
|
+
stiffness: resolvedStiffness,
|
|
316
|
+
damping: Math.max(zeta * 2 * Math.sqrt(resolvedStiffness * mass), Number.EPSILON),
|
|
317
|
+
initialVelocity: velocity,
|
|
318
|
+
overshootClamping: config.overshootClamping ?? false,
|
|
319
|
+
// Semi-axes of the energy ellipse: |x| where all the remaining energy is
|
|
320
|
+
// potential, |v| where all of it is kinetic. A spring at rest is inside
|
|
321
|
+
// both.
|
|
322
|
+
restDisplacementThreshold: Math.max(Math.sqrt((2 * restEnergy) / resolvedStiffness), Number.MIN_VALUE),
|
|
323
|
+
restSpeedThreshold: Math.max(Math.sqrt((2 * restEnergy) / mass), Number.MIN_VALUE),
|
|
324
|
+
};
|
|
325
|
+
};
|
|
326
|
+
// --- building a running animation ---------------------------------------
|
|
327
|
+
/**
|
|
328
|
+
* The last value an animation aims at, used by `withRepeat`'s reverse and by
|
|
329
|
+
* `updater-animations.ts` to seed a key that is animating for the first time.
|
|
330
|
+
*/
|
|
331
|
+
export const targetOf = (spec) => {
|
|
332
|
+
switch (spec.kind) {
|
|
333
|
+
case "timing":
|
|
334
|
+
case "spring":
|
|
335
|
+
return spec.toValue;
|
|
336
|
+
case "delay":
|
|
337
|
+
return targetOf(spec.animation);
|
|
338
|
+
case "sequence": {
|
|
339
|
+
const last = spec.animations[spec.animations.length - 1];
|
|
340
|
+
return last ? targetOf(last) : null;
|
|
341
|
+
}
|
|
342
|
+
case "repeat":
|
|
343
|
+
return targetOf(spec.animation);
|
|
344
|
+
case "clamp":
|
|
345
|
+
return targetOf(spec.animation);
|
|
346
|
+
// A decay has no target by construction — where it lands is the result
|
|
347
|
+
// rather than the input. `withRepeat(withDecay(...))` therefore replays
|
|
348
|
+
// from the same origin rather than ping-ponging between two.
|
|
349
|
+
case "decay":
|
|
350
|
+
return null;
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
/** A copy of `spec` aimed at `toValue`, for a reversed repetition. */
|
|
354
|
+
const aimedAt = (spec, toValue) => {
|
|
355
|
+
switch (spec.kind) {
|
|
356
|
+
case "timing":
|
|
357
|
+
case "spring":
|
|
358
|
+
return { ...spec, toValue };
|
|
359
|
+
case "delay":
|
|
360
|
+
return { ...spec, animation: aimedAt(spec.animation, toValue) };
|
|
361
|
+
case "sequence": {
|
|
362
|
+
const animations = [...spec.animations];
|
|
363
|
+
const lastIndex = animations.length - 1;
|
|
364
|
+
const last = animations[lastIndex];
|
|
365
|
+
if (last) {
|
|
366
|
+
animations[lastIndex] = aimedAt(last, toValue);
|
|
367
|
+
}
|
|
368
|
+
return { ...spec, animations };
|
|
369
|
+
}
|
|
370
|
+
case "repeat":
|
|
371
|
+
return { ...spec, animation: aimedAt(spec.animation, toValue) };
|
|
372
|
+
case "clamp":
|
|
373
|
+
return { ...spec, animation: aimedAt(spec.animation, toValue) };
|
|
374
|
+
// Nothing to re-aim: see targetOf.
|
|
375
|
+
case "decay":
|
|
376
|
+
return spec;
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
/**
|
|
380
|
+
* What makes two descriptors the SAME animation, for a caller that gets a
|
|
381
|
+
* freshly built one on every evaluation and must decide whether to restart.
|
|
382
|
+
*
|
|
383
|
+
* The target and the shape, not object identity and not the whole config: a
|
|
384
|
+
* mapper re-runs whenever anything it read changed, so `withSpring(open.value
|
|
385
|
+
* ? 320 : 0)` produces a new object many times a second while asking for the
|
|
386
|
+
* same animation every time. Config fields that change WHERE the animation
|
|
387
|
+
* ends are in (a `duration`, a decay's `velocity`); ones that only change how
|
|
388
|
+
* it gets there are not, because re-aiming a running animation at the value it
|
|
389
|
+
* is already aimed at is a no-op that costs a restart.
|
|
390
|
+
*/
|
|
391
|
+
export const animationSignature = (spec) => {
|
|
392
|
+
switch (spec.kind) {
|
|
393
|
+
case "timing":
|
|
394
|
+
return `timing(${spec.toValue},${spec.config.duration ?? ""})`;
|
|
395
|
+
case "spring":
|
|
396
|
+
return `spring(${spec.toValue})`;
|
|
397
|
+
case "delay":
|
|
398
|
+
return `delay(${spec.delayMs},${animationSignature(spec.animation)})`;
|
|
399
|
+
case "sequence":
|
|
400
|
+
return `sequence(${spec.animations.map(animationSignature).join(";")})`;
|
|
401
|
+
case "repeat":
|
|
402
|
+
return `repeat(${spec.numberOfReps},${spec.reverse},${animationSignature(spec.animation)})`;
|
|
403
|
+
case "clamp":
|
|
404
|
+
return `clamp(${spec.min},${spec.max},${animationSignature(spec.animation)})`;
|
|
405
|
+
// A decay has no target (targetOf), so its identity is the push it was
|
|
406
|
+
// given: a new flick is a new animation, the same flick is not.
|
|
407
|
+
case "decay":
|
|
408
|
+
return `decay(${spec.config.velocity},${spec.config.deceleration})`;
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
const callbackOf = (spec) => spec.kind === "timing" ||
|
|
412
|
+
spec.kind === "spring" ||
|
|
413
|
+
spec.kind === "repeat" ||
|
|
414
|
+
spec.kind === "decay"
|
|
415
|
+
? spec.callback
|
|
416
|
+
: undefined;
|
|
417
|
+
/**
|
|
418
|
+
* Fires the descriptor's own callback when its animation settles — including
|
|
419
|
+
* when it is cancelled, which reports `finished: false`, as upstream does.
|
|
420
|
+
* Every node carries one, so the per-child callbacks of a `withSequence` and
|
|
421
|
+
* the per-repetition callbacks of a `withRepeat` fire without the caller
|
|
422
|
+
* having to unpick the tree.
|
|
423
|
+
*/
|
|
424
|
+
const reportingTo = (animation, callback, driver) => callback
|
|
425
|
+
? {
|
|
426
|
+
start: (onEnd) => {
|
|
427
|
+
animation.start((result) => {
|
|
428
|
+
callback(result.finished, driver.__getValue());
|
|
429
|
+
onEnd?.(result);
|
|
430
|
+
});
|
|
431
|
+
},
|
|
432
|
+
stop: () => animation.stop(),
|
|
433
|
+
reset: () => animation.reset(),
|
|
434
|
+
}
|
|
435
|
+
: animation;
|
|
436
|
+
const buildRepeat = (engine, driver, spec) => {
|
|
437
|
+
let child = null;
|
|
438
|
+
let cancelled = false;
|
|
439
|
+
return {
|
|
440
|
+
start(onEnd) {
|
|
441
|
+
cancelled = false;
|
|
442
|
+
const origin = driver.__getValue();
|
|
443
|
+
let from = origin;
|
|
444
|
+
let to = targetOf(spec.animation) ?? origin;
|
|
445
|
+
let completed = 0;
|
|
446
|
+
const runIteration = () => {
|
|
447
|
+
child = buildAnimation(engine, driver, aimedAt(spec.animation, to));
|
|
448
|
+
child.start((result) => {
|
|
449
|
+
if (cancelled || !result.finished) {
|
|
450
|
+
onEnd?.(result);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
completed += 1;
|
|
454
|
+
if (spec.numberOfReps > 0 && completed >= spec.numberOfReps) {
|
|
455
|
+
onEnd?.({ finished: true });
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (spec.reverse) {
|
|
459
|
+
// Ping-pong: the value is already at `to`, so the next
|
|
460
|
+
// repetition simply aims back at where this one started.
|
|
461
|
+
const previousTarget = to;
|
|
462
|
+
to = from;
|
|
463
|
+
from = previousTarget;
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
// Replay: snap back to where the repeat began and run again,
|
|
467
|
+
// which is what upstream's onStart(startValue) amounts to.
|
|
468
|
+
driver.setValue(from);
|
|
469
|
+
}
|
|
470
|
+
runIteration();
|
|
471
|
+
});
|
|
472
|
+
};
|
|
473
|
+
runIteration();
|
|
474
|
+
},
|
|
475
|
+
stop() {
|
|
476
|
+
cancelled = true;
|
|
477
|
+
child?.stop();
|
|
478
|
+
},
|
|
479
|
+
reset() {
|
|
480
|
+
child?.reset();
|
|
481
|
+
},
|
|
482
|
+
};
|
|
483
|
+
};
|
|
484
|
+
/**
|
|
485
|
+
* Turns a descriptor into a running animation on `driver`. Every leaf is one
|
|
486
|
+
* of the platform's own animations, so the whole tree runs off the single
|
|
487
|
+
* injected frame scheduler.
|
|
488
|
+
*/
|
|
489
|
+
export const buildAnimation = (engine, driver, spec) => {
|
|
490
|
+
const { api, scheduler } = engine;
|
|
491
|
+
const build = () => {
|
|
492
|
+
switch (spec.kind) {
|
|
493
|
+
case "timing":
|
|
494
|
+
return api.timing(driver, {
|
|
495
|
+
toValue: spec.toValue,
|
|
496
|
+
duration: spec.config.duration ?? DEFAULT_TIMING_DURATION,
|
|
497
|
+
easing: spec.config.easing
|
|
498
|
+
? resolveEasing(spec.config.easing)
|
|
499
|
+
: defaultTimingEasing,
|
|
500
|
+
});
|
|
501
|
+
case "spring":
|
|
502
|
+
return api.spring(driver, toPlatformSpringConfig(spec.config, spec.toValue, driver.__getValue()));
|
|
503
|
+
case "delay":
|
|
504
|
+
return api.sequence([
|
|
505
|
+
api.delay(spec.delayMs),
|
|
506
|
+
buildAnimation(engine, driver, spec.animation),
|
|
507
|
+
]);
|
|
508
|
+
case "sequence":
|
|
509
|
+
return api.sequence(spec.animations.map((child) => buildAnimation(engine, driver, child)));
|
|
510
|
+
case "repeat":
|
|
511
|
+
return buildRepeat(engine, driver, spec);
|
|
512
|
+
case "decay":
|
|
513
|
+
return createValueAnimation(scheduler, driver, decayStep(spec.config));
|
|
514
|
+
case "clamp":
|
|
515
|
+
return buildClamp(engine, driver, spec);
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
return reportingTo(build(), callbackOf(spec), driver);
|
|
519
|
+
};
|
|
520
|
+
/**
|
|
521
|
+
* `withClamp` in full: the inner animation is built on a PRIVATE value and
|
|
522
|
+
* what that value publishes is clipped onto the real driver. Running it
|
|
523
|
+
* un-truncated is the whole behaviour — upstream keeps the clamped animation's
|
|
524
|
+
* own `current` unbounded for exactly this reason — and the private node costs
|
|
525
|
+
* one listener, no extra frame subscription and no second clock, because the
|
|
526
|
+
* inner animation is an ordinary one built by the same function.
|
|
527
|
+
*/
|
|
528
|
+
const buildClamp = (engine, driver, spec) => {
|
|
529
|
+
const inner = new engine.api.Value(driver.__getValue());
|
|
530
|
+
inner.addListener(({ value }) => {
|
|
531
|
+
const clipped = spec.max !== undefined && value > spec.max
|
|
532
|
+
? spec.max
|
|
533
|
+
: spec.min !== undefined && value < spec.min
|
|
534
|
+
? spec.min
|
|
535
|
+
: value;
|
|
536
|
+
driver.__updateValue(clipped);
|
|
537
|
+
});
|
|
538
|
+
return buildAnimation(engine, inner, spec.animation);
|
|
539
|
+
};
|
|
540
|
+
//# sourceMappingURL=animation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"animation.js","sourceRoot":"","sources":["../../src/reanimated-compat/animation.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,EAAE;AACF,6DAA6D;AAC7D,0EAA0E;AAC1E,0EAA0E;AAC1E,6EAA6E;AAC7E,2CAA2C;AAC3C,EAAE;AACF,0EAA0E;AAC1E,wEAAwE;AACxE,0EAA0E;AAC1E,mCAAmC;AACnC,EAAE;AACF,6EAA6E;AAC7E,oEAAoE;AACpE,wBAAwB;AACxB,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF,gFAAgF;AAChF,gFAAgF;AAChF,iFAAiF;AACjF,EAAE;AACF,4EAA4E;AAC5E,2EAA2E;AAC3E,+DAA+D;AAC/D,OAAO,EACL,oBAAoB,GAKrB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAwB,MAAM,SAAS,CAAA;AAC7E,OAAO,EAAE,MAAM,EAAE,aAAa,EAAuB,MAAM,UAAU,CAAA;AAmFrE,MAAM,MAAM,GAAG,6BAA6B,CAAA;AAI5C,MAAM,IAAI,GAAG,CAAC,IAAmB,EAAc,EAAE,CAC/C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,IAAa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K,GAAG,IAAI,CAAC,GAAG;YACxC,CAAC,CAAC,IAAI,CAAC,GAAG;YACV,CAAC,CAAC,IAAI,CAAC,GAAG,KAAK,SAAS,IAAI,KAAK,GAAG,IAAI,CAAC,GAAG;gBAC1C,CAAC,CAAC,IAAI,CAAC,GAAG;gBACV,CAAC,CAAC,KAAK,CAAA;QACb,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;IAC/B,CAAC,CAAC,CAAA;IACF,OAAO,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;AACtD,CAAC,CAAA","sourcesContent":["// `withTiming` / `withSpring` / `withDelay` / `withSequence` / `withRepeat`.\n//\n// Upstream types these as returning the animated type itself\n// (`withTiming(100)` is a `number`), because what starts the animation is\n// ASSIGNING the result to a shared value. The cast at each return mirrors\n// that trick rather than inventing a different API — see `mutable.ts`, which\n// recognises the descriptor in its setter.\n//\n// The descriptors are plain data. Turning one into a running animation is\n// `buildAnimation`, and it builds on the platform's own `src/animated/`\n// engine: same frame scheduler, same closed-form solvers, same preemption\n// rules. This layer adds no clock.\n//\n// It does NOT reuse `Animated.timing`/`Animated.spring`'s DEFAULTS, and that\n// distinction is load-bearing. Reanimated's defaults are materially\n// different animations:\n//\n// | config | RN Animated | Reanimated 4 |\n// | --------------- | ------------------------ | -------------------------- |\n// | timing duration | 500 ms | 300 ms |\n// | timing easing | inOut(ease) | inOut(quad) |\n// | spring | damping 10, mass 1, k 100 | damping 120, mass 4, k 900 |\n//\n// The spring row is not a tuning difference: RN's default has damping ratio\n// 0.5 and visibly bounces, Reanimated 4's is exactly critically damped and\n// does not. Every config below is therefore passed explicitly.\nimport {\n createValueAnimation,\n type AnimatedApi,\n type AnimatedValue,\n type CompositeAnimation,\n type FrameScheduler,\n} from \"../animated/index\"\nimport { decayStep, resolveDecayConfig, type WithDecayConfig } from \"./decay\"\nimport { Easing, resolveEasing, type EasingFunction } from \"./easing\"\n\n/** Called when an animation settles or is cancelled, as upstream. */\nexport type AnimationCallback = (finished?: boolean, current?: number) => void\n\nexport type WithTimingConfig = {\n duration?: number\n easing?: EasingFunction | { factory: () => EasingFunction }\n}\n\n/**\n * Upstream's config is a mutually exclusive union: either the physical\n * parameterisation (`stiffness`/`damping`) or the perceptual one\n * (`duration`/`dampingRatio`). Both are accepted here and normalised into the\n * physical one, which is what the platform's spring solver takes.\n */\nexport type WithSpringConfig = {\n mass?: number\n stiffness?: number\n damping?: number\n duration?: number\n dampingRatio?: number\n clamp?: { min?: number; max?: number }\n velocity?: number\n overshootClamping?: boolean\n energyThreshold?: number\n}\n\ntype TimingSpec = {\n kind: \"timing\"\n toValue: number\n config: WithTimingConfig\n callback?: AnimationCallback\n}\n\ntype SpringSpec = {\n kind: \"spring\"\n toValue: number\n config: WithSpringConfig\n callback?: AnimationCallback\n}\n\ntype DelaySpec = {\n kind: \"delay\"\n delayMs: number\n animation: AnimationSpec\n}\n\ntype SequenceSpec = {\n kind: \"sequence\"\n animations: AnimationSpec[]\n}\n\ntype RepeatSpec = {\n kind: \"repeat\"\n animation: AnimationSpec\n numberOfReps: number\n reverse: boolean\n callback?: AnimationCallback\n}\n\ntype DecaySpec = {\n kind: \"decay\"\n config: ReturnType<typeof resolveDecayConfig>\n callback?: AnimationCallback\n}\n\ntype ClampSpec = {\n kind: \"clamp\"\n min?: number\n max?: number\n animation: AnimationSpec\n}\n\nexport type AnimationSpec =\n | TimingSpec\n | SpringSpec\n | DelaySpec\n | SequenceSpec\n | RepeatSpec\n | DecaySpec\n | ClampSpec\n\nconst MARKER = \"__rnGtkxReanimatedAnimation\"\n\ntype MarkedSpec = AnimationSpec & { [MARKER]: true }\n\nconst mark = (spec: AnimationSpec): MarkedSpec =>\n Object.assign(spec, { [MARKER]: true as const })\n\nexport const isAnimationSpec = (value: unknown): value is AnimationSpec =>\n typeof value === \"object\" &&\n value !== null &&\n (value as Record<string, unknown>)[MARKER] === true\n\n// --- the initial run ----------------------------------------------------\n//\n// Upstream's `IN_STYLE_UPDATER`, and it is not a detail: the FIRST evaluation\n// of a `useDerivedValue`/`useAnimatedStyle`/`useAnimatedProps` updater has no\n// value to animate FROM, so every `with*` builder returns its target instead\n// of an animation. `defineAnimation` does it in one line —\n// `if (IN_STYLE_UPDATER.current) return starting` — and that line is what\n// makes the documented pattern\n//\n// const v = useDerivedValue(() => withSpring(active.value ? 1 : 0))\n//\n// work at all. Without it the shared value is SEEDED with the animation\n// object itself and every later write finds a value that is not a number.\n// Found by building `react-native-draggable-flatlist`, whose `ScaleDecorator`\n// is exactly that pattern (`hooks/useOnCellActiveAnimation.ts`).\nlet inInitialRun = false\n\n/**\n * Runs an updater in \"seed the value\" mode, where every animation collapses\n * to the value it would have finished at.\n */\nexport const initialUpdaterRun = <T>(updater: () => T): T => {\n inInitialRun = true\n try {\n return updater()\n } finally {\n inInitialRun = false\n }\n}\n\n// Upstream's own defaults, quoted in the table at the top of this file.\nconst DEFAULT_TIMING_DURATION = 300\nconst defaultTimingEasing = Easing.inOut(Easing.quad)\n\n// GentleSpringConfig + energyThreshold, react-native-reanimated 4.5.3\n// (src/animation/spring/springConfigs.ts).\nconst DEFAULT_SPRING_MASS = 4\nconst DEFAULT_SPRING_STIFFNESS = 900\nconst DEFAULT_SPRING_DAMPING = 120\nconst DEFAULT_SPRING_DURATION = 550\nconst DEFAULT_SPRING_DAMPING_RATIO = 1\nconst DEFAULT_ENERGY_THRESHOLD = 6e-9\n\nconst assertAnimatable = (value: unknown, api: string): number => {\n if (typeof value !== \"number\" || !Number.isFinite(value)) {\n throw new Error(\n `react-native-reanimated: ${api}() on this platform animates finite numbers only, got ${typeof value === \"string\" ? `\"${value}\"` : String(value)}. ` +\n \"Colors and layout properties cannot be driven imperatively here yet — see docs/api.md.\",\n )\n }\n return value\n}\n\n/**\n * Lets you animate a value over a duration with an easing curve. Assign the\n * result to a shared value to start it.\n */\nexport const withTiming = (\n toValue: number,\n config?: WithTimingConfig,\n callback?: AnimationCallback,\n): number =>\n inInitialRun\n ? assertAnimatable(toValue, \"withTiming\")\n : (mark({\n kind: \"timing\",\n toValue: assertAnimatable(toValue, \"withTiming\"),\n config: config ?? {},\n callback,\n }) as unknown as number)\n\n/** Lets you animate a value with spring physics. */\nexport const withSpring = (\n toValue: number,\n config?: WithSpringConfig,\n callback?: AnimationCallback,\n): number =>\n inInitialRun\n ? assertAnimatable(toValue, \"withSpring\")\n : (mark({\n kind: \"spring\",\n toValue: assertAnimatable(toValue, \"withSpring\"),\n config: config ?? {},\n callback,\n }) as unknown as number)\n\n/** Delays another animation by `delayMs`. */\nexport const withDelay = (delayMs: number, animation: number): number => {\n // Upstream's `starting` for every composite is the animation it wraps,\n // which the initial run has already collapsed to a plain value.\n if (inInitialRun) {\n return animation\n }\n if (!isAnimationSpec(animation)) {\n throw new Error(\n \"react-native-reanimated: withDelay() takes an animation, e.g. withDelay(500, withTiming(1))\",\n )\n }\n return mark({\n kind: \"delay\",\n delayMs,\n animation,\n }) as unknown as number\n}\n\n/** Runs animations one after another on the same shared value. */\nexport const withSequence = (...animations: number[]): number => {\n if (inInitialRun) {\n return animations[0] ?? 0\n }\n const specs: AnimationSpec[] = []\n for (const animation of animations) {\n if (!isAnimationSpec(animation)) {\n throw new Error(\n \"react-native-reanimated: withSequence() takes animations, e.g. withSequence(withTiming(1), withTiming(0))\",\n )\n }\n specs.push(animation)\n }\n return mark({ kind: \"sequence\", animations: specs }) as unknown as number\n}\n\n/**\n * Repeats an animation. `numberOfReps <= 0` repeats forever; `reverse` plays\n * every other repetition backwards.\n */\nexport const withRepeat = (\n animation: number,\n numberOfReps = 2,\n reverse = false,\n callback?: AnimationCallback,\n): number => {\n if (inInitialRun) {\n return animation\n }\n if (!isAnimationSpec(animation)) {\n throw new Error(\n \"react-native-reanimated: withRepeat() takes an animation, e.g. withRepeat(withTiming(1), 3)\",\n )\n }\n return mark({\n kind: \"repeat\",\n animation,\n numberOfReps,\n reverse,\n callback,\n }) as unknown as number\n}\n\n/**\n * Coasts to a stop from an initial velocity — the release half of a fling.\n * Unlike every other animation here it has no target: where it lands is the\n * result of the velocity and the friction, which is exactly what makes it the\n * one an inertial gesture needs.\n *\n * ```tsx\n * onPanResponderRelease: (_, g) => {\n * x.value = withDecay({ velocity: g.vx * 1000, clamp: [0, width] })\n * }\n * ```\n *\n * `velocity` is in units per SECOND, as upstream — `PanResponder`'s\n * `gestureState.vx` is per millisecond, so it wants the ×1000 above.\n */\nexport const withDecay = (\n config?: WithDecayConfig,\n callback?: AnimationCallback,\n): number =>\n inInitialRun\n ? // Upstream seeds a decay with 0: it has no target to collapse to.\n 0\n : (mark({\n kind: \"decay\",\n config: resolveDecayConfig(config),\n callback,\n }) as unknown as number)\n\n/**\n * Confines another animation to a range: the inner animation runs its own\n * un-truncated course and what reaches the value is clipped to `[min, max]`.\n * That distinction is upstream's and it is observable — a spring clamped at\n * 100 that would have overshot to 120 sits at 100 and then comes back down,\n * rather than settling at 100 the moment it first arrives.\n */\nexport const withClamp = (\n config: { min?: number; max?: number },\n animation: number,\n): number => {\n if (inInitialRun) {\n return animation\n }\n if (!isAnimationSpec(animation)) {\n throw new Error(\n \"react-native-reanimated: withClamp() takes an animation, e.g. withClamp({ min: 0 }, withSpring(1))\",\n )\n }\n if (\n config.min !== undefined &&\n config.max !== undefined &&\n config.max < config.min\n ) {\n throw new Error(\n `react-native-reanimated: withClamp() was given min ${config.min} above max ${config.max}.`,\n )\n }\n return mark({\n kind: \"clamp\",\n min: config.min,\n max: config.max,\n animation,\n }) as unknown as number\n}\n\nexport type { WithDecayConfig } from \"./decay\"\n\n// --- spring config normalisation ----------------------------------------\n\nconst bisect = (\n min: number,\n max: number,\n fn: (x: number) => number,\n precision: number,\n maxIterations = 100,\n): number => {\n let low = min\n let high = max\n const direction = fn(high) >= fn(low) ? 1 : -1\n let current = (low + high) / 2\n for (let i = 0; i < maxIterations && Math.abs(fn(current)) > precision; i++) {\n if (fn(current) * direction < 0) {\n low = current\n } else {\n high = current\n }\n current = (low + high) / 2\n }\n return current\n}\n\nconst energyOf = (\n displacement: number,\n velocity: number,\n stiffness: number,\n mass: number,\n): number => 0.5 * stiffness * displacement ** 2 + 0.5 * mass * velocity ** 2\n\n/**\n * Solves for the stiffness whose settling time matches a requested perceptual\n * duration, by bisection on the fraction of the initial energy left after\n * 1.5 × that duration. Ported from upstream's\n * `calculateNewStiffnessToMatchDuration` — the perceptual-duration spring is\n * a Reanimated concept with no RN equivalent, so there is nothing on the\n * platform side to reuse.\n */\nconst stiffnessForDuration = (\n x0: number,\n v0: number,\n durationMs: number,\n dampingRatio: number,\n mass: number,\n energyThreshold: number,\n): number => {\n const PERCEPTUAL_COEFFICIENT = 1.5\n const settlingSeconds = (durationMs * PERCEPTUAL_COEFFICIENT) / 1000\n const initialEnergyFor = (stiffness: number): number =>\n energyOf(x0, v0, stiffness, mass)\n\n const energyFractionLeft = (stiffness: number): number => {\n const decay = Math.sqrt(stiffness / mass) * dampingRatio\n const envelope = Math.exp(-decay * settlingSeconds)\n const displacement = (x0 + (v0 + x0 * decay) * settlingSeconds) * envelope\n const velocity = displacement * -decay + (v0 + x0 * decay) * envelope\n const initial = initialEnergyFor(stiffness)\n if (initial === 0) {\n return -energyThreshold\n }\n return (\n energyOf(displacement, velocity, stiffness, mass) / initial -\n energyThreshold\n )\n }\n\n return bisect(\n Number.EPSILON,\n // Upstream's bound: even an 8 ms spring stays under 2e3, with margin.\n 8e3,\n energyFractionLeft,\n energyThreshold * 1e-3,\n )\n}\n\n/**\n * Keeps the overshoot inside `clamp` by raising the damping ratio, using\n * upstream's approximation: the first two extrema of a damped oscillation sit\n * at `exp(-zeta * PI)` and `exp(-zeta * 2 * PI)` of the initial displacement,\n * so the zeta that puts them on the bound is a logarithm away.\n */\nconst zetaForClamp = (\n zeta: number,\n startDisplacement: number,\n toValue: number,\n clamp: { min?: number; max?: number },\n): number => {\n if (startDisplacement === 0) {\n return zeta\n }\n const [firstBound, secondBound] =\n startDisplacement <= 0 ? [clamp.min, clamp.max] : [clamp.max, clamp.min]\n const candidates = [zeta]\n if (secondBound !== undefined) {\n const extremum = Math.abs((secondBound - toValue) / startDisplacement)\n candidates.push(Math.abs(Math.log(extremum) / Math.PI))\n }\n if (firstBound !== undefined) {\n const extremum = Math.abs((firstBound - toValue) / startDisplacement)\n candidates.push(Math.abs(Math.log(extremum) / (2 * Math.PI)))\n }\n // Bigger zeta means smaller bounces, so the strictest candidate wins.\n return Math.max(...candidates)\n}\n\ntype PlatformSpringConfig = {\n toValue: number\n mass: number\n stiffness: number\n damping: number\n initialVelocity: number\n overshootClamping: boolean\n restDisplacementThreshold: number\n restSpeedThreshold: number\n}\n\n/**\n * Turns a Reanimated spring config into the platform solver's config.\n *\n * The rest condition is the one place the two genuinely differ. Upstream\n * stops when the oscillator's remaining energy falls to `energyThreshold` of\n * its initial energy — a RELATIVE criterion; the platform's solver stops on\n * absolute displacement and speed thresholds. Rather than accept RN's\n * absolute defaults (which would end a 400px spring at a different point than\n * a 4px one), the thresholds are derived per animation from the same energy\n * budget, so the stopping point tracks upstream's to well under a pixel.\n */\nexport const toPlatformSpringConfig = (\n config: WithSpringConfig,\n toValue: number,\n from: number,\n): PlatformSpringConfig => {\n const mass = config.mass ?? DEFAULT_SPRING_MASS\n const velocity = config.velocity ?? 0\n const energyThreshold = config.energyThreshold ?? DEFAULT_ENERGY_THRESHOLD\n const useDuration =\n config.duration !== undefined || config.dampingRatio !== undefined\n\n const displacement = from - toValue\n\n let stiffness: number\n let zeta: number\n if (useDuration) {\n const duration = config.duration ?? DEFAULT_SPRING_DURATION\n zeta = config.dampingRatio ?? DEFAULT_SPRING_DAMPING_RATIO\n stiffness =\n duration <= 0\n ? Number.POSITIVE_INFINITY\n : stiffnessForDuration(\n displacement,\n velocity,\n duration,\n zeta,\n mass,\n energyThreshold,\n )\n } else {\n stiffness = config.stiffness ?? DEFAULT_SPRING_STIFFNESS\n const damping = config.damping ?? DEFAULT_SPRING_DAMPING\n zeta = damping / (2 * Math.sqrt(stiffness * mass))\n }\n\n if (config.clamp) {\n zeta = zetaForClamp(zeta, displacement, toValue, config.clamp)\n }\n\n // A zero/degenerate duration means \"be there already\"; the platform solver\n // rejects a non-finite stiffness, so collapse it to a 0 ms timing instead.\n const resolvedStiffness = Number.isFinite(stiffness)\n ? Math.max(stiffness, Number.EPSILON)\n : 1e6\n\n const initialEnergy = energyOf(\n displacement,\n velocity,\n resolvedStiffness,\n mass,\n )\n const restEnergy = energyThreshold * initialEnergy\n\n return {\n toValue,\n mass,\n stiffness: resolvedStiffness,\n damping: Math.max(\n zeta * 2 * Math.sqrt(resolvedStiffness * mass),\n Number.EPSILON,\n ),\n initialVelocity: velocity,\n overshootClamping: config.overshootClamping ?? false,\n // Semi-axes of the energy ellipse: |x| where all the remaining energy is\n // potential, |v| where all of it is kinetic. A spring at rest is inside\n // both.\n restDisplacementThreshold: Math.max(\n Math.sqrt((2 * restEnergy) / resolvedStiffness),\n Number.MIN_VALUE,\n ),\n restSpeedThreshold: Math.max(\n Math.sqrt((2 * restEnergy) / mass),\n Number.MIN_VALUE,\n ),\n }\n}\n\n// --- building a running animation ---------------------------------------\n\n/**\n * The last value an animation aims at, used by `withRepeat`'s reverse and by\n * `updater-animations.ts` to seed a key that is animating for the first time.\n */\nexport const targetOf = (spec: AnimationSpec): number | null => {\n switch (spec.kind) {\n case \"timing\":\n case \"spring\":\n return spec.toValue\n case \"delay\":\n return targetOf(spec.animation)\n case \"sequence\": {\n const last = spec.animations[spec.animations.length - 1]\n return last ? targetOf(last) : null\n }\n case \"repeat\":\n return targetOf(spec.animation)\n case \"clamp\":\n return targetOf(spec.animation)\n // A decay has no target by construction — where it lands is the result\n // rather than the input. `withRepeat(withDecay(...))` therefore replays\n // from the same origin rather than ping-ponging between two.\n case \"decay\":\n return null\n }\n}\n\n/** A copy of `spec` aimed at `toValue`, for a reversed repetition. */\nconst aimedAt = (spec: AnimationSpec, toValue: number): AnimationSpec => {\n switch (spec.kind) {\n case \"timing\":\n case \"spring\":\n return { ...spec, toValue }\n case \"delay\":\n return { ...spec, animation: aimedAt(spec.animation, toValue) }\n case \"sequence\": {\n const animations = [...spec.animations]\n const lastIndex = animations.length - 1\n const last = animations[lastIndex]\n if (last) {\n animations[lastIndex] = aimedAt(last, toValue)\n }\n return { ...spec, animations }\n }\n case \"repeat\":\n return { ...spec, animation: aimedAt(spec.animation, toValue) }\n case \"clamp\":\n return { ...spec, animation: aimedAt(spec.animation, toValue) }\n // Nothing to re-aim: see targetOf.\n case \"decay\":\n return spec\n }\n}\n\n/**\n * What makes two descriptors the SAME animation, for a caller that gets a\n * freshly built one on every evaluation and must decide whether to restart.\n *\n * The target and the shape, not object identity and not the whole config: a\n * mapper re-runs whenever anything it read changed, so `withSpring(open.value\n * ? 320 : 0)` produces a new object many times a second while asking for the\n * same animation every time. Config fields that change WHERE the animation\n * ends are in (a `duration`, a decay's `velocity`); ones that only change how\n * it gets there are not, because re-aiming a running animation at the value it\n * is already aimed at is a no-op that costs a restart.\n */\nexport const animationSignature = (spec: AnimationSpec): string => {\n switch (spec.kind) {\n case \"timing\":\n return `timing(${spec.toValue},${spec.config.duration ?? \"\"})`\n case \"spring\":\n return `spring(${spec.toValue})`\n case \"delay\":\n return `delay(${spec.delayMs},${animationSignature(spec.animation)})`\n case \"sequence\":\n return `sequence(${spec.animations.map(animationSignature).join(\";\")})`\n case \"repeat\":\n return `repeat(${spec.numberOfReps},${spec.reverse},${animationSignature(spec.animation)})`\n case \"clamp\":\n return `clamp(${spec.min},${spec.max},${animationSignature(spec.animation)})`\n // A decay has no target (targetOf), so its identity is the push it was\n // given: a new flick is a new animation, the same flick is not.\n case \"decay\":\n return `decay(${spec.config.velocity},${spec.config.deceleration})`\n }\n}\n\nconst callbackOf = (spec: AnimationSpec): AnimationCallback | undefined =>\n spec.kind === \"timing\" ||\n spec.kind === \"spring\" ||\n spec.kind === \"repeat\" ||\n spec.kind === \"decay\"\n ? spec.callback\n : undefined\n\n/**\n * Fires the descriptor's own callback when its animation settles — including\n * when it is cancelled, which reports `finished: false`, as upstream does.\n * Every node carries one, so the per-child callbacks of a `withSequence` and\n * the per-repetition callbacks of a `withRepeat` fire without the caller\n * having to unpick the tree.\n */\nconst reportingTo = (\n animation: CompositeAnimation,\n callback: AnimationCallback | undefined,\n driver: AnimatedValue,\n): CompositeAnimation =>\n callback\n ? {\n start: (onEnd) => {\n animation.start((result) => {\n callback(result.finished, driver.__getValue())\n onEnd?.(result)\n })\n },\n stop: () => animation.stop(),\n reset: () => animation.reset(),\n }\n : animation\n\n/**\n * What a descriptor needs to become a running animation: the platform's\n * Animated api for the animations it already has, and the frame scheduler\n * behind it for the one it does not (`withDecay` — see decay.ts). Both come\n * from the same place, so there is still exactly one clock under this layer.\n */\nexport type AnimationEngine = {\n api: AnimatedApi\n scheduler: FrameScheduler\n}\n\nconst buildRepeat = (\n engine: AnimationEngine,\n driver: AnimatedValue,\n spec: RepeatSpec,\n): CompositeAnimation => {\n let child: CompositeAnimation | null = null\n let cancelled = false\n\n return {\n start(onEnd) {\n cancelled = false\n const origin = driver.__getValue()\n let from = origin\n let to = targetOf(spec.animation) ?? origin\n let completed = 0\n\n const runIteration = (): void => {\n child = buildAnimation(engine, driver, aimedAt(spec.animation, to))\n child.start((result) => {\n if (cancelled || !result.finished) {\n onEnd?.(result)\n return\n }\n completed += 1\n if (spec.numberOfReps > 0 && completed >= spec.numberOfReps) {\n onEnd?.({ finished: true })\n return\n }\n if (spec.reverse) {\n // Ping-pong: the value is already at `to`, so the next\n // repetition simply aims back at where this one started.\n const previousTarget = to\n to = from\n from = previousTarget\n } else {\n // Replay: snap back to where the repeat began and run again,\n // which is what upstream's onStart(startValue) amounts to.\n driver.setValue(from)\n }\n runIteration()\n })\n }\n\n runIteration()\n },\n stop() {\n cancelled = true\n child?.stop()\n },\n reset() {\n child?.reset()\n },\n }\n}\n\n/**\n * Turns a descriptor into a running animation on `driver`. Every leaf is one\n * of the platform's own animations, so the whole tree runs off the single\n * injected frame scheduler.\n */\nexport const buildAnimation = (\n engine: AnimationEngine,\n driver: AnimatedValue,\n spec: AnimationSpec,\n): CompositeAnimation => {\n const { api, scheduler } = engine\n const build = (): CompositeAnimation => {\n switch (spec.kind) {\n case \"timing\":\n return api.timing(driver, {\n toValue: spec.toValue,\n duration: spec.config.duration ?? DEFAULT_TIMING_DURATION,\n easing: spec.config.easing\n ? resolveEasing(spec.config.easing)\n : defaultTimingEasing,\n })\n case \"spring\":\n return api.spring(\n driver,\n toPlatformSpringConfig(\n spec.config,\n spec.toValue,\n driver.__getValue(),\n ),\n )\n case \"delay\":\n return api.sequence([\n api.delay(spec.delayMs),\n buildAnimation(engine, driver, spec.animation),\n ])\n case \"sequence\":\n return api.sequence(\n spec.animations.map((child) => buildAnimation(engine, driver, child)),\n )\n case \"repeat\":\n return buildRepeat(engine, driver, spec)\n case \"decay\":\n return createValueAnimation(scheduler, driver, decayStep(spec.config))\n case \"clamp\":\n return buildClamp(engine, driver, spec)\n }\n }\n return reportingTo(build(), callbackOf(spec), driver)\n}\n\n/**\n * `withClamp` in full: the inner animation is built on a PRIVATE value and\n * what that value publishes is clipped onto the real driver. Running it\n * un-truncated is the whole behaviour — upstream keeps the clamped animation's\n * own `current` unbounded for exactly this reason — and the private node costs\n * one listener, no extra frame subscription and no second clock, because the\n * inner animation is an ordinary one built by the same function.\n */\nconst buildClamp = (\n engine: AnimationEngine,\n driver: AnimatedValue,\n spec: ClampSpec,\n): CompositeAnimation => {\n const inner = new engine.api.Value(driver.__getValue())\n inner.addListener(({ value }) => {\n const clipped =\n spec.max !== undefined && value > spec.max\n ? spec.max\n : spec.min !== undefined && value < spec.min\n ? spec.min\n : value\n driver.__updateValue(clipped)\n })\n return buildAnimation(engine, inner, spec.animation)\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Upstream's shape: red, green, blue and alpha, each normalised to 0-1. */
|
|
2
|
+
export type ParsedColorArray = [number, number, number, number];
|
|
3
|
+
/** Upstream's `InterpolationOptions`, with upstream's defaults. */
|
|
4
|
+
export type ColorInterpolationOptions = {
|
|
5
|
+
/** Gamma used for the RGB colour space. Defaults to `2.2`. */
|
|
6
|
+
gamma?: number;
|
|
7
|
+
/** Wrap hues the short way round. Defaults to `true`. */
|
|
8
|
+
useCorrectedHSVInterpolation?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type ColorSpace = "RGB" | "HSV";
|
|
11
|
+
/** True for a string this platform can turn into a colour. Upstream's contract: numbers are not colours. */
|
|
12
|
+
export declare const isColor: (value: unknown) => value is string;
|
|
13
|
+
/**
|
|
14
|
+
* A colour as four 0-1 channels. Alpha is quantised to eighths-of-a-percent
|
|
15
|
+
* (n/255) exactly as upstream's is, because upstream reads it back out of an
|
|
16
|
+
* 8-bit packed integer and callers compare against those values.
|
|
17
|
+
*/
|
|
18
|
+
export declare const convertToRGBA: (color: unknown) => ParsedColorArray;
|
|
19
|
+
/** The inverse of {@link convertToRGBA}, in upstream's output format. */
|
|
20
|
+
export declare const rgbaArrayToRGBAColor: (rgba: ParsedColorArray) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Maps `value` from `inputRange` onto a range of colours, returning
|
|
23
|
+
* `rgba(r, g, b, a)`.
|
|
24
|
+
*
|
|
25
|
+
* Outside `inputRange` the result is clamped to the nearest end, as upstream
|
|
26
|
+
* does — colour has no meaningful extrapolation.
|
|
27
|
+
*/
|
|
28
|
+
export declare const interpolateColor: (value: number, inputRange: readonly number[], outputRange: readonly string[], colorSpace?: ColorSpace, options?: ColorInterpolationOptions) => string;
|