react-ui-animate 1.2.1 → 1.4.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.
Files changed (108) hide show
  1. package/dist/{animate → animation}/getInitialConfig.d.ts +0 -0
  2. package/dist/animation/index.d.ts +4 -0
  3. package/dist/{Interpolation.d.ts → animation/interpolation.d.ts} +0 -0
  4. package/dist/{Modules.d.ts → animation/modules.d.ts} +15 -0
  5. package/dist/{useAnimatedValue.d.ts → animation/useAnimatedValue.d.ts} +2 -2
  6. package/dist/{useMountedValue.d.ts → animation/useMountedValue.d.ts} +3 -3
  7. package/dist/gestures/controllers/DragGesture.d.ts +17 -0
  8. package/dist/gestures/controllers/Gesture.d.ts +20 -0
  9. package/dist/gestures/controllers/MouseMoveGesture.d.ts +13 -0
  10. package/dist/gestures/controllers/ScrollGesture.d.ts +14 -0
  11. package/dist/gestures/controllers/WheelGesture.d.ts +15 -0
  12. package/dist/gestures/controllers/index.d.ts +4 -0
  13. package/dist/gestures/eventAttacher.d.ts +11 -0
  14. package/dist/{animate → gestures}/hooks/index.d.ts +2 -4
  15. package/dist/gestures/hooks/useDrag.d.ts +4 -0
  16. package/dist/gestures/hooks/useGesture.d.ts +9 -0
  17. package/dist/gestures/hooks/useMouseMove.d.ts +4 -0
  18. package/dist/gestures/hooks/useRecognizer.d.ts +10 -0
  19. package/dist/gestures/hooks/useScroll.d.ts +4 -0
  20. package/dist/gestures/hooks/useWheel.d.ts +4 -0
  21. package/dist/gestures/index.d.ts +2 -0
  22. package/dist/{Math.d.ts → gestures/math.d.ts} +0 -0
  23. package/dist/{animate/Types.d.ts → gestures/types.d.ts} +17 -30
  24. package/dist/gestures/withDefault.d.ts +4 -0
  25. package/dist/hooks/index.d.ts +0 -4
  26. package/dist/hooks/useMeasure.d.ts +10 -1
  27. package/dist/hooks/useWindowDimension.d.ts +7 -1
  28. package/dist/index.d.ts +2 -5
  29. package/dist/index.js +848 -707
  30. package/dist/index.js.map +1 -1
  31. package/dist/utils/index.d.ts +1 -0
  32. package/dist/{animate → utils}/isDefined.d.ts +0 -0
  33. package/package.json +6 -3
  34. package/src/{getInitialConfig.ts → animation/getInitialConfig.ts} +0 -0
  35. package/src/animation/index.ts +4 -0
  36. package/src/{Interpolation.ts → animation/interpolation.ts} +0 -0
  37. package/src/{Modules.tsx → animation/modules.tsx} +26 -1
  38. package/src/{useAnimatedValue.ts → animation/useAnimatedValue.ts} +5 -8
  39. package/src/{useMountedValue.ts → animation/useMountedValue.ts} +4 -7
  40. package/src/gestures/controllers/DragGesture.ts +176 -0
  41. package/src/gestures/controllers/Gesture.ts +54 -0
  42. package/src/gestures/controllers/MouseMoveGesture.ts +111 -0
  43. package/src/gestures/controllers/ScrollGesture.ts +107 -0
  44. package/src/gestures/controllers/WheelGesture.ts +123 -0
  45. package/src/gestures/controllers/index.ts +4 -0
  46. package/src/gestures/eventAttacher.ts +67 -0
  47. package/src/gestures/hooks/index.ts +5 -0
  48. package/src/gestures/hooks/useDrag.ts +14 -0
  49. package/src/gestures/hooks/useGesture.ts +38 -0
  50. package/src/gestures/hooks/useMouseMove.ts +11 -0
  51. package/src/gestures/hooks/useRecognizer.ts +59 -0
  52. package/src/gestures/hooks/useScroll.ts +11 -0
  53. package/src/gestures/hooks/useWheel.ts +11 -0
  54. package/src/gestures/index.ts +2 -0
  55. package/src/{Math.ts → gestures/math.ts} +0 -0
  56. package/src/{Types.ts → gestures/types.ts} +19 -36
  57. package/src/gestures/withDefault.ts +3 -0
  58. package/src/hooks/index.ts +0 -4
  59. package/src/hooks/useMeasure.ts +11 -1
  60. package/src/hooks/useOutsideClick.ts +3 -2
  61. package/src/hooks/useWindowDimension.ts +7 -1
  62. package/src/index.ts +2 -5
  63. package/src/utils/index.ts +1 -0
  64. package/src/{isDefined.ts → utils/isDefined.ts} +0 -0
  65. package/tsconfig.json +1 -0
  66. package/dist/Types.d.ts +0 -64
  67. package/dist/animate/Interpolation.d.ts +0 -20
  68. package/dist/animate/Math.d.ts +0 -34
  69. package/dist/animate/Modules.d.ts +0 -32
  70. package/dist/animate/controllers/EventAttacher.d.ts +0 -8
  71. package/dist/animate/controllers/index.d.ts +0 -1
  72. package/dist/animate/hooks/useDrag.d.ts +0 -5
  73. package/dist/animate/hooks/useMeasure.d.ts +0 -5
  74. package/dist/animate/hooks/useMouseMove.d.ts +0 -5
  75. package/dist/animate/hooks/useOutsideClick.d.ts +0 -2
  76. package/dist/animate/hooks/useScroll.d.ts +0 -5
  77. package/dist/animate/hooks/useWheel.d.ts +0 -5
  78. package/dist/animate/hooks/useWindowDimension.d.ts +0 -3
  79. package/dist/animate/index.d.ts +0 -8
  80. package/dist/animate/useAnimatedValue.d.ts +0 -30
  81. package/dist/animate/useMountedValue.d.ts +0 -22
  82. package/dist/controllers/EventAttacher.d.ts +0 -8
  83. package/dist/controllers/index.d.ts +0 -1
  84. package/dist/core/Animation.d.ts +0 -13
  85. package/dist/core/Bezier.d.ts +0 -8
  86. package/dist/core/Colors.d.ts +0 -25
  87. package/dist/core/Easing.d.ts +0 -40
  88. package/dist/core/Interpolation.d.ts +0 -38
  89. package/dist/core/RequestAnimationFrame.d.ts +0 -8
  90. package/dist/core/SpringAnimation.d.ts +0 -39
  91. package/dist/core/Tags.d.ts +0 -2
  92. package/dist/core/TimingAnimation.d.ts +0 -34
  93. package/dist/core/TransformStyles.d.ts +0 -8
  94. package/dist/core/animated.d.ts +0 -9
  95. package/dist/core/index.d.ts +0 -7
  96. package/dist/core/useTransition.d.ts +0 -46
  97. package/dist/getInitialConfig.d.ts +0 -3
  98. package/dist/hooks/useDrag.d.ts +0 -5
  99. package/dist/hooks/useMouseMove.d.ts +0 -5
  100. package/dist/hooks/useScroll.d.ts +0 -5
  101. package/dist/hooks/useWheel.d.ts +0 -5
  102. package/dist/isDefined.d.ts +0 -1
  103. package/src/controllers/EventAttacher.ts +0 -35
  104. package/src/controllers/index.ts +0 -1
  105. package/src/hooks/useDrag.ts +0 -231
  106. package/src/hooks/useMouseMove.ts +0 -123
  107. package/src/hooks/useScroll.ts +0 -124
  108. package/src/hooks/useWheel.ts +0 -144
