react-modal-sheet 4.3.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,44 +0,0 @@
1
- import { type RefObject, useCallback, useEffect, useRef } from 'react';
2
-
3
- import { type SheetEvents } from '../types';
4
-
5
- export function useEventCallbacks(
6
- isOpen: boolean,
7
- callbacks: RefObject<SheetEvents>
8
- ) {
9
- const prevOpen = usePrevious(isOpen);
10
- const didOpen = useRef(false);
11
-
12
- // Because of AnimatePrecence we don't have access to latest isOpen value
13
- // so we need to read and write to a ref to determine if we are
14
- // opening or closing the sheet
15
- const handleAnimationComplete = useCallback(() => {
16
- if (!didOpen.current) {
17
- callbacks.current.onOpenEnd?.();
18
- didOpen.current = true;
19
- } else {
20
- callbacks.current.onCloseEnd?.();
21
- didOpen.current = false;
22
- }
23
- }, [isOpen, prevOpen]);
24
-
25
- useEffect(() => {
26
- if (!prevOpen && isOpen) {
27
- callbacks.current.onOpenStart?.();
28
- } else if (!isOpen && prevOpen) {
29
- callbacks.current.onCloseStart?.();
30
- }
31
- }, [isOpen, prevOpen]);
32
-
33
- return { handleAnimationComplete };
34
- }
35
-
36
- function usePrevious<T>(state: T): T | undefined {
37
- const ref = useRef<T>(undefined);
38
-
39
- useEffect(() => {
40
- ref.current = state;
41
- });
42
-
43
- return ref.current;
44
- }