react-ui-animate 2.0.0-rc.1 → 2.0.0-rc.2

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.
Files changed (44) hide show
  1. package/.vscode/settings.json +3 -3
  2. package/LICENSE +21 -21
  3. package/README.md +115 -115
  4. package/dist/animation/animationType.d.ts +8 -0
  5. package/dist/animation/getInitialConfig.d.ts +2 -2
  6. package/dist/index.d.ts +5 -4
  7. package/dist/index.js +35 -0
  8. package/dist/index.js.map +1 -1
  9. package/package.json +49 -49
  10. package/rollup.config.js +18 -18
  11. package/src/animation/animationType.ts +17 -9
  12. package/src/animation/getInitialConfig.ts +61 -30
  13. package/src/animation/index.ts +9 -9
  14. package/src/animation/interpolation.ts +24 -24
  15. package/src/animation/modules.tsx +105 -105
  16. package/src/animation/useAnimatedValue.ts +62 -62
  17. package/src/animation/useMountedValue.ts +66 -66
  18. package/src/gestures/controllers/DragGesture.ts +177 -177
  19. package/src/gestures/controllers/Gesture.ts +54 -54
  20. package/src/gestures/controllers/MouseMoveGesture.ts +111 -111
  21. package/src/gestures/controllers/ScrollGesture.ts +107 -107
  22. package/src/gestures/controllers/WheelGesture.ts +123 -123
  23. package/src/gestures/controllers/index.ts +4 -4
  24. package/src/gestures/eventAttacher.ts +67 -67
  25. package/src/gestures/hooks/index.ts +5 -5
  26. package/src/gestures/hooks/useDrag.ts +14 -14
  27. package/src/gestures/hooks/useGesture.ts +38 -38
  28. package/src/gestures/hooks/useMouseMove.ts +11 -11
  29. package/src/gestures/hooks/useRecognizer.ts +59 -59
  30. package/src/gestures/hooks/useScroll.ts +11 -11
  31. package/src/gestures/hooks/useWheel.ts +11 -11
  32. package/src/gestures/index.ts +2 -2
  33. package/src/gestures/math.ts +120 -120
  34. package/src/gestures/types.ts +49 -49
  35. package/src/gestures/withDefault.ts +3 -3
  36. package/src/hooks/index.ts +3 -3
  37. package/src/hooks/useMeasure.ts +133 -133
  38. package/src/hooks/useOutsideClick.ts +36 -36
  39. package/src/hooks/useWindowDimension.ts +59 -59
  40. package/src/index.ts +5 -4
  41. package/src/utils/delay.ts +9 -9
  42. package/src/utils/index.ts +2 -2
  43. package/src/utils/isDefined.ts +4 -4
  44. package/tsconfig.json +25 -25