@@ -1,124 +0,0 @@
1
- import * as React from "react";
2
- import { ScrollEventType, Vector2 } from "../Types";
3
- import { clamp } from "../Math";
4
- import { attachEvents } from "../controllers";
5
-
6
- export function useScroll(
7
- callback: (event: ScrollEventType) => void,
8
- deps?: React.DependencyList
9
- ) {
10
- const ref = React.useRef<any>(null);
11
-
12
- const scrollXY = React.useRef<Vector2>({
13
- x: 0,
14
- y: 0,
15
- });
16
- const previousScrollXY = React.useRef<Vector2>({
17
- x: 0,
18
- y: 0,
19
- });
20
- const isScrolling = React.useRef<boolean>(false);
21
- const scrollDirection = React.useRef<Vector2>({ x: 0, y: 0 });
22
- const _isScrolling = React.useRef<any>(-1); // For checking scrolling and add throttle
23
-
24
- const lastTimeStamp = React.useRef<number>(0);
25
- const velocity = React.useRef<Vector2>({ x: 0, y: 0 });
26
-
27
- const callbackRef = React.useRef<(event: ScrollEventType) => void>(callback);
28
-
29
- const handleCallback: () => void = () => {
30
- if (callbackRef) {
31
- callbackRef.current({
32
- isScrolling: isScrolling.current,
33
- scrollX: scrollXY.current.x,
34
- scrollY: scrollXY.current.y,
35
- velocityX: velocity.current.x,
36
- velocityY: velocity.current.y,
37
- directionX: scrollDirection.current.x,
38
- directionY: scrollDirection.current.y,
39
- });
40
- }
41
- };
42
-
43
- // Reinitiate callback when dependency change
44
- React.useEffect(() => {
45
- callbackRef.current = callback;
46
-
47
- return () => {
48
- callbackRef.current = () => false;
49
- };
50
- }, deps);
51
-
52
- React.useEffect(() => {
53
- const _refElement = ref.current;
54
-
55
- const scrollCallback = ({ x, y }: Vector2) => {
56
- const now: number = Date.now();
57
- const deltaTime = Math.min(now - lastTimeStamp.current, 64);
58
- lastTimeStamp.current = now;
59
- const t = deltaTime / 1000; // seconds
60
-
61
- scrollXY.current = { x, y };
62
-
63
- // Clear if scrolling
64
- if (_isScrolling.current !== -1) {
65
- isScrolling.current = true;
66
- clearTimeout(_isScrolling.current);
67
- }
68
-
69
- _isScrolling.current = setTimeout(() => {
70
- isScrolling.current = false;
71
- scrollDirection.current = { x: 0, y: 0 };
72
-
73
- // Reset Velocity
74
- velocity.current = { x: 0, y: 0 };
75
-
76
- handleCallback(); // Debounce 250milliseconds
77
- }, 250);
78
-
79
- const diffX = scrollXY.current.x - previousScrollXY.current.x;
80
- const diffY = scrollXY.current.y - previousScrollXY.current.y;
81
-
82
- scrollDirection.current = {
83
- x: Math.sign(diffX),
84
- y: Math.sign(diffY),
85
- };
86
-
87
- velocity.current = {
88
- x: clamp(diffX / t / 1000, -5, 5),
89
- y: clamp(diffY / t / 1000, -5, 5),
90
- };
91
-
92
- previousScrollXY.current = {
93
- x: scrollXY.current.x,
94
- y: scrollXY.current.y,
95
- };
96
-
97
- handleCallback();
98
- };
99
-
100
- const scrollListener: () => void = () => {
101
- const { pageYOffset: y, pageXOffset: x } = window;
102
- scrollCallback({ x, y });
103
- };
104
-
105
- const scrollElementListener: () => void = () => {
106
- const x = _refElement?.scrollLeft || 0;
107
- const y = _refElement?.scrollTop || 0;
108
- scrollCallback({ x, y });
109
- };
110
-
111
- var subscribe: any;
112
- if (_refElement) {
113
- subscribe = attachEvents(_refElement, [
114
- ["scroll", scrollElementListener],
115
- ]);
116
- } else {
117
- subscribe = attachEvents(window, [["scroll", scrollListener]]);
118
- }
119
-
120
- return () => subscribe && subscribe();
121
- }, []);
122
-
123
- return () => ({ ref }); // ...bind()
124
- }
@@ -1,144 +0,0 @@
1
- import * as React from "react";
2
- import { WheelEventType, Vector2 } from "../Types";
3
- import { clamp } from "../Math";
4
- import { attachEvents } from "../controllers";
5
-
6
- const LINE_HEIGHT = 40;
7
- const PAGE_HEIGHT = 800;
8
-
9
- export function useWheel(
10
- callback: (event: WheelEventType) => void,
11
- deps?: React.DependencyList
12
- ) {
13
- const ref = React.useRef<any>(null);
14
-
15
- const isWheeling = React.useRef<boolean>(false);
16
- const isWheelingID = React.useRef<any>(-1);
17
- const movementXY = React.useRef<Vector2>({
18
- x: 0,
19
- y: 0,
20
- });
21
- const previousMovementXY = React.useRef<Vector2>({
22
- x: 0,
23
- y: 0,
24
- });
25
- const deltaXY = React.useRef<Vector2>({
26
- x: 0,
27
- y: 0,
28
- });
29
- const direction = React.useRef<Vector2>({ x: 0, y: 0 });
30
-
31
- const lastTimeStamp = React.useRef<number>(0);
32
- const velocity = React.useRef<Vector2>({ x: 0, y: 0 });
33
-
34
- // Holds offsets
35
- const offset = React.useRef<Vector2>({ x: 0, y: 0 });
36
- const translation = React.useRef<Vector2>({ x: 0, y: 0 });
37
-
38
- const callbackRef = React.useRef<(event: WheelEventType) => void>(callback);
39
-
40
- const handleCallback: () => void = () => {
41
- if (callbackRef) {
42
- callbackRef.current({
43
- target: ref.current,
44
- isWheeling: isWheeling.current,
45
- deltaX: deltaXY.current.x,
46
- deltaY: deltaXY.current.y,
47
- directionX: direction.current.x,
48
- directionY: direction.current.y,
49
- movementX: movementXY.current.x,
50
- movementY: movementXY.current.y,
51
- offsetX: offset.current.x,
52
- offsetY: offset.current.y,
53
- velocityX: velocity.current.x,
54
- velocityY: velocity.current.y,
55
- });
56
- }
57
- };
58
-
59
- // Reinitiate callback when dependency change
60
- React.useEffect(() => {
61
- callbackRef.current = callback;
62
-
63
- return () => {
64
- callbackRef.current = () => false;
65
- };
66
- }, deps);
67
-
68
- React.useEffect(() => {
69
- const _refElement = ref.current;
70
-
71
- const wheelListener = (event: React.WheelEvent) => {
72
- let { deltaX, deltaY, deltaMode } = event;
73
-
74
- const now: number = Date.now();
75
- const deltaTime = Math.min(now - lastTimeStamp.current, 64);
76
- lastTimeStamp.current = now;
77
- const t = deltaTime / 1000; // seconds
78
-
79
- isWheeling.current = true;
80
-
81
- if (isWheelingID.current !== -1) {
82
- isWheeling.current = true;
83
- clearTimeout(isWheelingID.current);
84
- }
85
-
86
- isWheelingID.current = setTimeout(() => {
87
- isWheeling.current = false;
88
- translation.current = { x: offset.current.x, y: offset.current.y };
89
- handleCallback();
90
-
91
- velocity.current = { x: 0, y: 0 }; // Reset Velocity
92
- movementXY.current = { x: 0, y: 0 };
93
- }, 200);
94
-
95
- // normalize wheel values, especially for Firefox
96
- if (deltaMode === 1) {
97
- deltaX *= LINE_HEIGHT;
98
- deltaY *= LINE_HEIGHT;
99
- } else if (deltaMode === 2) {
100
- deltaX *= PAGE_HEIGHT;
101
- deltaY *= PAGE_HEIGHT;
102
- }
103
-
104
- deltaXY.current = { x: deltaX, y: deltaY };
105
- movementXY.current = {
106
- x: movementXY.current.x + deltaX,
107
- y: movementXY.current.y + deltaY,
108
- };
109
- offset.current = {
110
- x: translation.current.x + movementXY.current.x,
111
- y: translation.current.y + movementXY.current.y,
112
- };
113
-
114
- const diffX = movementXY.current.x - previousMovementXY.current.x;
115
- const diffY = movementXY.current.y - previousMovementXY.current.y;
116
-
117
- direction.current = {
118
- x: Math.sign(diffX),
119
- y: Math.sign(diffY),
120
- };
121
-
122
- velocity.current = {
123
- x: clamp(diffX / t / 1000, -20, 20),
124
- y: clamp(diffY / t / 1000, -20, 20),
125
- };
126
-
127
- previousMovementXY.current = {
128
- x: movementXY.current.x,
129
- y: movementXY.current.y,
130
- };
131
-
132
- handleCallback();
133
- };
134
-
135
- var subscribe: any;
136
- if (_refElement) {
137
- subscribe = attachEvents(_refElement, [["wheel", wheelListener]]);
138
- }
139
-
140
- return () => subscribe && subscribe();
141
- }, []);
142
-
143
- return () => ({ ref }); // ...bind()
144
- }