react-ui-animate 1.4.6 → 2.0.0-rc.3
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/.vscode/settings.json +3 -0
- package/dist/animation/animationType.d.ts +15 -0
- package/dist/animation/getInitialConfig.d.ts +3 -3
- package/dist/animation/index.d.ts +6 -4
- package/dist/animation/interpolation.d.ts +3 -11
- package/dist/animation/modules/AnimatedBlock.d.ts +8 -0
- package/dist/animation/modules/AnimatedImage.d.ts +8 -0
- package/dist/animation/modules/AnimatedInline.d.ts +8 -0
- package/dist/animation/modules/MountedBlock.d.ts +18 -0
- package/dist/animation/modules/ScrollableBlock.d.ts +22 -0
- package/dist/animation/modules/TransitionBlock.d.ts +18 -0
- package/dist/animation/modules/index.d.ts +6 -0
- package/dist/animation/useAnimatedValue.d.ts +17 -25
- package/dist/animation/useMountedValue.d.ts +9 -17
- package/dist/gestures/controllers/MouseMoveGesture.d.ts +2 -2
- package/dist/gestures/controllers/ScrollGesture.d.ts +2 -2
- package/dist/gestures/controllers/WheelGesture.d.ts +2 -2
- package/dist/gestures/controllers/index.d.ts +4 -4
- package/dist/gestures/eventAttacher.d.ts +1 -1
- package/dist/gestures/hooks/index.d.ts +5 -5
- package/dist/gestures/hooks/useDrag.d.ts +1 -1
- package/dist/gestures/hooks/useGesture.d.ts +1 -1
- package/dist/gestures/hooks/useMouseMove.d.ts +1 -1
- package/dist/gestures/hooks/useRecognizer.d.ts +1 -1
- package/dist/gestures/hooks/useScroll.d.ts +1 -1
- package/dist/gestures/hooks/useWheel.d.ts +1 -1
- package/dist/gestures/index.d.ts +2 -2
- package/dist/index.d.ts +5 -4
- package/dist/index.js +234 -216
- package/dist/index.js.map +1 -1
- package/dist/utils/delay.d.ts +5 -0
- package/dist/utils/index.d.ts +2 -1
- package/package.json +2 -2
- package/src/animation/animationType.ts +17 -0
- package/src/animation/getInitialConfig.ts +46 -16
- package/src/animation/index.ts +10 -4
- package/src/animation/interpolation.ts +5 -38
- package/src/animation/modules/AnimatedBlock.ts +8 -0
- package/src/animation/modules/AnimatedImage.ts +8 -0
- package/src/animation/modules/AnimatedInline.ts +8 -0
- package/src/animation/modules/MountedBlock.tsx +25 -0
- package/src/animation/modules/ScrollableBlock.tsx +62 -0
- package/src/animation/modules/TransitionBlock.tsx +26 -0
- package/src/animation/modules/index.ts +6 -0
- package/src/animation/useAnimatedValue.ts +31 -92
- package/src/animation/useMountedValue.ts +29 -44
- package/src/gestures/controllers/MouseMoveGesture.ts +8 -8
- package/src/gestures/controllers/ScrollGesture.ts +7 -7
- package/src/gestures/controllers/WheelGesture.ts +6 -6
- package/src/gestures/controllers/index.ts +4 -4
- package/src/gestures/eventAttacher.ts +15 -15
- package/src/gestures/hooks/index.ts +5 -5
- package/src/gestures/hooks/useDrag.ts +5 -5
- package/src/gestures/hooks/useGesture.ts +8 -8
- package/src/gestures/hooks/useMouseMove.ts +5 -5
- package/src/gestures/hooks/useRecognizer.ts +2 -2
- package/src/gestures/hooks/useScroll.ts +5 -5
- package/src/gestures/hooks/useWheel.ts +5 -5
- package/src/gestures/index.ts +2 -2
- package/src/index.ts +5 -4
- package/src/utils/delay.ts +9 -0
- package/src/utils/index.ts +2 -1
- package/dist/animation/modules.d.ts +0 -47
- package/src/animation/modules.tsx +0 -105
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { TransitionValue } from '@raidipesh78/re-motion';
|
|
3
|
+
import { useMountedValue, UseMountedValueConfig } from '../useMountedValue';
|
|
4
|
+
|
|
5
|
+
interface MountedBlockProps {
|
|
6
|
+
state: boolean;
|
|
7
|
+
children: (animation: { value: TransitionValue }) => React.ReactNode;
|
|
8
|
+
config: UseMountedValueConfig;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* MountedBlock - Higher order component which handles mounting and unmounting of a component.
|
|
13
|
+
* @prop { boolean } state - Boolean indicating the component should mount or unmount.
|
|
14
|
+
* @prop { function } children - Child as a function with `AnimatedValue` on `.value` property.
|
|
15
|
+
* @prop { UseMountedValueConfig } config - Animation configuration.
|
|
16
|
+
*/
|
|
17
|
+
export const MountedBlock = ({
|
|
18
|
+
state,
|
|
19
|
+
children,
|
|
20
|
+
config,
|
|
21
|
+
}: MountedBlockProps) => {
|
|
22
|
+
const open = useMountedValue(state, config);
|
|
23
|
+
|
|
24
|
+
return <>{open((animation, mounted) => mounted && children(animation))}</>;
|
|
25
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { TransitionValue } from '@raidipesh78/re-motion';
|
|
3
|
+
import { useAnimatedValue, UseAnimatedValueConfig } from '../useAnimatedValue';
|
|
4
|
+
|
|
5
|
+
interface ScrollableBlockProps {
|
|
6
|
+
children?: (animation: { value: TransitionValue }) => React.ReactNode;
|
|
7
|
+
direction?: 'single' | 'both';
|
|
8
|
+
threshold?: number;
|
|
9
|
+
animationConfig?: UseAnimatedValueConfig;
|
|
10
|
+
}
|
|
11
|
+
|
|
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 { UseAnimatedValueConfig } animationConfig - Animation config
|
|
20
|
+
*/
|
|
21
|
+
export const ScrollableBlock = (props: ScrollableBlockProps) => {
|
|
22
|
+
const {
|
|
23
|
+
children,
|
|
24
|
+
direction = 'single',
|
|
25
|
+
animationConfig,
|
|
26
|
+
threshold = 0.2,
|
|
27
|
+
} = props;
|
|
28
|
+
const scrollableBlockRef = React.useRef<HTMLDivElement>(null);
|
|
29
|
+
const animation = useAnimatedValue(0, animationConfig); // 0: not intersecting | 1: intersecting
|
|
30
|
+
|
|
31
|
+
React.useEffect(() => {
|
|
32
|
+
const _scrollableBlock = scrollableBlockRef.current;
|
|
33
|
+
|
|
34
|
+
const observer = new IntersectionObserver(
|
|
35
|
+
function ([entry]) {
|
|
36
|
+
const { isIntersecting } = entry;
|
|
37
|
+
|
|
38
|
+
if (isIntersecting) {
|
|
39
|
+
animation.value = 1;
|
|
40
|
+
} else {
|
|
41
|
+
if (direction === 'both') animation.value = 0;
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
root: null, // FOR VIEWPORT ONLY
|
|
46
|
+
threshold,
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
if (_scrollableBlock) {
|
|
51
|
+
observer.observe(_scrollableBlock);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return () => {
|
|
55
|
+
if (_scrollableBlock) {
|
|
56
|
+
observer.unobserve(_scrollableBlock);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}, []);
|
|
60
|
+
|
|
61
|
+
return <div ref={scrollableBlockRef}>{children && children(animation)}</div>;
|
|
62
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { TransitionValue } from '@raidipesh78/re-motion';
|
|
3
|
+
import { bin } from '../../gestures/math';
|
|
4
|
+
import { useAnimatedValue, UseAnimatedValueConfig } from '../useAnimatedValue';
|
|
5
|
+
|
|
6
|
+
interface TransitionBlockProps {
|
|
7
|
+
state: boolean;
|
|
8
|
+
children: (animation: { value: TransitionValue }) => React.ReactNode;
|
|
9
|
+
config?: UseAnimatedValueConfig;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* TransitionBlock - Higher order component which animates on state change.
|
|
14
|
+
* @prop { boolean } state - Boolean indicating the current state of animation, usually `false = 0 and true = 1`.
|
|
15
|
+
* @prop { function } children - Child as a function with `AnimatedValue` on `.value` property.
|
|
16
|
+
* @prop { UseAnimatedValueConfig } config - Animation configuration.
|
|
17
|
+
*/
|
|
18
|
+
export const TransitionBlock = ({
|
|
19
|
+
state,
|
|
20
|
+
children,
|
|
21
|
+
config,
|
|
22
|
+
}: TransitionBlockProps) => {
|
|
23
|
+
const amv = useAnimatedValue(bin(state), config);
|
|
24
|
+
|
|
25
|
+
return <>{children(amv)}</>;
|
|
26
|
+
};
|
|
@@ -1,131 +1,70 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
useTransition,
|
|
4
|
-
TransitionValue,
|
|
5
|
-
ResultType,
|
|
6
|
-
} from "@raidipesh78/re-motion";
|
|
7
|
-
import { InitialConfigType, getInitialConfig } from "./getInitialConfig";
|
|
1
|
+
import { useTransition, UseTransitionConfig } from '@raidipesh78/re-motion';
|
|
2
|
+
import { AnimationConfigUtils } from './animationType';
|
|
8
3
|
|
|
9
4
|
// useAnimatedValue value type
|
|
10
|
-
type
|
|
5
|
+
type Length = number | string;
|
|
6
|
+
type AnimatedValueType = Length;
|
|
11
7
|
|
|
12
|
-
|
|
13
|
-
* getValue checks for type of initialValue and throws error
|
|
14
|
-
* for type other than AnimatedValueType
|
|
15
|
-
*/
|
|
16
|
-
const getValue = (value: AnimatedValueType) => {
|
|
17
|
-
if (typeof value === "number" || typeof value === "string") {
|
|
18
|
-
return value;
|
|
19
|
-
} else {
|
|
20
|
-
throw new Error(
|
|
21
|
-
"Invalid Value! Animated value only accepts string or number."
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// General config type
|
|
27
|
-
export interface GenericAnimationConfig {
|
|
28
|
-
duration?: number;
|
|
29
|
-
mass?: number;
|
|
30
|
-
friction?: number;
|
|
31
|
-
tension?: number;
|
|
32
|
-
easing?: (t: number) => number;
|
|
33
|
-
delay?: number;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface UseAnimatedValueConfig extends GenericAnimationConfig {
|
|
37
|
-
animationType?: InitialConfigType;
|
|
38
|
-
onAnimationEnd?: (value: ResultType) => void;
|
|
39
|
-
listener?: (value: number) => void;
|
|
40
|
-
immediate?: boolean;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type ValueReturnType =
|
|
44
|
-
| TransitionValue
|
|
45
|
-
| number
|
|
46
|
-
| string
|
|
47
|
-
| { toValue: number | string; immediate?: boolean };
|
|
8
|
+
export interface UseAnimatedValueConfig extends UseTransitionConfig {}
|
|
48
9
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
10
|
+
type AssignValue = {
|
|
11
|
+
toValue: Length;
|
|
12
|
+
config?: UseAnimatedValueConfig;
|
|
13
|
+
};
|
|
14
|
+
export type ValueType =
|
|
15
|
+
| Length
|
|
16
|
+
| AssignValue
|
|
17
|
+
| ((update: (next: AssignValue) => Promise<any>) => void);
|
|
53
18
|
|
|
54
19
|
/**
|
|
55
|
-
* useAnimatedValue
|
|
20
|
+
* `useAnimatedValue` returns an animation value with `.value` and `.currentValue` property which is
|
|
21
|
+
* initialized when passed to argument (`initialValue`). The retured value persist until the lifetime of
|
|
22
|
+
* a component. It doesnot cast any re-renders which can is very good for performance optimization.
|
|
23
|
+
* @param { string | number } initialValue - Initial value
|
|
24
|
+
* @param { UseAnimatedValueConfig } config - Animation configuration object.
|
|
56
25
|
*/
|
|
57
26
|
export function useAnimatedValue(
|
|
58
27
|
initialValue: AnimatedValueType,
|
|
59
28
|
config?: UseAnimatedValueConfig
|
|
60
|
-
)
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const animationType = config?.animationType ?? "ease"; // Defines default animation
|
|
65
|
-
const onAnimationEnd = config?.onAnimationEnd;
|
|
66
|
-
const listener = config?.listener;
|
|
67
|
-
|
|
68
|
-
const [animation, setAnimation] = useTransition(_initialValue, {
|
|
69
|
-
...getInitialConfig(animationType),
|
|
29
|
+
) {
|
|
30
|
+
const [animation, setAnimation] = useTransition(initialValue, {
|
|
31
|
+
...AnimationConfigUtils.EASE,
|
|
70
32
|
...config,
|
|
71
|
-
onRest: function (result: any) {
|
|
72
|
-
if (result.finished) {
|
|
73
|
-
onAnimationEnd && onAnimationEnd(result.value);
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
onChange: function (value: number) {
|
|
77
|
-
listener && listener(value);
|
|
78
|
-
},
|
|
79
33
|
});
|
|
80
34
|
|
|
81
|
-
// doesn't fire on initial render
|
|
82
|
-
React.useEffect(() => {
|
|
83
|
-
if (!_isInitial.current) {
|
|
84
|
-
setAnimation({ toValue: _initialValue });
|
|
85
|
-
}
|
|
86
|
-
_isInitial.current = false;
|
|
87
|
-
}, [_initialValue]);
|
|
88
|
-
|
|
89
35
|
const targetObject: {
|
|
90
36
|
value: any;
|
|
91
|
-
currentValue:
|
|
37
|
+
currentValue: number | string;
|
|
92
38
|
} = {
|
|
93
39
|
value: animation,
|
|
94
40
|
currentValue: animation.get(),
|
|
95
41
|
};
|
|
96
42
|
|
|
97
43
|
return new Proxy(targetObject, {
|
|
98
|
-
set: function (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
value: number | string | { toValue: number | string; immediate?: boolean }
|
|
102
|
-
) {
|
|
103
|
-
if (key === "value") {
|
|
104
|
-
if (typeof value === "number" || typeof value === "string") {
|
|
44
|
+
set: function (_, key, value: ValueType) {
|
|
45
|
+
if (key === 'value') {
|
|
46
|
+
if (typeof value === 'number' || typeof value === 'string') {
|
|
105
47
|
setAnimation({ toValue: value });
|
|
106
|
-
} else if (typeof value ===
|
|
107
|
-
setAnimation(
|
|
108
|
-
toValue: value.toValue,
|
|
109
|
-
config: { immediate: value.immediate },
|
|
110
|
-
});
|
|
48
|
+
} else if (typeof value === 'object' || typeof value === 'function') {
|
|
49
|
+
setAnimation(value);
|
|
111
50
|
}
|
|
112
51
|
|
|
113
52
|
return true;
|
|
114
53
|
}
|
|
115
54
|
|
|
116
|
-
throw new Error(
|
|
55
|
+
throw new Error('You cannot set any other property to animation node.');
|
|
117
56
|
},
|
|
118
57
|
get: function (_, key) {
|
|
119
|
-
if (key ===
|
|
58
|
+
if (key === 'value') {
|
|
120
59
|
return animation;
|
|
121
60
|
}
|
|
122
61
|
|
|
123
|
-
if (key ===
|
|
62
|
+
if (key === 'currentValue') {
|
|
124
63
|
return animation.get();
|
|
125
64
|
}
|
|
126
65
|
|
|
127
66
|
throw new Error(
|
|
128
|
-
|
|
67
|
+
'You cannot access any other property from animation node.'
|
|
129
68
|
);
|
|
130
69
|
},
|
|
131
70
|
});
|
|
@@ -1,50 +1,42 @@
|
|
|
1
|
-
import * as React from
|
|
1
|
+
import * as React from 'react';
|
|
2
2
|
import {
|
|
3
3
|
useTransition,
|
|
4
4
|
TransitionValue,
|
|
5
|
-
|
|
6
|
-
} from
|
|
5
|
+
UseMountConfig,
|
|
6
|
+
} from '@raidipesh78/re-motion';
|
|
7
7
|
|
|
8
|
-
export interface
|
|
9
|
-
enterDuration?: number;
|
|
10
|
-
exitDuration?: number;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface UseMountedValueConfig {
|
|
14
|
-
from: number;
|
|
15
|
-
enter: number;
|
|
16
|
-
exit: number;
|
|
17
|
-
config?: InnerUseMountedValueConfig;
|
|
18
|
-
}
|
|
8
|
+
export interface UseMountedValueConfig extends UseMountConfig {}
|
|
19
9
|
|
|
20
10
|
/**
|
|
21
|
-
* useMountedValue handles mounting and unmounting of a component
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @
|
|
11
|
+
* `useMountedValue` handles mounting and unmounting of a component which captures current state
|
|
12
|
+
* passed as an arugment (`state`) and exposes the shadow state which handles the mount and unmount
|
|
13
|
+
* of a component.
|
|
14
|
+
* @param { boolean } state - Boolean indicating the component should mount or unmount.
|
|
15
|
+
* @param { UseMountedValueConfig } config - Animation configuration.
|
|
25
16
|
*/
|
|
26
17
|
export function useMountedValue(state: boolean, config: UseMountedValueConfig) {
|
|
27
|
-
const
|
|
18
|
+
const initial = React.useRef(true);
|
|
28
19
|
const [mounted, setMounted] = React.useState(state);
|
|
29
|
-
const {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
20
|
+
const {
|
|
21
|
+
from,
|
|
22
|
+
enter,
|
|
23
|
+
exit,
|
|
24
|
+
config: innerConfig,
|
|
25
|
+
enterConfig,
|
|
26
|
+
exitConfig,
|
|
27
|
+
} = React.useRef(config).current;
|
|
28
|
+
const [animation, setAnimation] = useTransition(from, innerConfig);
|
|
35
29
|
|
|
36
30
|
React.useEffect(() => {
|
|
37
31
|
if (state) {
|
|
38
|
-
|
|
32
|
+
initial.current = true;
|
|
39
33
|
setMounted(true);
|
|
40
34
|
} else {
|
|
41
|
-
|
|
35
|
+
initial.current = false;
|
|
42
36
|
setAnimation(
|
|
43
37
|
{
|
|
44
38
|
toValue: exit,
|
|
45
|
-
config:
|
|
46
|
-
duration: exitDuration,
|
|
47
|
-
},
|
|
39
|
+
config: exitConfig,
|
|
48
40
|
},
|
|
49
41
|
function ({ finished }) {
|
|
50
42
|
if (finished) {
|
|
@@ -56,24 +48,17 @@ export function useMountedValue(state: boolean, config: UseMountedValueConfig) {
|
|
|
56
48
|
}, [state]);
|
|
57
49
|
|
|
58
50
|
React.useEffect(() => {
|
|
59
|
-
if (mounted && initial) {
|
|
60
|
-
setAnimation(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
duration: enterDuration,
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
function () {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
);
|
|
51
|
+
if (mounted && initial.current) {
|
|
52
|
+
setAnimation({
|
|
53
|
+
toValue: enter,
|
|
54
|
+
config: enterConfig,
|
|
55
|
+
});
|
|
71
56
|
}
|
|
72
|
-
}, [mounted, initial]);
|
|
57
|
+
}, [mounted, initial.current]);
|
|
73
58
|
|
|
74
59
|
return function (
|
|
75
60
|
callback: (
|
|
76
|
-
{ value }: { value: TransitionValue },
|
|
61
|
+
{ value: animation }: { value: TransitionValue },
|
|
77
62
|
mounted: boolean
|
|
78
63
|
) => React.ReactNode
|
|
79
64
|
) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { attachEvents } from
|
|
2
|
-
import { Vector2 } from
|
|
3
|
-
import { clamp } from
|
|
4
|
-
import { withDefault } from
|
|
5
|
-
import { Gesture } from
|
|
1
|
+
import { attachEvents } from '../eventAttacher';
|
|
2
|
+
import { Vector2 } from '../types';
|
|
3
|
+
import { clamp } from '../math';
|
|
4
|
+
import { withDefault } from '../withDefault';
|
|
5
|
+
import { Gesture } from './Gesture';
|
|
6
6
|
|
|
7
7
|
export class MouseMoveGesture extends Gesture {
|
|
8
8
|
event?: MouseEvent;
|
|
@@ -18,16 +18,16 @@ export class MouseMoveGesture extends Gesture {
|
|
|
18
18
|
if (this.targetElement) {
|
|
19
19
|
this._subscribe = attachEvents(
|
|
20
20
|
[this.targetElement],
|
|
21
|
-
[[
|
|
21
|
+
[['mousemove', this.onMouseMove.bind(this)]]
|
|
22
22
|
);
|
|
23
23
|
} else if (this.targetElements.length > 0) {
|
|
24
24
|
this._subscribe = attachEvents(this.targetElements, [
|
|
25
|
-
[
|
|
25
|
+
['mousemove', this.onMouseMove.bind(this)],
|
|
26
26
|
]);
|
|
27
27
|
} else {
|
|
28
28
|
this._subscribe = attachEvents(
|
|
29
29
|
[window],
|
|
30
|
-
[[
|
|
30
|
+
[['mousemove', this.onMouseMove.bind(this)]]
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { attachEvents } from
|
|
2
|
-
import { Vector2 } from
|
|
3
|
-
import { clamp } from
|
|
4
|
-
import { withDefault } from
|
|
5
|
-
import { Gesture } from
|
|
1
|
+
import { attachEvents } from '../eventAttacher';
|
|
2
|
+
import { Vector2 } from '../types';
|
|
3
|
+
import { clamp } from '../math';
|
|
4
|
+
import { withDefault } from '../withDefault';
|
|
5
|
+
import { Gesture } from './Gesture';
|
|
6
6
|
|
|
7
7
|
export class ScrollGesture extends Gesture {
|
|
8
8
|
isActiveID?: any;
|
|
@@ -17,12 +17,12 @@ export class ScrollGesture extends Gesture {
|
|
|
17
17
|
if (this.targetElement) {
|
|
18
18
|
this._subscribe = attachEvents(
|
|
19
19
|
[this.targetElement],
|
|
20
|
-
[[
|
|
20
|
+
[['scroll', this.scrollElementListener.bind(this)]]
|
|
21
21
|
);
|
|
22
22
|
} else {
|
|
23
23
|
this._subscribe = attachEvents(
|
|
24
24
|
[window],
|
|
25
|
-
[[
|
|
25
|
+
[['scroll', this.scrollListener.bind(this)]]
|
|
26
26
|
);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { attachEvents } from
|
|
2
|
-
import { Vector2 } from
|
|
3
|
-
import { clamp } from
|
|
4
|
-
import { withDefault } from
|
|
5
|
-
import { Gesture } from
|
|
1
|
+
import { attachEvents } from '../eventAttacher';
|
|
2
|
+
import { Vector2 } from '../types';
|
|
3
|
+
import { clamp } from '../math';
|
|
4
|
+
import { withDefault } from '../withDefault';
|
|
5
|
+
import { Gesture } from './Gesture';
|
|
6
6
|
|
|
7
7
|
const LINE_HEIGHT = 40;
|
|
8
8
|
const PAGE_HEIGHT = 800;
|
|
@@ -25,7 +25,7 @@ export class WheelGesture extends Gesture {
|
|
|
25
25
|
if (this.targetElement) {
|
|
26
26
|
this._subscribe = attachEvents(
|
|
27
27
|
[this.targetElement],
|
|
28
|
-
[[
|
|
28
|
+
[['wheel', this.onWheel.bind(this)]]
|
|
29
29
|
);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from './DragGesture';
|
|
2
|
+
export * from './MouseMoveGesture';
|
|
3
|
+
export * from './ScrollGesture';
|
|
4
|
+
export * from './WheelGesture';
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
type MouseEventType =
|
|
2
|
-
|
|
|
3
|
-
|
|
|
4
|
-
|
|
|
5
|
-
|
|
|
6
|
-
|
|
|
7
|
-
|
|
|
8
|
-
|
|
|
9
|
-
|
|
|
10
|
-
|
|
|
11
|
-
|
|
|
12
|
-
|
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
16
|
-
|
|
|
2
|
+
| 'click'
|
|
3
|
+
| 'dblclick'
|
|
4
|
+
| 'mousedown'
|
|
5
|
+
| 'mousemove'
|
|
6
|
+
| 'mouseup'
|
|
7
|
+
| 'touchstart'
|
|
8
|
+
| 'touchmove'
|
|
9
|
+
| 'touchend'
|
|
10
|
+
| 'mouseenter'
|
|
11
|
+
| 'mouseleave'
|
|
12
|
+
| 'mouseout'
|
|
13
|
+
| 'mouseover'
|
|
14
|
+
| 'scroll'
|
|
15
|
+
| 'wheel'
|
|
16
|
+
| 'contextmenu';
|
|
17
17
|
|
|
18
18
|
type DomTargetTypes = Array<Window | Document | HTMLElement>;
|
|
19
19
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from './useDrag';
|
|
2
|
+
export * from './useMouseMove';
|
|
3
|
+
export * from './useScroll';
|
|
4
|
+
export * from './useWheel';
|
|
5
|
+
export * from './useGesture';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as React from
|
|
1
|
+
import * as React from 'react';
|
|
2
2
|
|
|
3
|
-
import { DragEventType, UseDragConfig } from
|
|
4
|
-
import { DragGesture } from
|
|
5
|
-
import { useRecognizer } from
|
|
3
|
+
import { DragEventType, UseDragConfig } from '../types';
|
|
4
|
+
import { DragGesture } from '../controllers';
|
|
5
|
+
import { useRecognizer } from './useRecognizer';
|
|
6
6
|
|
|
7
7
|
export function useDrag(
|
|
8
8
|
callback: (event: DragEventType) => void,
|
|
@@ -10,5 +10,5 @@ export function useDrag(
|
|
|
10
10
|
) {
|
|
11
11
|
const gesture = React.useRef(new DragGesture()).current;
|
|
12
12
|
|
|
13
|
-
return useRecognizer([[
|
|
13
|
+
return useRecognizer([['drag', gesture, callback, config]]);
|
|
14
14
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import * as React from
|
|
1
|
+
import * as React from 'react';
|
|
2
2
|
import {
|
|
3
3
|
DragGesture,
|
|
4
4
|
MouseMoveGesture,
|
|
5
5
|
ScrollGesture,
|
|
6
6
|
WheelGesture,
|
|
7
|
-
} from
|
|
7
|
+
} from '../controllers';
|
|
8
8
|
import {
|
|
9
9
|
DragEventType,
|
|
10
10
|
WheelEventType,
|
|
11
11
|
ScrollEventType,
|
|
12
12
|
MouseMoveEventType,
|
|
13
|
-
} from
|
|
14
|
-
import { useRecognizer } from
|
|
13
|
+
} from '../types';
|
|
14
|
+
import { useRecognizer } from './useRecognizer';
|
|
15
15
|
|
|
16
16
|
export function useGesture({
|
|
17
17
|
onDrag,
|
|
@@ -30,9 +30,9 @@ export function useGesture({
|
|
|
30
30
|
const mouseMoveGesture = React.useRef(new MouseMoveGesture()).current;
|
|
31
31
|
|
|
32
32
|
return useRecognizer([
|
|
33
|
-
[
|
|
34
|
-
[
|
|
35
|
-
[
|
|
36
|
-
[
|
|
33
|
+
['drag', dragGesture, onDrag],
|
|
34
|
+
['wheel', wheelGesture, onWheel],
|
|
35
|
+
['scroll', scrollGesture, onScroll],
|
|
36
|
+
['move', mouseMoveGesture, onMouseMove],
|
|
37
37
|
]);
|
|
38
38
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as React from
|
|
1
|
+
import * as React from 'react';
|
|
2
2
|
|
|
3
|
-
import { MouseMoveEventType } from
|
|
4
|
-
import { MouseMoveGesture } from
|
|
5
|
-
import { useRecognizer } from
|
|
3
|
+
import { MouseMoveEventType } from '../types';
|
|
4
|
+
import { MouseMoveGesture } from '../controllers';
|
|
5
|
+
import { useRecognizer } from './useRecognizer';
|
|
6
6
|
|
|
7
7
|
export function useMouseMove(callback: (event: MouseMoveEventType) => void) {
|
|
8
8
|
const gesture = React.useRef(new MouseMoveGesture()).current;
|
|
9
9
|
|
|
10
|
-
return useRecognizer([[
|
|
10
|
+
return useRecognizer([['move', gesture, callback]]);
|
|
11
11
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
2
|
-
import * as React from
|
|
2
|
+
import * as React from 'react';
|
|
3
3
|
|
|
4
4
|
type UseRecognizerHandlerType = Array<
|
|
5
5
|
[
|
|
6
|
-
key:
|
|
6
|
+
key: 'drag' | 'wheel' | 'move' | 'scroll',
|
|
7
7
|
gesture: any,
|
|
8
8
|
callback: any,
|
|
9
9
|
config?: any
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as React from
|
|
1
|
+
import * as React from 'react';
|
|
2
2
|
|
|
3
|
-
import { ScrollEventType } from
|
|
4
|
-
import { ScrollGesture } from
|
|
5
|
-
import { useRecognizer } from
|
|
3
|
+
import { ScrollEventType } from '../types';
|
|
4
|
+
import { ScrollGesture } from '../controllers';
|
|
5
|
+
import { useRecognizer } from './useRecognizer';
|
|
6
6
|
|
|
7
7
|
export function useScroll(callback: (event: ScrollEventType) => void) {
|
|
8
8
|
const gesture = React.useRef(new ScrollGesture()).current;
|
|
9
9
|
|
|
10
|
-
return useRecognizer([[
|
|
10
|
+
return useRecognizer([['scroll', gesture, callback]]);
|
|
11
11
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as React from
|
|
1
|
+
import * as React from 'react';
|
|
2
2
|
|
|
3
|
-
import { WheelEventType } from
|
|
4
|
-
import { WheelGesture } from
|
|
5
|
-
import { useRecognizer } from
|
|
3
|
+
import { WheelEventType } from '../types';
|
|
4
|
+
import { WheelGesture } from '../controllers';
|
|
5
|
+
import { useRecognizer } from './useRecognizer';
|
|
6
6
|
|
|
7
7
|
export function useWheel(callback: (event: WheelEventType) => void) {
|
|
8
8
|
const gesture = React.useRef(new WheelGesture()).current;
|
|
9
9
|
|
|
10
|
-
return useRecognizer([[
|
|
10
|
+
return useRecognizer([['wheel', gesture, callback]]);
|
|
11
11
|
}
|