diff options
author | Eric Bailey <git@esb.lol> | 2024-02-20 18:20:59 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-20 18:20:59 -0600 |
commit | f88b16525498584f81ea7f594a63623fc5dc7ce9 (patch) | |
tree | 0f87d5dc87778da6b4451be536437a432adfbf91 /src/components/Dialog/index.tsx | |
parent | 6413b8ba8cbf73678d0f1687153b16f3a44f08b0 (diff) | |
download | voidsky-f88b16525498584f81ea7f594a63623fc5dc7ce9.tar.zst |
Add optional close callback to Dialog (#2947)
* Add optional close callback * No emitter
Diffstat (limited to 'src/components/Dialog/index.tsx')
-rw-r--r-- | src/components/Dialog/index.tsx | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/components/Dialog/index.tsx b/src/components/Dialog/index.tsx index 529535051..27f43afd3 100644 --- a/src/components/Dialog/index.tsx +++ b/src/components/Dialog/index.tsx @@ -35,6 +35,7 @@ export function Outer({ const sheetOptions = nativeOptions?.sheet || {} const hasSnapPoints = !!sheetOptions.snapPoints const insets = useSafeAreaInsets() + const closeCallback = React.useRef<() => void>() /* * Used to manage open/closed, but index is otherwise handled internally by `BottomSheet` @@ -54,7 +55,10 @@ export function Outer({ [setOpenIndex], ) - const close = React.useCallback(() => { + const close = React.useCallback<DialogControlProps['close']>(cb => { + if (cb) { + closeCallback.current = cb + } sheet.current?.close() }, []) @@ -70,6 +74,8 @@ export function Outer({ const onChange = React.useCallback( (index: number) => { if (index === -1) { + closeCallback.current?.() + closeCallback.current = undefined onClose?.() setOpenIndex(-1) } |