react-ui-animate 4.1.1 → 4.2.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/README.md +55 -43
- package/dist/animation/controllers/index.d.ts +2 -2
- package/dist/animation/controllers/withDecay.d.ts +9 -5
- package/dist/animation/controllers/withDelay.d.ts +4 -6
- package/dist/animation/controllers/withEase.d.ts +6 -4
- package/dist/animation/controllers/withLoop.d.ts +8 -2
- package/dist/animation/controllers/withNative.d.ts +5 -0
- package/dist/animation/controllers/withSequence.d.ts +8 -2
- package/dist/animation/controllers/withSpring.d.ts +10 -5
- package/dist/animation/controllers/withTiming.d.ts +9 -5
- package/dist/animation/helpers/animationType.d.ts +59 -55
- package/dist/animation/helpers/getToValue.d.ts +2 -2
- package/dist/animation/helpers/index.d.ts +1 -3
- package/dist/animation/hooks/index.d.ts +1 -1
- package/dist/animation/hooks/useMount.d.ts +6 -11
- package/dist/animation/hooks/useValue.d.ts +3 -13
- package/dist/animation/hooks/useValues.d.ts +3 -4
- package/dist/animation/index.d.ts +4 -4
- package/dist/animation/modules/MountedBlock.d.ts +4 -13
- package/dist/animation/modules/ScrollableBlock.d.ts +2 -13
- package/dist/animation/modules/index.d.ts +0 -1
- package/dist/animation/types.d.ts +16 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/dist/animation/controllers/withConfig.d.ts +0 -5
- package/dist/animation/core/FluidArrayController.d.ts +0 -7
- package/dist/animation/core/FluidController.d.ts +0 -34
- package/dist/animation/core/useFluidValue.d.ts +0 -3
- package/dist/animation/core/useFluidValues.d.ts +0 -3
- package/dist/animation/core/useMount.d.ts +0 -18
- package/dist/animation/helpers/delay.d.ts +0 -5
- package/dist/animation/helpers/isDefined.d.ts +0 -1
- package/dist/animation/modules/TransitionBlock.d.ts +0 -18
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
### Install
|
|
8
8
|
|
|
9
|
-
You can install react-ui-animate via npm or yarn
|
|
9
|
+
You can install react-ui-animate via `npm` or `yarn`:
|
|
10
10
|
|
|
11
11
|
```sh
|
|
12
12
|
npm i react-ui-animate
|
|
@@ -24,15 +24,13 @@ The `react-ui-animate` library provides a straightforward way to add animations
|
|
|
24
24
|
import { animate, useValue } from 'react-ui-animate';
|
|
25
25
|
|
|
26
26
|
export default function () {
|
|
27
|
-
|
|
28
|
-
const opacity = useValue(0);
|
|
27
|
+
const opacity = useValue(0); // Initialize
|
|
29
28
|
|
|
30
29
|
return (
|
|
31
|
-
|
|
32
|
-
{/* animate.div component uses the animated opacity value */}
|
|
30
|
+
<>
|
|
33
31
|
<animate.div
|
|
34
32
|
style={{
|
|
35
|
-
opacity: opacity.value, //
|
|
33
|
+
opacity: opacity.value, // Apply
|
|
36
34
|
width: 100,
|
|
37
35
|
padding: 20,
|
|
38
36
|
background: '#39F',
|
|
@@ -40,39 +38,40 @@ export default function () {
|
|
|
40
38
|
>
|
|
41
39
|
ANIMATED
|
|
42
40
|
</animate.div>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
|
|
42
|
+
<button
|
|
43
|
+
onClick={() => {
|
|
44
|
+
opacity.value = 1 // Update
|
|
45
|
+
}}
|
|
46
|
+
>
|
|
47
|
+
Animate Me
|
|
48
|
+
</button>
|
|
49
|
+
</>
|
|
47
50
|
);
|
|
48
51
|
}
|
|
49
52
|
```
|
|
50
53
|
|
|
51
|
-
In this example, clicking the
|
|
54
|
+
In this example, clicking the `Animate Me` button changes the opacity from 0 to 1.
|
|
55
|
+
|
|
56
|
+
---
|
|
52
57
|
|
|
53
|
-
###
|
|
58
|
+
### Implementation Steps
|
|
54
59
|
|
|
55
|
-
####
|
|
60
|
+
#### 1. Initialize
|
|
56
61
|
|
|
57
62
|
The `useValue()` hook is central to creating animations. It initializes an animated value and allows you to seamlessly update it to create dynamic effects.
|
|
58
63
|
|
|
59
64
|
```javascript
|
|
60
|
-
const opacity = useValue(0); //
|
|
61
|
-
|
|
62
|
-
// Use in style
|
|
63
|
-
style={{
|
|
64
|
-
opacity: opacity.value, // Access the animated opacity value
|
|
65
|
-
}}
|
|
66
|
-
|
|
67
|
-
// Update the value on user interaction
|
|
68
|
-
onClick={() => (opacity.value = 1)} // Changes the opacity to 1
|
|
65
|
+
const opacity = useValue(0); // Initialize a animation value 0
|
|
69
66
|
```
|
|
70
67
|
|
|
71
|
-
####
|
|
68
|
+
#### 2. Apply
|
|
72
69
|
|
|
73
70
|
`animate.div` is a special component designed to work with `useValue()`. It simplifies animating elements by directly using animated values.
|
|
74
71
|
|
|
75
|
-
```
|
|
72
|
+
```jsx
|
|
73
|
+
import { useValue, animate } from 'react-ui-animate'
|
|
74
|
+
|
|
76
75
|
const width = useValue(100); // Start with a width of 100
|
|
77
76
|
|
|
78
77
|
<animate.div
|
|
@@ -84,6 +83,29 @@ const width = useValue(100); // Start with a width of 100
|
|
|
84
83
|
/>;
|
|
85
84
|
```
|
|
86
85
|
|
|
86
|
+
#### 3. Update
|
|
87
|
+
|
|
88
|
+
To update the value simply assign the initialized animated node with a value.
|
|
89
|
+
|
|
90
|
+
```jsx
|
|
91
|
+
import { useValue, withSpring } from 'react-ui-animate';
|
|
92
|
+
|
|
93
|
+
const width = useValue(100);
|
|
94
|
+
|
|
95
|
+
<button
|
|
96
|
+
onClick={() => {
|
|
97
|
+
// Update
|
|
98
|
+
width.value = withSpring(400);
|
|
99
|
+
}}
|
|
100
|
+
>
|
|
101
|
+
Update
|
|
102
|
+
</button>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
In this example, `withSpring` runs spring animation when updating the value.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
87
109
|
#### `interpolate`
|
|
88
110
|
|
|
89
111
|
The `interpolate()` function is useful for mapping values from one range to another, enabling more complex animations.
|
|
@@ -91,7 +113,7 @@ The `interpolate()` function is useful for mapping values from one range to anot
|
|
|
91
113
|
```javascript
|
|
92
114
|
import { useValue, animate, interpolate } from 'react-ui-animate';
|
|
93
115
|
|
|
94
|
-
const width = useValue(100);
|
|
116
|
+
const width = useValue(100);
|
|
95
117
|
|
|
96
118
|
<animate.div
|
|
97
119
|
style={{
|
|
@@ -104,7 +126,7 @@ const width = useValue(100); // Start with a width of 100
|
|
|
104
126
|
|
|
105
127
|
In this example, as the width changes from 100 to 200, the background color smoothly transitions from red to blue.
|
|
106
128
|
|
|
107
|
-
####
|
|
129
|
+
#### Modifiers
|
|
108
130
|
|
|
109
131
|
You can dynamically modify animation configurations by assigning values to an animated value using various animation functions.
|
|
110
132
|
|
|
@@ -123,17 +145,9 @@ x.value = withTiming(10, { duration: 5000 });
|
|
|
123
145
|
To create sequential transitions using the `withSequence` function with dynamic modifiers like `withSpring` and `withTiming`:
|
|
124
146
|
|
|
125
147
|
```jsx
|
|
126
|
-
x.value = withSequence([withSpring(50), withTiming(100), 200]);
|
|
148
|
+
x.value = withSequence([withSpring(50), withTiming(100), withEase(200)]);
|
|
127
149
|
```
|
|
128
150
|
|
|
129
|
-
To delay an animation using the withDelay function:
|
|
130
|
-
|
|
131
|
-
```jsx
|
|
132
|
-
x.value = withDelay(1000, withSpring(100));
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
In this example, a spring animation to `100` will be applied after a 1-second delay.
|
|
136
|
-
|
|
137
151
|
#### `useMount()`
|
|
138
152
|
|
|
139
153
|
The `useMount()` hook facilitates managing the mounting and unmounting of a component with animations.
|
|
@@ -144,11 +158,7 @@ import { useMount } from 'react-ui-animate';
|
|
|
144
158
|
export default function App() {
|
|
145
159
|
const [visible, setVisible] = useState(false);
|
|
146
160
|
|
|
147
|
-
const open = useMount(visible
|
|
148
|
-
from: 0,
|
|
149
|
-
enter: 1,
|
|
150
|
-
exit: 0,
|
|
151
|
-
});
|
|
161
|
+
const open = useMount(visible);
|
|
152
162
|
|
|
153
163
|
return open((animation, mounted) => mounted && <animate.div />);
|
|
154
164
|
}
|
|
@@ -160,6 +170,8 @@ In this example,
|
|
|
160
170
|
2. The `useMount` hook takes `visible` as an argument and provides animation states for mounting and unmounting.
|
|
161
171
|
3. The `open` function, returned by `useMount`, is used to conditionally render `animate.div` based on the `mounted` boolean and apply the transition animation.
|
|
162
172
|
|
|
173
|
+
---
|
|
174
|
+
|
|
163
175
|
### Gestures
|
|
164
176
|
|
|
165
177
|
The `react-ui-animate` library also provides several hooks for handling different types of gestures:
|
|
@@ -175,13 +187,13 @@ The `react-ui-animate` library also provides several hooks for handling differen
|
|
|
175
187
|
Here’s an example of using the useDrag hook to enable drag gestures:
|
|
176
188
|
|
|
177
189
|
```jsx
|
|
178
|
-
import { useValue, animate, useDrag } from 'react-ui-animate';
|
|
190
|
+
import { useValue, animate, useDrag, withSpring } from 'react-ui-animate';
|
|
179
191
|
|
|
180
192
|
export const Draggable = () => {
|
|
181
193
|
const translateX = useValue(0);
|
|
182
194
|
|
|
183
195
|
const bind = useDrag(function ({ down, movementX }) {
|
|
184
|
-
translateX.value = down ? movementX : 0;
|
|
196
|
+
translateX.value = down ? movementX : withSpring(0);
|
|
185
197
|
});
|
|
186
198
|
|
|
187
199
|
return (
|
|
@@ -191,7 +203,7 @@ export const Draggable = () => {
|
|
|
191
203
|
width: 100,
|
|
192
204
|
height: 100,
|
|
193
205
|
backgroundColor: '#3399ff',
|
|
194
|
-
translateX: translateX.value,
|
|
206
|
+
translateX: translateX.value,
|
|
195
207
|
}}
|
|
196
208
|
/>
|
|
197
209
|
);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { withConfig } from './withConfig';
|
|
2
1
|
export { withDecay } from './withDecay';
|
|
3
2
|
export { withDelay } from './withDelay';
|
|
4
|
-
export { withEase } from './withEase';
|
|
5
3
|
export { withSequence } from './withSequence';
|
|
6
4
|
export { withSpring } from './withSpring';
|
|
7
5
|
export { withTiming } from './withTiming';
|
|
8
6
|
export { withLoop } from './withLoop';
|
|
7
|
+
export { withNative } from './withNative';
|
|
8
|
+
export { withEase } from './withEase';
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { FluidValue } from '@raidipesh78/re-motion';
|
|
2
|
+
import type { WithCallbacks } from '../types';
|
|
3
|
+
interface WithDecayConfig extends WithCallbacks {
|
|
4
|
+
velocity?: number;
|
|
5
|
+
deceleration?: number;
|
|
5
6
|
}
|
|
6
|
-
export declare const withDecay: (config?: WithDecayConfig) =>
|
|
7
|
+
export declare const withDecay: (config?: WithDecayConfig, callback?: (result: any) => void) => (value: FluidValue) => {
|
|
8
|
+
controller: import("@raidipesh78/re-motion/dist/controllers/types").ControllerAnimation;
|
|
9
|
+
callback: ((result: any) => void) | undefined;
|
|
10
|
+
};
|
|
7
11
|
export {};
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
config?: UseValueConfig;
|
|
6
|
-
}) => UpdateValue;
|
|
1
|
+
export declare const withDelay: (ms: number, callback?: (result: any) => void) => () => {
|
|
2
|
+
controller: import("@raidipesh78/re-motion/dist/controllers/types").ControllerAnimation;
|
|
3
|
+
callback: ((result: any) => void) | undefined;
|
|
4
|
+
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
interface WithEaseConfig extends WithOnCallbacks {
|
|
1
|
+
import type { WithCallbacks } from '../types';
|
|
2
|
+
interface WithEaseConfig extends WithCallbacks {
|
|
4
3
|
}
|
|
5
|
-
export declare const withEase: (toValue: number, config?: WithEaseConfig) =>
|
|
4
|
+
export declare const withEase: (toValue: number, config?: WithEaseConfig, callback?: (result: any) => void) => (value: import("@raidipesh78/re-motion").FluidValue) => {
|
|
5
|
+
controller: import("@raidipesh78/re-motion/dist/controllers/types").ControllerAnimation;
|
|
6
|
+
callback: ((result: any) => void) | undefined;
|
|
7
|
+
};
|
|
6
8
|
export {};
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare const withLoop: (
|
|
1
|
+
import { FluidValue, loop } from '@raidipesh78/re-motion';
|
|
2
|
+
export declare const withLoop: (animations: (value: FluidValue) => {
|
|
3
|
+
controller: ReturnType<typeof loop>;
|
|
4
|
+
callback?: (result: any) => void;
|
|
5
|
+
}, iterations: number, callback?: (result: any) => void) => (value: FluidValue) => {
|
|
6
|
+
controller: import("@raidipesh78/re-motion/dist/controllers/types").ControllerAnimation;
|
|
7
|
+
callback: ((result: any) => void) | undefined;
|
|
8
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { FluidValue } from '@raidipesh78/re-motion';
|
|
2
|
+
export declare const withNative: (toValue: number | string, callback?: (result: any) => void) => (value: FluidValue) => {
|
|
3
|
+
controller: import("@raidipesh78/re-motion/dist/controllers/types").ControllerAnimation;
|
|
4
|
+
callback: ((result: any) => void) | undefined;
|
|
5
|
+
};
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const withSequence: (animations: Array<
|
|
1
|
+
import { FluidValue, sequence } from '@raidipesh78/re-motion';
|
|
2
|
+
export declare const withSequence: (animations: Array<(value: FluidValue) => {
|
|
3
|
+
controller: ReturnType<typeof sequence>;
|
|
4
|
+
callback?: (result: any) => void;
|
|
5
|
+
}>, callback?: (result: any) => void) => (value: FluidValue) => {
|
|
6
|
+
controller: import("@raidipesh78/re-motion/dist/controllers/types").ControllerAnimation;
|
|
7
|
+
callback: ((result: any) => void) | undefined;
|
|
8
|
+
};
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { FluidValue } from '@raidipesh78/re-motion';
|
|
2
|
+
import type { WithCallbacks } from '../types';
|
|
3
|
+
interface WithSpringConfig extends WithCallbacks {
|
|
4
|
+
mass?: number;
|
|
5
|
+
friction?: number;
|
|
6
|
+
tension?: number;
|
|
5
7
|
}
|
|
6
|
-
export declare const withSpring: (toValue: number, config?: WithSpringConfig) =>
|
|
8
|
+
export declare const withSpring: (toValue: number, config?: WithSpringConfig, callback?: (result: any) => void) => (value: FluidValue) => {
|
|
9
|
+
controller: import("@raidipesh78/re-motion/dist/controllers/types").ControllerAnimation;
|
|
10
|
+
callback: ((result: any) => void) | undefined;
|
|
11
|
+
};
|
|
7
12
|
export {};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { FluidValue } from '@raidipesh78/re-motion';
|
|
2
|
+
import type { WithCallbacks } from '../types';
|
|
3
|
+
interface WithTimingConfig extends WithCallbacks {
|
|
4
|
+
duration?: number;
|
|
5
|
+
easing?: (t: number) => number;
|
|
5
6
|
}
|
|
6
|
-
export declare const withTiming: (toValue: number, config?: WithTimingConfig) =>
|
|
7
|
+
export declare const withTiming: (toValue: number, config?: WithTimingConfig, callback?: (result: any) => void) => (value: FluidValue) => {
|
|
8
|
+
controller: import("@raidipesh78/re-motion/dist/controllers/types").ControllerAnimation;
|
|
9
|
+
callback: ((result: any) => void) | undefined;
|
|
10
|
+
};
|
|
7
11
|
export {};
|
|
@@ -1,59 +1,63 @@
|
|
|
1
1
|
import { Easing } from '@raidipesh78/re-motion';
|
|
2
2
|
export declare const AnimationConfig: {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
3
|
+
Timing: {
|
|
4
|
+
BOUNCE: {
|
|
5
|
+
duration: number;
|
|
6
|
+
easing: typeof Easing.bounce;
|
|
7
|
+
};
|
|
8
|
+
EASE_IN: {
|
|
9
|
+
duration: number;
|
|
10
|
+
easing: (t: number) => number;
|
|
11
|
+
};
|
|
12
|
+
EASE_OUT: {
|
|
13
|
+
duration: number;
|
|
14
|
+
easing: (t: number) => number;
|
|
15
|
+
};
|
|
16
|
+
EASE_IN_OUT: {
|
|
17
|
+
duration: number;
|
|
18
|
+
easing: (t: number) => number;
|
|
19
|
+
};
|
|
20
|
+
POWER1: {
|
|
21
|
+
duration: number;
|
|
22
|
+
easing: (t: number) => number;
|
|
23
|
+
};
|
|
24
|
+
POWER2: {
|
|
25
|
+
duration: number;
|
|
26
|
+
easing: (t: number) => number;
|
|
27
|
+
};
|
|
28
|
+
POWER3: {
|
|
29
|
+
duration: number;
|
|
30
|
+
easing: (t: number) => number;
|
|
31
|
+
};
|
|
32
|
+
POWER4: {
|
|
33
|
+
duration: number;
|
|
34
|
+
easing: (t: number) => number;
|
|
35
|
+
};
|
|
36
|
+
LINEAR: {
|
|
37
|
+
duration: number;
|
|
38
|
+
easing: typeof Easing.linear;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
Spring: {
|
|
42
|
+
ELASTIC: {
|
|
43
|
+
mass: number;
|
|
44
|
+
friction: number;
|
|
45
|
+
tension: number;
|
|
46
|
+
};
|
|
47
|
+
EASE: {
|
|
48
|
+
mass: number;
|
|
49
|
+
friction: number;
|
|
50
|
+
tension: number;
|
|
51
|
+
};
|
|
52
|
+
STIFF: {
|
|
53
|
+
mass: number;
|
|
54
|
+
friction: number;
|
|
55
|
+
tension: number;
|
|
56
|
+
};
|
|
57
|
+
WOBBLE: {
|
|
58
|
+
mass: number;
|
|
59
|
+
friction: number;
|
|
60
|
+
tension: number;
|
|
61
|
+
};
|
|
58
62
|
};
|
|
59
63
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function getToValue(
|
|
1
|
+
import { ToValue } from '../types';
|
|
2
|
+
export declare function getToValue(val: string | number | ToValue): ToValue;
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { FluidValue } from '@raidipesh78/re-motion';
|
|
2
|
-
import {
|
|
3
|
-
export interface UseMountConfig
|
|
2
|
+
import type { ToValue } from '../types';
|
|
3
|
+
export interface UseMountConfig {
|
|
4
|
+
from?: number;
|
|
5
|
+
enter?: ToValue;
|
|
6
|
+
exit?: ToValue;
|
|
4
7
|
}
|
|
5
|
-
|
|
6
|
-
* `useMount` handles mounting and unmounting of a component which captures current state
|
|
7
|
-
* passed as an argument (`state`) and exposes the shadow state which handles the mount and unmount
|
|
8
|
-
* of a component.
|
|
9
|
-
*
|
|
10
|
-
* @param { boolean } state - Boolean indicating the component should mount or unmount.
|
|
11
|
-
* @param { UseMountConfig } config - Animation configuration.
|
|
12
|
-
*/
|
|
13
|
-
export declare function useMount(state: boolean, config: UseMountConfig): (cb: (value: {
|
|
8
|
+
export declare const useMount: (state: boolean, config?: UseMountConfig) => (fn: (animation: {
|
|
14
9
|
value: FluidValue;
|
|
15
10
|
}, mounted: boolean) => React.ReactNode) => import("react").ReactNode;
|
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
import { FluidValue } from '@raidipesh78/re-motion';
|
|
2
|
-
import type {
|
|
3
|
-
export
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* `useValue` returns an animation value with `.value` and `.currentValue` property which is
|
|
7
|
-
* initialized when passed to argument (`initialValue`). The returned value persist until the lifetime of
|
|
8
|
-
* a component. It doesn't cast any re-renders which can is very good for performance optimization.
|
|
9
|
-
*
|
|
10
|
-
* @param { number } initialValue - Initial value
|
|
11
|
-
* @param { UseValueConfig } config - Animation configuration object.
|
|
12
|
-
*/
|
|
13
|
-
export declare function useValue<T extends number | string>(initialValue: T, config?: UseValueConfig): {
|
|
2
|
+
import type { ToValue } from '../types';
|
|
3
|
+
export declare function useValue(initialValue: number | string): {
|
|
14
4
|
get value(): FluidValue;
|
|
15
|
-
set value(to: number | string |
|
|
5
|
+
set value(to: number | string | ToValue);
|
|
16
6
|
readonly currentValue: string | number;
|
|
17
7
|
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { FluidValue } from '@raidipesh78/re-motion';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export declare function useValues<T extends number[] | string[]>(initialValue: T, config?: UseValueConfig): {
|
|
2
|
+
import type { ToValue } from '../types';
|
|
3
|
+
export declare function useValues(initialValue: number[] | string[]): {
|
|
5
4
|
get value(): FluidValue[];
|
|
6
|
-
set value(to:
|
|
5
|
+
set value(to: number[] | string[] | ToValue[]);
|
|
7
6
|
readonly currentValue: (string | number)[];
|
|
8
7
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { interpolate, bInterpolate } from './interpolation';
|
|
2
|
-
export { MountedBlock, ScrollableBlock
|
|
3
|
-
export { useValue,
|
|
4
|
-
export { withSpring, withTiming, withSequence, withDelay,
|
|
5
|
-
export {
|
|
2
|
+
export { MountedBlock, ScrollableBlock } from './modules';
|
|
3
|
+
export { useValue, useMount, useValues, type UseMountConfig } from './hooks';
|
|
4
|
+
export { withSpring, withTiming, withSequence, withDelay, withDecay, withLoop, withEase, } from './controllers';
|
|
5
|
+
export { AnimationConfig } from './helpers';
|
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { type UseMountConfig } from '../hooks';
|
|
1
|
+
import { ReactNode } from 'react';
|
|
3
2
|
import { FluidValue } from '@raidipesh78/re-motion';
|
|
3
|
+
import { type UseMountConfig } from '../hooks';
|
|
4
4
|
interface MountedBlockProps extends Partial<UseMountConfig> {
|
|
5
5
|
state: boolean;
|
|
6
6
|
children: (animation: {
|
|
7
7
|
value: FluidValue;
|
|
8
|
-
}) =>
|
|
8
|
+
}) => ReactNode;
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
* MountedBlock - Higher order component which handles mounting and unmounting of a component.
|
|
12
|
-
* @param { boolean } state - Boolean indicating the component should mount or unmount.
|
|
13
|
-
* @param { function } children - Child as a function with `AnimatedValue` on `.value` property.
|
|
14
|
-
* @param { number } } from - Number that dictates the beginning state for animation.
|
|
15
|
-
* @param { number } enter - Number that dictates the entry state for animation.
|
|
16
|
-
* @param { number } exit - Number that dictates the exit state for animation.
|
|
17
|
-
* @param { UseValueConfig } config - Animation configuration for overall animation.
|
|
18
|
-
*/
|
|
19
|
-
export declare const MountedBlock: ({ state, children, from, enter, exit, config, }: MountedBlockProps) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export declare const MountedBlock: ({ state, children, from, enter, exit, }: MountedBlockProps) => import("react/jsx-runtime").JSX.Element;
|
|
20
11
|
export {};
|
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
2
|
import { FluidValue } from '@raidipesh78/re-motion';
|
|
3
|
-
import { type UseValueConfig } from '../hooks';
|
|
4
3
|
interface ScrollableBlockProps {
|
|
5
4
|
children?: (animation: {
|
|
6
5
|
value: FluidValue;
|
|
7
|
-
}) =>
|
|
6
|
+
}) => ReactNode;
|
|
8
7
|
direction?: 'single' | 'both';
|
|
9
8
|
threshold?: number;
|
|
10
|
-
animationConfig?: UseValueConfig;
|
|
11
9
|
}
|
|
12
|
-
/**
|
|
13
|
-
* ScrollableBlock - Higher order component to handle the entrance or exit animation
|
|
14
|
-
* of a component when it enters or exit the viewport. Accepts child as a function with
|
|
15
|
-
* `AnimatedValue` as its first argument which can be interpolated on input range [0, 1]
|
|
16
|
-
* @prop { function } children - child as a function with `AnimatedValue` as its first argument.
|
|
17
|
-
* @prop { 'single' | 'both' } direction - single applies animation on enter once, both applies on enter and exit.
|
|
18
|
-
* @prop { number } threshold - should be in range 0 to 1 which equivalent to `IntersectionObserver` threshold.
|
|
19
|
-
* @prop { UseValueConfig } animationConfig - Animation config
|
|
20
|
-
*/
|
|
21
10
|
export declare const ScrollableBlock: (props: ScrollableBlockProps) => import("react/jsx-runtime").JSX.Element;
|
|
22
11
|
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FluidValue, spring } from '@raidipesh78/re-motion';
|
|
2
|
+
export type EndCallbackResult = {
|
|
3
|
+
finished: boolean;
|
|
4
|
+
value?: number | string;
|
|
5
|
+
};
|
|
6
|
+
export type EndCallback = (result: EndCallbackResult) => void;
|
|
7
|
+
export type Controller = ReturnType<typeof spring>;
|
|
8
|
+
export type ToValue = (animation: FluidValue) => {
|
|
9
|
+
controller: Controller;
|
|
10
|
+
callback?: EndCallback;
|
|
11
|
+
};
|
|
12
|
+
export interface WithCallbacks {
|
|
13
|
+
onStart?: (value: number | string) => void;
|
|
14
|
+
onChange?: (value: number | string) => void;
|
|
15
|
+
onRest?: (value: number | string) => void;
|
|
16
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { Easing, makeFluid as makeAnimated, fluid as animate, } from '@raidipesh78/re-motion';
|
|
2
|
-
export { AnimationConfig, MountedBlock, ScrollableBlock
|
|
2
|
+
export { AnimationConfig, MountedBlock, ScrollableBlock } from './animation';
|
|
3
3
|
export { interpolate, bInterpolate } from './animation';
|
|
4
4
|
export { useValue, useMount, useValues } from './animation';
|
|
5
|
-
export { withSpring, withTiming, withSequence, withDelay,
|
|
5
|
+
export { withSpring, withTiming, withSequence, withDelay, withDecay, withLoop, withEase, } from './animation';
|
|
6
6
|
export { useMeasure, useOutsideClick, useWindowDimension } from './hooks';
|
|
7
7
|
export { useDrag, useGesture, useMouseMove, useScroll, useWheel, } from './gestures/hooks';
|
|
8
8
|
export { bin, clamp, mix, rubberClamp, move, snapTo } from './gestures/helpers';
|
|
9
|
-
export type {
|
|
9
|
+
export type { UseMountConfig } from './animation';
|