MCPcopy Create free account
hub / github.com/adobe/react-spectrum / useAnimation

Function useAnimation

packages/react-aria/src/utils/animation.ts:83–116  ·  view source on GitHub ↗
(
  ref: RefObject<HTMLElement | null>,
  isActive: boolean,
  onEnd: () => void
)

Source from the content-addressed store, hash-verified

81}
82
83function useAnimation(
84 ref: RefObject<HTMLElement | null>,
85 isActive: boolean,
86 onEnd: () => void
87): void {
88 useLayoutEffect(() => {
89 if (isActive && ref.current) {
90 if (!('getAnimations' in ref.current)) {
91 // JSDOM
92 onEnd();
93 return;
94 }
95
96 let animations = ref.current.getAnimations();
97 if (animations.length === 0) {
98 onEnd();
99 return;
100 }
101
102 let canceled = false;
103 Promise.allSettled(animations.map(a => a.finished)).then(() => {
104 if (!canceled) {
105 flushSync(() => {
106 onEnd();
107 });
108 }
109 });
110
111 return () => {
112 canceled = true;
113 };
114 }
115 }, [ref, isActive, onEnd]);
116}

Callers 2

useEnterAnimationFunction · 0.85
useExitAnimationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected