@progress/kendo-react-animation
Version:
React Animation component assists with animating HTML elements. KendoReact Animation package
31 lines (30 loc) • 1.09 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
import * as n from "react";
const p = (s, m) => {
const t = n.useRef(0), i = n.useRef(!1), r = n.useRef(null), d = (e) => {
const l = e.duration;
let o, u;
const w = t.current && 1 - t.current;
e.onStart && e.onStart();
const a = (f) => {
o || (o = f), u = f - o + 1;
const c = u / l + w;
c <= 1 ? (e.onUpdate && e.onUpdate(c), r.current = window.requestAnimationFrame(a), t.current = c) : (e.onEnd && e.onEnd(1), t.current = 0);
};
r.current = window.requestAnimationFrame(a);
};
n.useEffect(() => (d(s), () => {
r.current && window.cancelAnimationFrame(r.current);
}), m), n.useEffect(() => {
i.current = !0;
}, []);
};
export {
p as useAnimation
};