UNPKG

4.42 kBTypeScriptView Raw
1import type { Animation, AnimatableValue, Timestamp, ReduceMotion } from '../commonTypes';
2/**
3 * Spring animation configuration.
4 *
5 * @param mass - The weight of the spring. Reducing this value makes the
6 * animation faster. Defaults to 1.
7 * @param damping - How quickly a spring slows down. Higher damping means the
8 * spring will come to rest faster. Defaults to 10.
9 * @param duration - Length of the animation (in milliseconds). Defaults to
10 * 2000.
11 * @param dampingRatio - How damped the spring is. Value 1 means the spring is
12 * critically damped, and value `>`1 means the spring is overdamped. Defaults
13 * to 0.5.
14 * @param stiffness - How bouncy the spring is. Defaults to 100.
15 * @param velocity - Initial velocity applied to the spring equation. Defaults
16 * to 0.
17 * @param overshootClamping - Whether a spring can bounce over the `toValue`.
18 * Defaults to false.
19 * @param restDisplacementThreshold - The displacement below which the spring
20 * will snap to toValue without further oscillations. Defaults to 0.01.
21 * @param restSpeedThreshold - The speed in pixels per second from which the
22 * spring will snap to toValue without further oscillations. Defaults to 2.
23 * @param reduceMotion - Determines how the animation responds to the device's
24 * reduced motion accessibility setting. Default to `ReduceMotion.System` -
25 * {@link ReduceMotion}.
26 * @see https://docs.swmansion.com/react-native-reanimated/docs/animations/withSpring/#config-
27 */
28export type SpringConfig = {
29 stiffness?: number;
30 overshootClamping?: boolean;
31 restDisplacementThreshold?: number;
32 restSpeedThreshold?: number;
33 velocity?: number;
34 reduceMotion?: ReduceMotion;
35} & ({
36 mass?: number;
37 damping?: number;
38 duration?: never;
39 dampingRatio?: never;
40 clamp?: never;
41} | {
42 mass?: never;
43 damping?: never;
44 duration?: number;
45 dampingRatio?: number;
46 clamp?: {
47 min?: number;
48 max?: number;
49 };
50});
51export type DefaultSpringConfig = {
52 [K in keyof Required<SpringConfig>]: K extends 'reduceMotion' | 'clamp' ? Required<SpringConfig>[K] | undefined : Required<SpringConfig>[K];
53};
54export type WithSpringConfig = SpringConfig;
55export interface SpringConfigInner {
56 useDuration: boolean;
57 skipAnimation: boolean;
58}
59export interface SpringAnimation extends Animation<SpringAnimation> {
60 current: AnimatableValue;
61 toValue: AnimatableValue;
62 velocity: number;
63 lastTimestamp: Timestamp;
64 startTimestamp: Timestamp;
65 startValue: number;
66 zeta: number;
67 omega0: number;
68 omega1: number;
69}
70export interface InnerSpringAnimation extends Omit<SpringAnimation, 'toValue' | 'current'> {
71 toValue: number;
72 current: number;
73}
74export declare function checkIfConfigIsValid(config: DefaultSpringConfig): boolean;
75export declare function bisectRoot({ min, max, func, maxIterations, }: {
76 min: number;
77 max: number;
78 func: (x: number) => number;
79 maxIterations?: number;
80}): number;
81export declare function initialCalculations(mass: number | undefined, config: DefaultSpringConfig & SpringConfigInner): {
82 zeta: number;
83 omega0: number;
84 omega1: number;
85};
86/**
87 * We make an assumption that we can manipulate zeta without changing duration
88 * of movement. According to theory this change is small and tests shows that we
89 * can indeed ignore it.
90 */
91export declare function scaleZetaToMatchClamps(animation: SpringAnimation, clamp: {
92 min?: number;
93 max?: number;
94}): number;
95/** Runs before initial */
96export declare function calculateNewMassToMatchDuration(x0: number, config: DefaultSpringConfig & SpringConfigInner, v0: number): number;
97export declare function criticallyDampedSpringCalculations(animation: InnerSpringAnimation, precalculatedValues: {
98 v0: number;
99 x0: number;
100 omega0: number;
101 t: number;
102}): {
103 position: number;
104 velocity: number;
105};
106export declare function underDampedSpringCalculations(animation: InnerSpringAnimation, precalculatedValues: {
107 zeta: number;
108 v0: number;
109 x0: number;
110 omega0: number;
111 omega1: number;
112 t: number;
113}): {
114 position: number;
115 velocity: number;
116};
117export declare function isAnimationTerminatingCalculation(animation: InnerSpringAnimation, config: DefaultSpringConfig): {
118 isOvershooting: boolean;
119 isVelocity: boolean;
120 isDisplacement: boolean;
121};
122//# sourceMappingURL=springUtils.d.ts.map
\No newline at end of file