MCPcopy Index your code
hub / github.com/adobe/react-spectrum / useExitAnimation

Function useExitAnimation

packages/react-aria/src/utils/animation.ts:48–81  ·  view source on GitHub ↗
(ref: RefObject<HTMLElement | null>, isOpen: boolean)

Source from the content-addressed store, hash-verified

46}
47
48export function useExitAnimation(ref: RefObject<HTMLElement | null>, isOpen: boolean): boolean {
49 let [exitState, setExitState] = useState<'closed' | 'open' | 'exiting'>(
50 isOpen ? 'open' : 'closed'
51 );
52
53 switch (exitState) {
54 case 'open':
55 // If isOpen becomes false, set the state to exiting.
56 if (!isOpen) {
57 setExitState('exiting');
58 }
59 break;
60 case 'closed':
61 case 'exiting':
62 // If we are exiting and isOpen becomes true, the animation was interrupted.
63 // Reset the state to open.
64 if (isOpen) {
65 setExitState('open');
66 }
67 break;
68 }
69
70 let isExiting = exitState === 'exiting';
71 useAnimation(
72 ref,
73 isExiting,
74 useCallback(() => {
75 // Set the state to closed, which will cause the element to be unmounted.
76 setExitState(state => (state === 'exiting' ? 'closed' : state));
77 }, [])
78 );
79
80 return isExiting;
81}
82
83function useAnimation(
84 ref: RefObject<HTMLElement | null>,

Callers 6

Popover.tsxFile · 0.90
Tooltip.tsxFile · 0.90
Tabs.tsxFile · 0.90
ThreadScrollButtonFunction · 0.90
ActionBar.tsxFile · 0.90

Calls 1

useAnimationFunction · 0.85

Tested by

no test coverage detected