@@ -1,3 +1,3 @@
1
- {
2
- "compile-hero.disable-compile-files-on-did-save-code": false
3
- }
1
+ {
2
+ "compile-hero.disable-compile-files-on-did-save-code": false
3
+ }
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,115 +1,115 @@
1
- # React UI Animate
2
-
3
- [![npm version](https://badge.fury.io/js/react-ui-animate.svg)](https://badge.fury.io/js/react-ui-animate)
4
-
5
- > React library for gestures and animation
6
-
7
- ### Install
8
-
9
- Install with npm:
10
-
11
- ```sh
12
- npm i react-ui-animate
13
- ```
14
-
15
- or
16
- Install with yarn:
17
-
18
- ```sh
19
- yarn add react-ui-animate
20
- ```
21
-
22
- ### Getting Started
23
-
24
- `react-ui-animate` provides lots of easy to use APIs to create smooth animations and gestures.
25
-
26
- ```javascript
27
- import { AnimatedBlock, useAnimatedValue } from "react-ui-animate";
28
-
29
- export default function () {
30
- const opacity = useAnimatedValue(0); // It initializes opacity object with value 0.
31
-
32
- return (
33
- <div>
34
- {/* AnimatedBlock component can read useAnimatedValue() */}
35
- <AnimatedBlock
36
- style={{
37
- opacity: opacity.value, // using opacity with value property
38
- width: 100,
39
- padding: 20,
40
- background: "#39F",
41
- }}
42
- >
43
- ANIMATED
44
- </AnimatedBlock>
45
-
46
- {/* Assigning value to 1 auto animates from initialized value 0 to 1 smoothly */}
47
- <button onClick={() => (opacity.value = 1)}>Animate Me</button>
48
- </div>
49
- );
50
- }
51
- ```
52
-
53
- Animates opacity from 0 to 1.
54
-
55
- #### `useAnimatedValue()`
56
-
57
- `useAnimatedValue()` is very flexible and powerful hook that lets you define animated values. It accepts a value and returns a node with same value on `value` property. Whenever `value` property is assigned to another value, it auto animates from one value to another.
58
-
59
- ```javascript
60
- const opacity = useAnimatedValue(0); // initialize with 0 opacity
61
-
62
- ...
63
- style={{
64
- opacity: opacity.value // access with `.value`
65
- }}
66
- ...
67
-
68
- ...
69
- onClick={() => opacity.value = 1} // Assignment
70
- ...
71
- ```
72
-
73
- #### `AnimatedBlock`
74
-
75
- `AnimatedBlock` is a `div` component which can accept the animation node from `useAnimatedValue()` hook.
76
-
77
- ```javascript
78
- const width = useAnimatedValue(100);
79
-
80
- <AnimatedBlock
81
- style={{
82
- width: width.value,
83
- height: 100,
84
- backgroundColor: "#39f",
85
- }}
86
- />;
87
- ```
88
-
89
- #### `interpolate`
90
-
91
- The `interpolate()` function allows animated node value to map from input ranges to different output ranges. By default, it will extrapolate the curve beyond the ranges given, but you can also have it clamp the output value.
92
-
93
- ```javascript
94
- import { useAnimatedValue, AnimatedBlock, interpolate } from "react-ui-animate";
95
-
96
- const width = useAnimatedValue(100);
97
-
98
- <AnimatedBlock
99
- style={{
100
- width: width.value,
101
- height: 100,
102
- backgroundColor: interpolate(width.value, [100, 200], ["red", "blue"]),
103
- }}
104
- />;
105
- ```
106
-
107
- `backgroundColor` is interpolated from input range `[100, 200]` to output range `["red", "blue"]`. So, when the width changes from 100 to 200, `backgroundColor` will change from `red` to `blue`.
108
-
109
- ## Documentation
110
-
111
- The official documentation are now published at http://react-ui-animate.js.org/
112
-
113
- ## License
114
-
115
- MIT
1
+ # React UI Animate
2
+
3
+ [![npm version](https://badge.fury.io/js/react-ui-animate.svg)](https://badge.fury.io/js/react-ui-animate)
4
+
5
+ > React library for gestures and animation
6
+
7
+ ### Install
8
+
9
+ Install with npm:
10
+
11
+ ```sh
12
+ npm i react-ui-animate
13
+ ```
14
+
15
+ or
16
+ Install with yarn:
17
+
18
+ ```sh
19
+ yarn add react-ui-animate
20
+ ```
21
+
22
+ ### Getting Started
23
+
24
+ `react-ui-animate` provides lots of easy to use APIs to create smooth animations and gestures.
25
+
26
+ ```javascript
27
+ import { AnimatedBlock, useAnimatedValue } from "react-ui-animate";
28
+
29
+ export default function () {
30
+ const opacity = useAnimatedValue(0); // It initializes opacity object with value 0.
31
+
32
+ return (
33
+ <div>
34
+ {/* AnimatedBlock component can read useAnimatedValue() */}
35
+ <AnimatedBlock
36
+ style={{
37
+ opacity: opacity.value, // using opacity with value property
38
+ width: 100,
39
+ padding: 20,
40
+ background: "#39F",
41
+ }}
42
+ >
43
+ ANIMATED
44
+ </AnimatedBlock>
45
+
46
+ {/* Assigning value to 1 auto animates from initialized value 0 to 1 smoothly */}
47
+ <button onClick={() => (opacity.value = 1)}>Animate Me</button>
48
+ </div>
49
+ );
50
+ }
51
+ ```
52
+
53
+ Animates opacity from 0 to 1.
54
+
55
+ #### `useAnimatedValue()`
56
+
57
+ `useAnimatedValue()` is very flexible and powerful hook that lets you define animated values. It accepts a value and returns a node with same value on `value` property. Whenever `value` property is assigned to another value, it auto animates from one value to another.
58
+
59
+ ```javascript
60
+ const opacity = useAnimatedValue(0); // initialize with 0 opacity
61
+
62
+ ...
63
+ style={{
64
+ opacity: opacity.value // access with `.value`
65
+ }}
66
+ ...
67
+
68
+ ...
69
+ onClick={() => opacity.value = 1} // Assignment
70
+ ...
71
+ ```
72
+
73
+ #### `AnimatedBlock`
74
+
75
+ `AnimatedBlock` is a `div` component which can accept the animation node from `useAnimatedValue()` hook.
76
+
77
+ ```javascript
78
+ const width = useAnimatedValue(100);
79
+
80
+ <AnimatedBlock
81
+ style={{
82
+ width: width.value,
83
+ height: 100,
84
+ backgroundColor: "#39f",
85
+ }}
86
+ />;
87
+ ```
88
+
89
+ #### `interpolate`
90
+
91
+ The `interpolate()` function allows animated node value to map from input ranges to different output ranges. By default, it will extrapolate the curve beyond the ranges given, but you can also have it clamp the output value.
92
+
93
+ ```javascript
94
+ import { useAnimatedValue, AnimatedBlock, interpolate } from "react-ui-animate";
95
+
96
+ const width = useAnimatedValue(100);
97
+
98
+ <AnimatedBlock
99
+ style={{
100
+ width: width.value,
101
+ height: 100,
102
+ backgroundColor: interpolate(width.value, [100, 200], ["red", "blue"]),
103
+ }}
104
+ />;
105
+ ```
106
+
107
+ `backgroundColor` is interpolated from input range `[100, 200]` to output range `["red", "blue"]`. So, when the width changes from 100 to 200, `backgroundColor` will change from `red` to `blue`.
108
+
109
+ ## Documentation
110
+
111
+ The official documentation are now published at http://react-ui-animate.js.org/
112
+
113
+ ## License
114
+
115
+ MIT
@@ -4,4 +4,12 @@ export declare const AnimationConfigUtils: {
4
4
  EASE: import("@raidipesh78/re-motion").UseTransitionConfig;
5
5
  STIFF: import("@raidipesh78/re-motion").UseTransitionConfig;
6
6
  WOOBLE: import("@raidipesh78/re-motion").UseTransitionConfig;
7
+ EASE_IN: import("@raidipesh78/re-motion").UseTransitionConfig;
8
+ EASE_OUT: import("@raidipesh78/re-motion").UseTransitionConfig;
9
+ EASE_IN_OUT: import("@raidipesh78/re-motion").UseTransitionConfig;
10
+ POWER1: import("@raidipesh78/re-motion").UseTransitionConfig;
11
+ POWER2: import("@raidipesh78/re-motion").UseTransitionConfig;
12
+ POWER3: import("@raidipesh78/re-motion").UseTransitionConfig;
13
+ POWER4: import("@raidipesh78/re-motion").UseTransitionConfig;
14
+ LINEAR: import("@raidipesh78/re-motion").UseTransitionConfig;
7
15
  };
@@ -1,3 +1,3 @@
1
1
  import { UseTransitionConfig } from '@raidipesh78/re-motion';
2
- export declare type InitialConfigType = 'ease' | 'elastic' | 'stiff' | 'wooble' | 'bounce' | undefined;
3
- export declare const getInitialConfig: (animationType: InitialConfigType) => UseTransitionConfig;
2
+ export declare type InitialConfigType = 'linear' | 'easein' | 'easeout' | 'easeinout' | 'ease' | 'power1' | 'power2' | 'power3' | 'power4' | 'elastic' | 'stiff' | 'wooble' | 'bounce';
3
+ export declare const getInitialConfig: (animationType?: "linear" | "easein" | "easeout" | "easeinout" | "ease" | "power1" | "power2" | "power3" | "power4" | "elastic" | "stiff" | "wooble" | "bounce" | undefined) => UseTransitionConfig;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { Easing } from "@raidipesh78/re-motion";
2
- export * from "./animation";
3
- export * from "./gestures";
4
- export * from "./hooks";
1
+ export { Easing } from '@raidipesh78/re-motion';
2
+ export { delay } from './utils';
3
+ export * from './animation';
4
+ export * from './gestures';
5
+ export * from './hooks';
package/dist/index.js CHANGED
@@ -3,6 +3,16 @@ Object.defineProperty(exports, '__esModule', { value: true });
3
3
  var reMotion = require('@raidipesh78/re-motion');
4
4
  var React = require('react');
5
5
 
6
+ /**
7
+ * @param { number } ms - number of milliseconds to delay code execution
8
+ * @returns Promise
9
+ */
10
+ function delay(ms) {
11
+ return new Promise(function (resolve) {
12
+ setTimeout(function () { return resolve(null); }, ms);
13
+ });
14
+ }
15
+
6
16
  /**
7
17
  * bInterpolate functions maps input range [0, 1] to given [minOutput, maxOutput]
8
18
  * sorthand function to interpolate input range [0, 1]
@@ -243,6 +253,22 @@ var getInitialConfig = function (animationType) {
243
253
  return { mass: 1, friction: 8, tension: 250 };
244
254
  case 'bounce':
245
255
  return { duration: 500, easing: reMotion.Easing.bounce };
256
+ case 'power1':
257
+ return { duration: 500, easing: reMotion.Easing.bezier(0.17, 0.42, 0.51, 0.97) };
258
+ case 'power2':
259
+ return { duration: 500, easing: reMotion.Easing.bezier(0.07, 0.11, 0.13, 1) };
260
+ case 'power3':
261
+ return { duration: 500, easing: reMotion.Easing.bezier(0.09, 0.7, 0.16, 1.04) };
262
+ case 'power4':
263
+ return { duration: 500, easing: reMotion.Easing.bezier(0.05, 0.54, 0, 1.03) };
264
+ case 'linear':
265
+ return { duration: 500, easing: reMotion.Easing.linear };
266
+ case 'easein':
267
+ return { duration: 500, easing: reMotion.Easing.in(reMotion.Easing.ease) };
268
+ case 'easeout':
269
+ return { duration: 500, easing: reMotion.Easing.out(reMotion.Easing.ease) };
270
+ case 'easeinout':
271
+ return { duration: 500, easing: reMotion.Easing.inOut(reMotion.Easing.ease) };
246
272
  case 'ease':
247
273
  default:
248
274
  return { mass: 1, friction: 26, tension: 170 };
@@ -255,6 +281,14 @@ var AnimationConfigUtils = {
255
281
  EASE: getInitialConfig('ease'),
256
282
  STIFF: getInitialConfig('stiff'),
257
283
  WOOBLE: getInitialConfig('wooble'),
284
+ EASE_IN: getInitialConfig('easein'),
285
+ EASE_OUT: getInitialConfig('easeout'),
286
+ EASE_IN_OUT: getInitialConfig('easeinout'),
287
+ POWER1: getInitialConfig('power1'),
288
+ POWER2: getInitialConfig('power2'),
289
+ POWER3: getInitialConfig('power3'),
290
+ POWER4: getInitialConfig('power4'),
291
+ LINEAR: getInitialConfig('linear'),
258
292
  };
259
293
 
260
294
  /**
@@ -1131,6 +1165,7 @@ exports.ScrollableBlock = ScrollableBlock;
1131
1165
  exports.bInterpolate = bInterpolate;
1132
1166
  exports.bin = bin;
1133
1167
  exports.clamp = clamp;
1168
+ exports.delay = delay;
1134
1169
  exports.makeAnimatedComponent = makeAnimatedComponent;
1135
1170
  exports.mix = mix;
1136
1171
  exports.move = move;