react-ui-animate 4.0.0-rc.2 → 4.0.0-rc.4
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/.idea/codeStyles/Project.xml +59 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/modules.xml +8 -0
- package/.idea/react-ui-animate.iml +9 -0
- package/.idea/vcs.xml +6 -0
- package/LICENSE +21 -21
- package/README.md +209 -209
- package/dist/animation/animationType.d.ts +58 -15
- package/dist/animation/controllers/index.d.ts +8 -0
- package/dist/animation/controllers/withConfig.d.ts +5 -0
- package/dist/animation/controllers/withDecay.d.ts +7 -0
- package/dist/animation/controllers/withDelay.d.ts +6 -0
- package/dist/animation/controllers/withEase.d.ts +6 -0
- package/dist/animation/controllers/withLoop.d.ts +2 -0
- package/dist/animation/controllers/withSequence.d.ts +2 -0
- package/dist/animation/controllers/withSpring.d.ts +7 -0
- package/dist/animation/controllers/withTiming.d.ts +7 -0
- package/dist/animation/core/FluidArrayController.d.ts +2 -2
- package/dist/animation/core/FluidController.d.ts +5 -3
- package/dist/animation/core/useFluidValue.d.ts +2 -2
- package/dist/animation/core/useFluidValues.d.ts +3 -0
- package/dist/animation/core/useMount.d.ts +3 -3
- package/dist/animation/helpers/getToValue.d.ts +2 -0
- package/dist/animation/helpers/index.d.ts +1 -0
- package/dist/animation/hooks/index.d.ts +3 -0
- package/dist/animation/hooks/useMount.d.ts +15 -0
- package/dist/animation/hooks/useValue.d.ts +17 -0
- package/dist/animation/hooks/useValues.d.ts +8 -0
- package/dist/animation/index.d.ts +3 -4
- package/dist/animation/interpolation.d.ts +5 -4
- package/dist/animation/modules/MountedBlock.d.ts +7 -10
- package/dist/animation/modules/ScrollableBlock.d.ts +5 -4
- package/dist/animation/modules/TransitionBlock.d.ts +5 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +52 -52
- package/dist/animation/useAnimatedValue.d.ts +0 -21
- package/dist/animation/useMountedValue.d.ts +0 -15
- package/dist/animation/withFunctions.d.ts +0 -107
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<component name="ProjectCodeStyleConfiguration">
|
|
2
|
+
<code_scheme name="Project" version="173">
|
|
3
|
+
<HTMLCodeStyleSettings>
|
|
4
|
+
<option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
|
|
5
|
+
</HTMLCodeStyleSettings>
|
|
6
|
+
<JSCodeStyleSettings version="0">
|
|
7
|
+
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
8
|
+
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
9
|
+
<option name="USE_DOUBLE_QUOTES" value="false" />
|
|
10
|
+
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
11
|
+
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
|
|
12
|
+
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
|
13
|
+
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
14
|
+
</JSCodeStyleSettings>
|
|
15
|
+
<TypeScriptCodeStyleSettings version="0">
|
|
16
|
+
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
17
|
+
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
|
|
18
|
+
<option name="USE_DOUBLE_QUOTES" value="false" />
|
|
19
|
+
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
20
|
+
<option name="ENFORCE_TRAILING_COMMA" value="WhenMultiline" />
|
|
21
|
+
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
|
|
22
|
+
<option name="SPACES_WITHIN_IMPORTS" value="true" />
|
|
23
|
+
</TypeScriptCodeStyleSettings>
|
|
24
|
+
<VueCodeStyleSettings>
|
|
25
|
+
<option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
|
|
26
|
+
<option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
|
|
27
|
+
</VueCodeStyleSettings>
|
|
28
|
+
<codeStyleSettings language="HTML">
|
|
29
|
+
<option name="SOFT_MARGINS" value="80" />
|
|
30
|
+
<indentOptions>
|
|
31
|
+
<option name="INDENT_SIZE" value="2" />
|
|
32
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
33
|
+
<option name="TAB_SIZE" value="2" />
|
|
34
|
+
</indentOptions>
|
|
35
|
+
</codeStyleSettings>
|
|
36
|
+
<codeStyleSettings language="JavaScript">
|
|
37
|
+
<option name="SOFT_MARGINS" value="80" />
|
|
38
|
+
<indentOptions>
|
|
39
|
+
<option name="INDENT_SIZE" value="2" />
|
|
40
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
41
|
+
<option name="TAB_SIZE" value="2" />
|
|
42
|
+
</indentOptions>
|
|
43
|
+
</codeStyleSettings>
|
|
44
|
+
<codeStyleSettings language="TypeScript">
|
|
45
|
+
<option name="SOFT_MARGINS" value="80" />
|
|
46
|
+
<indentOptions>
|
|
47
|
+
<option name="INDENT_SIZE" value="2" />
|
|
48
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
49
|
+
<option name="TAB_SIZE" value="2" />
|
|
50
|
+
</indentOptions>
|
|
51
|
+
</codeStyleSettings>
|
|
52
|
+
<codeStyleSettings language="Vue">
|
|
53
|
+
<option name="SOFT_MARGINS" value="80" />
|
|
54
|
+
<indentOptions>
|
|
55
|
+
<option name="CONTINUATION_INDENT_SIZE" value="2" />
|
|
56
|
+
</indentOptions>
|
|
57
|
+
</codeStyleSettings>
|
|
58
|
+
</code_scheme>
|
|
59
|
+
</component>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/react-ui-animate.iml" filepath="$PROJECT_DIR$/.idea/react-ui-animate.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="JAVA_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
+
<exclude-output />
|
|
5
|
+
<content url="file://$MODULE_DIR$" />
|
|
6
|
+
<orderEntry type="inheritedJdk" />
|
|
7
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
|
+
</component>
|
|
9
|
+
</module>
|
package/.idea/vcs.xml
ADDED
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020 Dipesh Rai
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Dipesh Rai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,209 +1,209 @@
|
|
|
1
|
-
# React UI Animate
|
|
2
|
-
|
|
3
|
-
[](https://badge.fury.io/js/react-ui-animate)
|
|
4
|
-
|
|
5
|
-
> Create smooth animations and interactive gestures in React applications effortlessly.
|
|
6
|
-
|
|
7
|
-
### Install
|
|
8
|
-
|
|
9
|
-
You can install react-ui-animate via npm or yarn:
|
|
10
|
-
|
|
11
|
-
```sh
|
|
12
|
-
npm i react-ui-animate
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
```sh
|
|
16
|
-
yarn add react-ui-animate
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
### Getting Started
|
|
20
|
-
|
|
21
|
-
The `react-ui-animate` library provides a straightforward way to add animations and gestures to your React components. Here’s how you can get started quickly:
|
|
22
|
-
|
|
23
|
-
```javascript
|
|
24
|
-
import { animate,
|
|
25
|
-
|
|
26
|
-
export default function () {
|
|
27
|
-
// Initialize an animated opacity value
|
|
28
|
-
const opacity =
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<div>
|
|
32
|
-
{/* animate.div component uses the animated opacity value */}
|
|
33
|
-
<animate.div
|
|
34
|
-
style={{
|
|
35
|
-
opacity: opacity.value, // using opacity with value property
|
|
36
|
-
width: 100,
|
|
37
|
-
padding: 20,
|
|
38
|
-
background: '#39F',
|
|
39
|
-
}}
|
|
40
|
-
>
|
|
41
|
-
ANIMATED
|
|
42
|
-
</animate.div>
|
|
43
|
-
|
|
44
|
-
{/* Clicking the button changes the opacity smoothly to 1 */}
|
|
45
|
-
<button onClick={() => (opacity.value = 1)}>Animate Me</button>
|
|
46
|
-
</div>
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
In this example, clicking the "Animate Me" button smoothly changes the opacity of the animated block from 0 to 1.
|
|
52
|
-
|
|
53
|
-
### Key Features
|
|
54
|
-
|
|
55
|
-
#### `
|
|
56
|
-
|
|
57
|
-
The `
|
|
58
|
-
|
|
59
|
-
```javascript
|
|
60
|
-
const opacity =
|
|
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
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
#### `animate.div`
|
|
72
|
-
|
|
73
|
-
`animate.div` is a special component designed to work with `
|
|
74
|
-
|
|
75
|
-
```javascript
|
|
76
|
-
const width =
|
|
77
|
-
|
|
78
|
-
<animate.div
|
|
79
|
-
style={{
|
|
80
|
-
width: width.value,
|
|
81
|
-
height: 100,
|
|
82
|
-
backgroundColor: '#39f',
|
|
83
|
-
}}
|
|
84
|
-
/>;
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
#### `interpolate`
|
|
88
|
-
|
|
89
|
-
The `interpolate()` function is useful for mapping values from one range to another, enabling more complex animations.
|
|
90
|
-
|
|
91
|
-
```javascript
|
|
92
|
-
import {
|
|
93
|
-
|
|
94
|
-
const width =
|
|
95
|
-
|
|
96
|
-
<animate.div
|
|
97
|
-
style={{
|
|
98
|
-
width: width.value,
|
|
99
|
-
height: 100,
|
|
100
|
-
backgroundColor: interpolate(width.value, [100, 200], ['red', 'blue']),
|
|
101
|
-
}}
|
|
102
|
-
/>;
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
In this example, as the width changes from 100 to 200, the background color smoothly transitions from red to blue.
|
|
106
|
-
|
|
107
|
-
#### Dynamic Animations and Sequence Transitions
|
|
108
|
-
|
|
109
|
-
You can dynamically modify animation configurations by assigning values to an animated value using various animation functions.
|
|
110
|
-
|
|
111
|
-
To apply a spring animation and update the value to `10`:
|
|
112
|
-
|
|
113
|
-
```jsx
|
|
114
|
-
x.value = withSpring(10);
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
To apply a timing animation with a duration of 5000 milliseconds:
|
|
118
|
-
|
|
119
|
-
```jsx
|
|
120
|
-
x.value = withTiming(10, { duration: 5000 });
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
To create sequential transitions using the `withSequence` function with dynamic modifiers like `withSpring` and `withTiming`:
|
|
124
|
-
|
|
125
|
-
```jsx
|
|
126
|
-
x.value = withSequence([withSpring(50), withTiming(100), 200]);
|
|
127
|
-
```
|
|
128
|
-
|
|
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
|
-
#### `
|
|
138
|
-
|
|
139
|
-
The `
|
|
140
|
-
|
|
141
|
-
```jsx
|
|
142
|
-
import {
|
|
143
|
-
|
|
144
|
-
export default function App() {
|
|
145
|
-
const [visible, setVisible] = useState(false);
|
|
146
|
-
|
|
147
|
-
const open =
|
|
148
|
-
from: 0,
|
|
149
|
-
enter: 1,
|
|
150
|
-
exit: 0,
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
return open((animation, mounted) => mounted && <animate.div />);
|
|
154
|
-
}
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
In this example,
|
|
158
|
-
|
|
159
|
-
1. A state variable `visible` determines whether the component is visible.
|
|
160
|
-
2. The `
|
|
161
|
-
3. The `open` function, returned by `
|
|
162
|
-
|
|
163
|
-
### Gestures
|
|
164
|
-
|
|
165
|
-
The `react-ui-animate` library also provides several hooks for handling different types of gestures:
|
|
166
|
-
|
|
167
|
-
1. `useDrag`: Handles drag gestures on elements.
|
|
168
|
-
2. `useMouseMove`: Handles mouse movements.
|
|
169
|
-
3. `useScroll`: Handles scrolling of the document.
|
|
170
|
-
4. `useWheel`: Handles wheel rotation gestures.
|
|
171
|
-
5. `useGesture`: Handles combinations of various gestures.
|
|
172
|
-
|
|
173
|
-
**Example**: `useDrag`
|
|
174
|
-
|
|
175
|
-
Here’s an example of using the useDrag hook to enable drag gestures:
|
|
176
|
-
|
|
177
|
-
```jsx
|
|
178
|
-
import {
|
|
179
|
-
|
|
180
|
-
export const Draggable = () => {
|
|
181
|
-
const translateX =
|
|
182
|
-
|
|
183
|
-
const bind = useDrag(function ({ down, movementX }) {
|
|
184
|
-
translateX.value = down ? movementX : 0;
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
return (
|
|
188
|
-
<animate.div
|
|
189
|
-
{...bind()}
|
|
190
|
-
style={{
|
|
191
|
-
width: 100,
|
|
192
|
-
height: 100,
|
|
193
|
-
backgroundColor: '#3399ff',
|
|
194
|
-
translateX: translateX.value, // Use translateX with animated value
|
|
195
|
-
}}
|
|
196
|
-
/>
|
|
197
|
-
);
|
|
198
|
-
};
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
In this example, the blue block can be dragged horizontally by clicking and dragging.
|
|
202
|
-
|
|
203
|
-
## Documentation
|
|
204
|
-
|
|
205
|
-
For detailed documentation and examples, visit the official [react-ui-animate documentation](http://react-ui-animate.js.org/).
|
|
206
|
-
|
|
207
|
-
## License
|
|
208
|
-
|
|
209
|
-
This library is licensed under the MIT License.
|
|
1
|
+
# React UI Animate
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/react-ui-animate)
|
|
4
|
+
|
|
5
|
+
> Create smooth animations and interactive gestures in React applications effortlessly.
|
|
6
|
+
|
|
7
|
+
### Install
|
|
8
|
+
|
|
9
|
+
You can install react-ui-animate via npm or yarn:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm i react-ui-animate
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
yarn add react-ui-animate
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Getting Started
|
|
20
|
+
|
|
21
|
+
The `react-ui-animate` library provides a straightforward way to add animations and gestures to your React components. Here’s how you can get started quickly:
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
import { animate, useValue } from 'react-ui-animate';
|
|
25
|
+
|
|
26
|
+
export default function () {
|
|
27
|
+
// Initialize an animated opacity value
|
|
28
|
+
const opacity = useValue(0);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<div>
|
|
32
|
+
{/* animate.div component uses the animated opacity value */}
|
|
33
|
+
<animate.div
|
|
34
|
+
style={{
|
|
35
|
+
opacity: opacity.value, // using opacity with value property
|
|
36
|
+
width: 100,
|
|
37
|
+
padding: 20,
|
|
38
|
+
background: '#39F',
|
|
39
|
+
}}
|
|
40
|
+
>
|
|
41
|
+
ANIMATED
|
|
42
|
+
</animate.div>
|
|
43
|
+
|
|
44
|
+
{/* Clicking the button changes the opacity smoothly to 1 */}
|
|
45
|
+
<button onClick={() => (opacity.value = 1)}>Animate Me</button>
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
In this example, clicking the "Animate Me" button smoothly changes the opacity of the animated block from 0 to 1.
|
|
52
|
+
|
|
53
|
+
### Key Features
|
|
54
|
+
|
|
55
|
+
#### `useValue()`
|
|
56
|
+
|
|
57
|
+
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
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
const opacity = useValue(0); // Start with opacity set to 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
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
#### `animate.div`
|
|
72
|
+
|
|
73
|
+
`animate.div` is a special component designed to work with `useValue()`. It simplifies animating elements by directly using animated values.
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
const width = useValue(100); // Start with a width of 100
|
|
77
|
+
|
|
78
|
+
<animate.div
|
|
79
|
+
style={{
|
|
80
|
+
width: width.value,
|
|
81
|
+
height: 100,
|
|
82
|
+
backgroundColor: '#39f',
|
|
83
|
+
}}
|
|
84
|
+
/>;
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### `interpolate`
|
|
88
|
+
|
|
89
|
+
The `interpolate()` function is useful for mapping values from one range to another, enabling more complex animations.
|
|
90
|
+
|
|
91
|
+
```javascript
|
|
92
|
+
import { useValue, animate, interpolate } from 'react-ui-animate';
|
|
93
|
+
|
|
94
|
+
const width = useValue(100); // Start with a width of 100
|
|
95
|
+
|
|
96
|
+
<animate.div
|
|
97
|
+
style={{
|
|
98
|
+
width: width.value,
|
|
99
|
+
height: 100,
|
|
100
|
+
backgroundColor: interpolate(width.value, [100, 200], ['red', 'blue']),
|
|
101
|
+
}}
|
|
102
|
+
/>;
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
In this example, as the width changes from 100 to 200, the background color smoothly transitions from red to blue.
|
|
106
|
+
|
|
107
|
+
#### Dynamic Animations and Sequence Transitions
|
|
108
|
+
|
|
109
|
+
You can dynamically modify animation configurations by assigning values to an animated value using various animation functions.
|
|
110
|
+
|
|
111
|
+
To apply a spring animation and update the value to `10`:
|
|
112
|
+
|
|
113
|
+
```jsx
|
|
114
|
+
x.value = withSpring(10);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
To apply a timing animation with a duration of 5000 milliseconds:
|
|
118
|
+
|
|
119
|
+
```jsx
|
|
120
|
+
x.value = withTiming(10, { duration: 5000 });
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
To create sequential transitions using the `withSequence` function with dynamic modifiers like `withSpring` and `withTiming`:
|
|
124
|
+
|
|
125
|
+
```jsx
|
|
126
|
+
x.value = withSequence([withSpring(50), withTiming(100), 200]);
|
|
127
|
+
```
|
|
128
|
+
|
|
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
|
+
#### `useMount()`
|
|
138
|
+
|
|
139
|
+
The `useMount()` hook facilitates managing the mounting and unmounting of a component with animations.
|
|
140
|
+
|
|
141
|
+
```jsx
|
|
142
|
+
import { useMount } from 'react-ui-animate';
|
|
143
|
+
|
|
144
|
+
export default function App() {
|
|
145
|
+
const [visible, setVisible] = useState(false);
|
|
146
|
+
|
|
147
|
+
const open = useMount(visible, {
|
|
148
|
+
from: 0,
|
|
149
|
+
enter: 1,
|
|
150
|
+
exit: 0,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
return open((animation, mounted) => mounted && <animate.div />);
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
In this example,
|
|
158
|
+
|
|
159
|
+
1. A state variable `visible` determines whether the component is visible.
|
|
160
|
+
2. The `useMount` hook takes `visible` as an argument and provides animation states for mounting and unmounting.
|
|
161
|
+
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
|
+
|
|
163
|
+
### Gestures
|
|
164
|
+
|
|
165
|
+
The `react-ui-animate` library also provides several hooks for handling different types of gestures:
|
|
166
|
+
|
|
167
|
+
1. `useDrag`: Handles drag gestures on elements.
|
|
168
|
+
2. `useMouseMove`: Handles mouse movements.
|
|
169
|
+
3. `useScroll`: Handles scrolling of the document.
|
|
170
|
+
4. `useWheel`: Handles wheel rotation gestures.
|
|
171
|
+
5. `useGesture`: Handles combinations of various gestures.
|
|
172
|
+
|
|
173
|
+
**Example**: `useDrag`
|
|
174
|
+
|
|
175
|
+
Here’s an example of using the useDrag hook to enable drag gestures:
|
|
176
|
+
|
|
177
|
+
```jsx
|
|
178
|
+
import { useValue, animate, useDrag } from 'react-ui-animate';
|
|
179
|
+
|
|
180
|
+
export const Draggable = () => {
|
|
181
|
+
const translateX = useValue(0);
|
|
182
|
+
|
|
183
|
+
const bind = useDrag(function ({ down, movementX }) {
|
|
184
|
+
translateX.value = down ? movementX : 0;
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
return (
|
|
188
|
+
<animate.div
|
|
189
|
+
{...bind()}
|
|
190
|
+
style={{
|
|
191
|
+
width: 100,
|
|
192
|
+
height: 100,
|
|
193
|
+
backgroundColor: '#3399ff',
|
|
194
|
+
translateX: translateX.value, // Use translateX with animated value
|
|
195
|
+
}}
|
|
196
|
+
/>
|
|
197
|
+
);
|
|
198
|
+
};
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
In this example, the blue block can be dragged horizontally by clicking and dragging.
|
|
202
|
+
|
|
203
|
+
## Documentation
|
|
204
|
+
|
|
205
|
+
For detailed documentation and examples, visit the official [react-ui-animate documentation](http://react-ui-animate.js.org/).
|
|
206
|
+
|
|
207
|
+
## License
|
|
208
|
+
|
|
209
|
+
This library is licensed under the MIT License.
|
|
@@ -1,16 +1,59 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare const
|
|
3
|
-
ELASTIC:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import { Easing } from '@raidipesh78/re-motion';
|
|
2
|
+
export declare const AnimationConfig: {
|
|
3
|
+
ELASTIC: {
|
|
4
|
+
mass: number;
|
|
5
|
+
friction: number;
|
|
6
|
+
tension: number;
|
|
7
|
+
};
|
|
8
|
+
BOUNCE: {
|
|
9
|
+
duration: number;
|
|
10
|
+
easing: typeof Easing.bounce;
|
|
11
|
+
};
|
|
12
|
+
EASE: {
|
|
13
|
+
mass: number;
|
|
14
|
+
friction: number;
|
|
15
|
+
tension: number;
|
|
16
|
+
};
|
|
17
|
+
STIFF: {
|
|
18
|
+
mass: number;
|
|
19
|
+
friction: number;
|
|
20
|
+
tension: number;
|
|
21
|
+
};
|
|
22
|
+
WOOBLE: {
|
|
23
|
+
mass: number;
|
|
24
|
+
friction: number;
|
|
25
|
+
tension: number;
|
|
26
|
+
};
|
|
27
|
+
EASE_IN: {
|
|
28
|
+
duration: number;
|
|
29
|
+
easing: (t: number) => number;
|
|
30
|
+
};
|
|
31
|
+
EASE_OUT: {
|
|
32
|
+
duration: number;
|
|
33
|
+
easing: (t: number) => number;
|
|
34
|
+
};
|
|
35
|
+
EASE_IN_OUT: {
|
|
36
|
+
duration: number;
|
|
37
|
+
easing: (t: number) => number;
|
|
38
|
+
};
|
|
39
|
+
POWER1: {
|
|
40
|
+
duration: number;
|
|
41
|
+
easing: (t: number) => number;
|
|
42
|
+
};
|
|
43
|
+
POWER2: {
|
|
44
|
+
duration: number;
|
|
45
|
+
easing: (t: number) => number;
|
|
46
|
+
};
|
|
47
|
+
POWER3: {
|
|
48
|
+
duration: number;
|
|
49
|
+
easing: (t: number) => number;
|
|
50
|
+
};
|
|
51
|
+
POWER4: {
|
|
52
|
+
duration: number;
|
|
53
|
+
easing: (t: number) => number;
|
|
54
|
+
};
|
|
55
|
+
LINEAR: {
|
|
56
|
+
duration: number;
|
|
57
|
+
easing: typeof Easing.linear;
|
|
58
|
+
};
|
|
16
59
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { withConfig } from './withConfig';
|
|
2
|
+
export { withDecay } from './withDecay';
|
|
3
|
+
export { withDelay } from './withDelay';
|
|
4
|
+
export { withEase } from './withEase';
|
|
5
|
+
export { withSequence } from './withSequence';
|
|
6
|
+
export { withSpring } from './withSpring';
|
|
7
|
+
export { withTiming } from './withTiming';
|
|
8
|
+
export { withLoop } from './withLoop';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { UseValueConfig } from '../hooks';
|
|
2
|
+
import type { UpdateValue } from '../core/FluidController';
|
|
3
|
+
export interface WithOnCallbacks extends Pick<UseValueConfig, 'onRest' | 'onStart' | 'onChange'> {
|
|
4
|
+
}
|
|
5
|
+
export declare const withConfig: (toValue: number, config?: UseValueConfig) => UpdateValue;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { UseValueConfig } from '../hooks';
|
|
2
|
+
import type { WithOnCallbacks } from './withConfig';
|
|
3
|
+
import type { UpdateValue } from '../core/FluidController';
|
|
4
|
+
interface WithDecayConfig extends Pick<UseValueConfig, 'velocity' | 'deceleration'>, WithOnCallbacks {
|
|
5
|
+
}
|
|
6
|
+
export declare const withDecay: (config?: WithDecayConfig) => UpdateValue;
|
|
7
|
+
export {};
|