UNPKG

@progress/kendo-react-animation

Version:

React Animation component assists with animating HTML elements. KendoReact Animation package

31 lines (30 loc) 1.09 kB
/** * @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 t from "react"; const p = (s, m) => { const n = t.useRef(0), i = t.useRef(!1), r = t.useRef(), d = (e) => { const w = e.duration; let o, u; const l = n.current && 1 - n.current; e.onStart && e.onStart(); const a = (f) => { o || (o = f), u = f - o + 1; const c = u / w + l; c <= 1 ? (e.onUpdate && e.onUpdate(c), r.current = window.requestAnimationFrame(a), n.current = c) : (e.onEnd && e.onEnd(1), n.current = 0); }; r.current = window.requestAnimationFrame(a); }; t.useEffect(() => (d(s), () => { r.current && window.cancelAnimationFrame(r.current); }), m), t.useEffect(() => { i.current = !0; }, []); }; export { p as useAnimation };