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,9 +1,9 @@
1
- export * from './interpolation';
2
- export * from './modules';
3
- export {
4
- useAnimatedValue,
5
- ValueType,
6
- UseAnimatedValueConfig,
7
- } from './useAnimatedValue';
8
- export { useMountedValue } from './useMountedValue';
9
- export * from './animationType';
1
+ export * from './interpolation';
2
+ export * from './modules';
3
+ export {
4
+ useAnimatedValue,
5
+ ValueType,
6
+ UseAnimatedValueConfig,
7
+ } from './useAnimatedValue';
8
+ export { useMountedValue } from './useMountedValue';
9
+ export * from './animationType';
@@ -1,24 +1,24 @@
1
- import {
2
- interpolate,
3
- ExtrapolateConfig,
4
- TransitionValue,
5
- } from '@raidipesh78/re-motion';
6
- export { interpolate } from '@raidipesh78/re-motion';
7
-
8
- /**
9
- * bInterpolate functions maps input range [0, 1] to given [minOutput, maxOutput]
10
- * sorthand function to interpolate input range [0, 1]
11
- * @param value - number | TransitionValue
12
- * @param minOutput - number | string
13
- * @param maxOutput - number | string
14
- * @param extrapolateConfig - "clamp" | "identity" | "extend"
15
- * @returns - number | TransitionValue
16
- */
17
- export function bInterpolate(
18
- value: number | TransitionValue,
19
- minOutput: number | string,
20
- maxOutput: number | string,
21
- extrapolateConfig?: ExtrapolateConfig
22
- ) {
23
- return interpolate(value, [0, 1], [minOutput, maxOutput], extrapolateConfig);
24
- }
1
+ import {
2
+ interpolate,
3
+ ExtrapolateConfig,
4
+ TransitionValue,
5
+ } from '@raidipesh78/re-motion';
6
+ export { interpolate } from '@raidipesh78/re-motion';
7
+
8
+ /**
9
+ * bInterpolate functions maps input range [0, 1] to given [minOutput, maxOutput]
10
+ * sorthand function to interpolate input range [0, 1]
11
+ * @param value - number | TransitionValue
12
+ * @param minOutput - number | string
13
+ * @param maxOutput - number | string
14
+ * @param extrapolateConfig - "clamp" | "identity" | "extend"
15
+ * @returns - number | TransitionValue
16
+ */
17
+ export function bInterpolate(
18
+ value: number | TransitionValue,
19
+ minOutput: number | string,
20
+ maxOutput: number | string,
21
+ extrapolateConfig?: ExtrapolateConfig
22
+ ) {
23
+ return interpolate(value, [0, 1], [minOutput, maxOutput], extrapolateConfig);
24
+ }
@@ -1,105 +1,105 @@
1
- import * as React from 'react';
2
- import {
3
- makeAnimatedComponent as animated,
4
- TransitionValue,
5
- } from '@raidipesh78/re-motion';
6
- import { useAnimatedValue, UseAnimatedValueConfig } from './useAnimatedValue';
7
- import { useMountedValue, UseMountedValueConfig } from './useMountedValue';
8
-
9
- /**
10
- * Make any component animatable
11
- */
12
- export function makeAnimatedComponent(
13
- WrappedComponent: React.ElementType<any>
14
- ) {
15
- return animated(WrappedComponent);
16
- }
17
-
18
- /**
19
- * AnimatedBlock : Animated Div
20
- */
21
- export const AnimatedBlock = animated('div');
22
- /**
23
- * AnimatedInline : Animated Span
24
- */
25
- export const AnimatedInline = animated('span');
26
- /**
27
- * AnimatedImage : Animated Image
28
- */
29
- export const AnimatedImage = animated('img');
30
- interface ScrollableBlockProps {
31
- children?: (animation: any) => React.ReactNode;
32
- direction?: 'single' | 'both';
33
- threshold?: number;
34
- animationConfig?: UseAnimatedValueConfig;
35
- }
36
-
37
- /**
38
- * ScrollableBlock
39
- * Used to animate element when enter into viewport
40
- * Render props pattern with children accepts animation node
41
- * animated value goes from 0 to 1 when appear on viewport & vice versa.
42
- */
43
- export const ScrollableBlock: React.FC<ScrollableBlockProps> = (props) => {
44
- const {
45
- children,
46
- direction = 'single',
47
- animationConfig,
48
- threshold = 0.2,
49
- } = props;
50
- const scrollableBlockRef = React.useRef<HTMLDivElement>(null);
51
- const animation = useAnimatedValue(0, animationConfig); // 0: not intersecting | 1: intersecting
52
-
53
- React.useEffect(() => {
54
- const _scrollableBlock = scrollableBlockRef.current;
55
-
56
- const observer = new IntersectionObserver(
57
- function ([entry]) {
58
- const { isIntersecting } = entry;
59
-
60
- if (isIntersecting) {
61
- animation.value = 1;
62
- } else {
63
- if (direction === 'both') animation.value = 0;
64
- }
65
- },
66
- {
67
- root: null, // FOR VIEWPORT ONLY
68
- threshold,
69
- }
70
- );
71
-
72
- if (_scrollableBlock) {
73
- observer.observe(_scrollableBlock);
74
- }
75
-
76
- return () => {
77
- if (_scrollableBlock) {
78
- observer.unobserve(_scrollableBlock);
79
- }
80
- };
81
- }, []);
82
-
83
- return <div ref={scrollableBlockRef}>{children && children(animation)}</div>;
84
- };
85
-
86
- interface MountedBlockProps {
87
- state: boolean;
88
- children: (animation: { value: TransitionValue }) => React.ReactNode;
89
- config: UseMountedValueConfig;
90
- }
91
-
92
- /**
93
- * MountedBlock handles mounting and unmounting of a component
94
- * @props - state: boolean, config: InnerUseMountedValueConfig
95
- * @children - (animation: { value: TransitionValue }) => React.ReactNode
96
- */
97
- export const MountedBlock = ({
98
- state,
99
- children,
100
- config,
101
- }: MountedBlockProps) => {
102
- const open = useMountedValue(state, config);
103
-
104
- return <>{open((animation, mounted) => mounted && children(animation))}</>;
105
- };
1
+ import * as React from 'react';
2
+ import {
3
+ makeAnimatedComponent as animated,
4
+ TransitionValue,
5
+ } from '@raidipesh78/re-motion';
6
+ import { useAnimatedValue, UseAnimatedValueConfig } from './useAnimatedValue';
7
+ import { useMountedValue, UseMountedValueConfig } from './useMountedValue';
8
+
9
+ /**
10
+ * Make any component animatable
11
+ */
12
+ export function makeAnimatedComponent(
13
+ WrappedComponent: React.ElementType<any>
14
+ ) {
15
+ return animated(WrappedComponent);
16
+ }
17
+
18
+ /**
19
+ * AnimatedBlock : Animated Div
20
+ */
21
+ export const AnimatedBlock = animated('div');
22
+ /**
23
+ * AnimatedInline : Animated Span
24
+ */
25
+ export const AnimatedInline = animated('span');
26
+ /**
27
+ * AnimatedImage : Animated Image
28
+ */
29
+ export const AnimatedImage = animated('img');
30
+ interface ScrollableBlockProps {
31
+ children?: (animation: any) => React.ReactNode;
32
+ direction?: 'single' | 'both';
33
+ threshold?: number;
34
+ animationConfig?: UseAnimatedValueConfig;
35
+ }
36
+
37
+ /**
38
+ * ScrollableBlock
39
+ * Used to animate element when enter into viewport
40
+ * Render props pattern with children accepts animation node
41
+ * animated value goes from 0 to 1 when appear on viewport & vice versa.
42
+ */
43
+ export const ScrollableBlock: React.FC<ScrollableBlockProps> = (props) => {
44
+ const {
45
+ children,
46
+ direction = 'single',
47
+ animationConfig,
48
+ threshold = 0.2,
49
+ } = props;
50
+ const scrollableBlockRef = React.useRef<HTMLDivElement>(null);
51
+ const animation = useAnimatedValue(0, animationConfig); // 0: not intersecting | 1: intersecting
52
+
53
+ React.useEffect(() => {
54
+ const _scrollableBlock = scrollableBlockRef.current;
55
+
56
+ const observer = new IntersectionObserver(
57
+ function ([entry]) {
58
+ const { isIntersecting } = entry;
59
+
60
+ if (isIntersecting) {
61
+ animation.value = 1;
62
+ } else {
63
+ if (direction === 'both') animation.value = 0;
64
+ }
65
+ },
66
+ {
67
+ root: null, // FOR VIEWPORT ONLY
68
+ threshold,
69
+ }
70
+ );
71
+
72
+ if (_scrollableBlock) {
73
+ observer.observe(_scrollableBlock);
74
+ }
75
+
76
+ return () => {
77
+ if (_scrollableBlock) {
78
+ observer.unobserve(_scrollableBlock);
79
+ }
80
+ };
81
+ }, []);
82
+
83
+ return <div ref={scrollableBlockRef}>{children && children(animation)}</div>;
84
+ };
85
+
86
+ interface MountedBlockProps {
87
+ state: boolean;
88
+ children: (animation: { value: TransitionValue }) => React.ReactNode;
89
+ config: UseMountedValueConfig;
90
+ }
91
+
92
+ /**
93
+ * MountedBlock handles mounting and unmounting of a component
94
+ * @props - state: boolean, config: InnerUseMountedValueConfig
95
+ * @children - (animation: { value: TransitionValue }) => React.ReactNode
96
+ */
97
+ export const MountedBlock = ({
98
+ state,
99
+ children,
100
+ config,
101
+ }: MountedBlockProps) => {
102
+ const open = useMountedValue(state, config);
103
+
104
+ return <>{open((animation, mounted) => mounted && children(animation))}</>;
105
+ };
@@ -1,62 +1,62 @@
1
- import { useTransition, UseTransitionConfig } from '@raidipesh78/re-motion';
2
-
3
- // useAnimatedValue value type
4
- type AnimatedValueType = number | string;
5
- export interface UseAnimatedValueConfig extends UseTransitionConfig {}
6
-
7
- type Length = number | string;
8
- type AssignValue = {
9
- toValue: Length;
10
- config?: UseAnimatedValueConfig;
11
- };
12
- export type ValueType =
13
- | Length
14
- | AssignValue
15
- | ((update: (next: AssignValue) => Promise<any>) => void);
16
-
17
- /**
18
- * useAnimatedValue for animated transitions
19
- */
20
- export function useAnimatedValue(
21
- initialValue: AnimatedValueType,
22
- config?: UseAnimatedValueConfig
23
- ) {
24
- const [animation, setAnimation] = useTransition(initialValue, config);
25
-
26
- const targetObject: {
27
- value: any;
28
- currentValue: number | string;
29
- } = {
30
- value: animation,
31
- currentValue: animation.get(),
32
- };
33
-
34
- return new Proxy(targetObject, {
35
- set: function (_, key, value: ValueType) {
36
- if (key === 'value') {
37
- if (typeof value === 'number' || typeof value === 'string') {
38
- setAnimation({ toValue: value });
39
- } else if (typeof value === 'object' || typeof value === 'function') {
40
- setAnimation(value);
41
- }
42
-
43
- return true;
44
- }
45
-
46
- throw new Error('You cannot set any other property to animation node.');
47
- },
48
- get: function (_, key) {
49
- if (key === 'value') {
50
- return animation;
51
- }
52
-
53
- if (key === 'currentValue') {
54
- return animation.get();
55
- }
56
-
57
- throw new Error(
58
- 'You cannot access any other property from animation node.'
59
- );
60
- },
61
- });
62
- }
1
+ import { useTransition, UseTransitionConfig } from '@raidipesh78/re-motion';
2
+
3
+ // useAnimatedValue value type
4
+ type AnimatedValueType = number | string;
5
+ export interface UseAnimatedValueConfig extends UseTransitionConfig {}
6
+
7
+ type Length = number | string;
8
+ type AssignValue = {
9
+ toValue: Length;
10
+ config?: UseAnimatedValueConfig;
11
+ };
12
+ export type ValueType =
13
+ | Length
14
+ | AssignValue
15
+ | ((update: (next: AssignValue) => Promise<any>) => void);
16
+
17
+ /**
18
+ * useAnimatedValue for animated transitions
19
+ */
20
+ export function useAnimatedValue(
21
+ initialValue: AnimatedValueType,
22
+ config?: UseAnimatedValueConfig
23
+ ) {
24
+ const [animation, setAnimation] = useTransition(initialValue, config);
25
+
26
+ const targetObject: {
27
+ value: any;
28
+ currentValue: number | string;
29
+ } = {
30
+ value: animation,
31
+ currentValue: animation.get(),
32
+ };
33
+
34
+ return new Proxy(targetObject, {
35
+ set: function (_, key, value: ValueType) {
36
+ if (key === 'value') {
37
+ if (typeof value === 'number' || typeof value === 'string') {
38
+ setAnimation({ toValue: value });
39
+ } else if (typeof value === 'object' || typeof value === 'function') {
40
+ setAnimation(value);
41
+ }
42
+
43
+ return true;
44
+ }
45
+
46
+ throw new Error('You cannot set any other property to animation node.');
47
+ },
48
+ get: function (_, key) {
49
+ if (key === 'value') {
50
+ return animation;
51
+ }
52
+
53
+ if (key === 'currentValue') {
54
+ return animation.get();
55
+ }
56
+
57
+ throw new Error(
58
+ 'You cannot access any other property from animation node.'
59
+ );
60
+ },
61
+ });
62
+ }
@@ -1,66 +1,66 @@
1
- import * as React from 'react';
2
- import {
3
- useTransition,
4
- TransitionValue,
5
- UseMountConfig,
6
- } from '@raidipesh78/re-motion';
7
-
8
- export interface UseMountedValueConfig extends UseMountConfig {}
9
-
10
- /**
11
- * useMountedValue handles mounting and unmounting of a component
12
- * @param state - boolean
13
- * @param config - useTransitionConfig
14
- * @returns mountedValueFunction with a callback with argument ( { value: animationNode }, mounted )
15
- */
16
- export function useMountedValue(state: boolean, config: UseMountedValueConfig) {
17
- const initial = React.useRef(true);
18
- const [mounted, setMounted] = React.useState(state);
19
- const {
20
- from,
21
- enter,
22
- exit,
23
- config: innerConfig,
24
- enterConfig,
25
- exitConfig,
26
- } = React.useRef(config).current;
27
- const [animation, setAnimation] = useTransition(from, innerConfig);
28
-
29
- React.useEffect(() => {
30
- if (state) {
31
- initial.current = true;
32
- setMounted(true);
33
- } else {
34
- initial.current = false;
35
- setAnimation(
36
- {
37
- toValue: exit,
38
- config: exitConfig,
39
- },
40
- function ({ finished }) {
41
- if (finished) {
42
- setMounted(false);
43
- }
44
- }
45
- );
46
- }
47
- }, [state]);
48
-
49
- React.useEffect(() => {
50
- if (mounted && initial.current) {
51
- setAnimation({
52
- toValue: enter,
53
- config: enterConfig,
54
- });
55
- }
56
- }, [mounted, initial.current]);
57
-
58
- return function (
59
- callback: (
60
- { value: animation }: { value: TransitionValue },
61
- mounted: boolean
62
- ) => React.ReactNode
63
- ) {
64
- return callback({ value: animation }, mounted);
65
- };
66
- }
1
+ import * as React from 'react';
2
+ import {
3
+ useTransition,
4
+ TransitionValue,
5
+ UseMountConfig,
6
+ } from '@raidipesh78/re-motion';
7
+
8
+ export interface UseMountedValueConfig extends UseMountConfig {}
9
+
10
+ /**
11
+ * useMountedValue handles mounting and unmounting of a component
12
+ * @param state - boolean
13
+ * @param config - useTransitionConfig
14
+ * @returns mountedValueFunction with a callback with argument ( { value: animationNode }, mounted )
15
+ */
16
+ export function useMountedValue(state: boolean, config: UseMountedValueConfig) {
17
+ const initial = React.useRef(true);
18
+ const [mounted, setMounted] = React.useState(state);
19
+ const {
20
+ from,
21
+ enter,
22
+ exit,
23
+ config: innerConfig,
24
+ enterConfig,
25
+ exitConfig,
26
+ } = React.useRef(config).current;
27
+ const [animation, setAnimation] = useTransition(from, innerConfig);
28
+
29
+ React.useEffect(() => {
30
+ if (state) {
31
+ initial.current = true;
32
+ setMounted(true);
33
+ } else {
34
+ initial.current = false;
35
+ setAnimation(
36
+ {
37
+ toValue: exit,
38
+ config: exitConfig,
39
+ },
40
+ function ({ finished }) {
41
+ if (finished) {
42
+ setMounted(false);
43
+ }
44
+ }
45
+ );
46
+ }
47
+ }, [state]);
48
+
49
+ React.useEffect(() => {
50
+ if (mounted && initial.current) {
51
+ setAnimation({
52
+ toValue: enter,
53
+ config: enterConfig,
54
+ });
55
+ }
56
+ }, [mounted, initial.current]);
57
+
58
+ return function (
59
+ callback: (
60
+ { value: animation }: { value: TransitionValue },
61
+ mounted: boolean
62
+ ) => React.ReactNode
63
+ ) {
64
+ return callback({ value: animation }, mounted);
65
+ };
66
+ }