source: node_modules/recharts/es6/animation/JavascriptAnimate.js@ a762898

Last change on this file since a762898 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.9 KB
Line 
1import { useEffect, useRef, useState } from 'react';
2import { noop } from '../util/DataUtils';
3import { resolveDefaultProps } from '../util/resolveDefaultProps';
4import configUpdate from './configUpdate';
5import { configEasing } from './easing';
6import { useAnimationManager } from './useAnimationManager';
7import { Global } from '../util/Global';
8var defaultJavascriptAnimateProps = {
9 begin: 0,
10 duration: 1000,
11 easing: 'ease',
12 isActive: true,
13 canBegin: true,
14 onAnimationEnd: () => {},
15 onAnimationStart: () => {}
16};
17var from = {
18 t: 0
19};
20var to = {
21 t: 1
22};
23export function JavascriptAnimate(outsideProps) {
24 var props = resolveDefaultProps(outsideProps, defaultJavascriptAnimateProps);
25 var {
26 isActive: isActiveProp,
27 canBegin,
28 duration,
29 easing,
30 begin,
31 onAnimationEnd,
32 onAnimationStart,
33 children
34 } = props;
35 var isActive = isActiveProp === 'auto' ? !Global.isSsr : isActiveProp;
36 var animationManager = useAnimationManager(props.animationId, props.animationManager);
37 var [style, setStyle] = useState(isActive ? from : to);
38 var stopJSAnimation = useRef(null);
39 useEffect(() => {
40 if (!isActive) {
41 setStyle(to);
42 }
43 }, [isActive]);
44 useEffect(() => {
45 if (!isActive || !canBegin) {
46 return noop;
47 }
48 var startAnimation = configUpdate(from, to, configEasing(easing), duration, setStyle, animationManager.getTimeoutController());
49 var onAnimationActive = () => {
50 stopJSAnimation.current = startAnimation();
51 };
52 animationManager.start([onAnimationStart, begin, onAnimationActive, duration, onAnimationEnd]);
53 return () => {
54 animationManager.stop();
55 if (stopJSAnimation.current) {
56 stopJSAnimation.current();
57 }
58 onAnimationEnd();
59 };
60 }, [isActive, canBegin, duration, easing, begin, onAnimationStart, onAnimationEnd, animationManager]);
61 return children(style.t);
62}
Note: See TracBrowser for help on using the repository browser.