react-ui-animate 2.0.0-rc.1 → 2.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/dist/animation/animationType.d.ts +8 -0
- package/dist/animation/getInitialConfig.d.ts +2 -2
- package/dist/animation/index.d.ts +1 -0
- 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 +21 -0
- package/dist/animation/modules/TransitionBlock.d.ts +17 -0
- package/dist/animation/modules/index.d.ts +6 -0
- package/dist/animation/useAnimatedValue.d.ts +8 -4
- package/dist/animation/useMountedValue.d.ts +5 -4
- 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 +216 -150
- package/dist/index.js.map +1 -1
- package/package.json +8 -9
- package/src/animation/animationType.ts +8 -0
- package/src/animation/getInitialConfig.ts +35 -4
- package/src/animation/index.ts +1 -0
- 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 +69 -0
- package/src/animation/modules/TransitionBlock.tsx +29 -0
- package/src/animation/modules/index.ts +6 -0
- package/src/animation/useAnimatedValue.ts +15 -6
- package/src/animation/useMountedValue.ts +5 -4
- 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/dist/animation/modules.d.ts +0 -55
- package/src/animation/modules.tsx +0 -105
|
@@ -1,105 +0,0 @@
|
|
|
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
|
-
};
|