( props: UseAnimationKeyframesProps, )
| 23 | | 'keyframes' |
| 24 | >; |
| 25 | export default function useAnimateKeyframes( |
| 26 | props: UseAnimationKeyframesProps, |
| 27 | ): { |
| 28 | style: React.CSSProperties; |
| 29 | play: (isPlaying: boolean) => void; |
| 30 | pause: (isPaused: boolean) => void; |
| 31 | isPlaying: boolean; |
| 32 | } { |
| 33 | const { |
| 34 | duration = DEFAULT_DURATION, |
| 35 | delay = 0, |
| 36 | easeType = DEFAULT_EASE_TYPE, |
| 37 | direction = DEFAULT_DIRECTION, |
| 38 | fillMode = DEFAULT_FILLMODE, |
| 39 | iterationCount = 1, |
| 40 | keyframes, |
| 41 | } = props; |
| 42 | const animationNameRef = React.useRef({ |
| 43 | forward: '', |
| 44 | reverse: '', |
| 45 | }); |
| 46 | const styleTagRef = React.useRef< |
| 47 | Record<'forward' | 'reverse', HTMLStyleElement | null> |
| 48 | >({ |
| 49 | forward: null, |
| 50 | reverse: null, |
| 51 | }); |
| 52 | const { register } = React.useContext(AnimateContext); |
| 53 | const [isPlaying, setIsPlaying] = React.useState<boolean | null>(null); |
| 54 | const [isPaused, setIsPaused] = React.useState(false); |
| 55 | |
| 56 | React.useEffect(() => { |
| 57 | const styleTag = styleTagRef.current; |
| 58 | const animationName = animationNameRef.current; |
| 59 | |
| 60 | animationNameRef.current.forward = createRandomName(); |
| 61 | let result = createTag({ |
| 62 | animationName: animationNameRef.current.forward, |
| 63 | keyframes, |
| 64 | }); |
| 65 | styleTagRef.current.forward = result.styleTag; |
| 66 | |
| 67 | animationNameRef.current.reverse = createRandomName(); |
| 68 | result = createTag({ |
| 69 | animationName: animationNameRef.current.reverse, |
| 70 | keyframes: keyframes.reverse(), |
| 71 | }); |
| 72 | styleTagRef.current.reverse = result.styleTag; |
| 73 | |
| 74 | register(props); |
| 75 | |
| 76 | return () => { |
| 77 | deleteRules(styleTag.forward?.sheet, animationName.forward); |
| 78 | deleteRules(styleTag.reverse?.sheet, animationName.reverse); |
| 79 | }; |
| 80 | // eslint-disable-next-line react-hooks/exhaustive-deps |
| 81 | }, []); |
| 82 |
no test coverage detected