From 67fbb92c714dd5003914237a719c08dc63479803 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 20 Feb 2024 18:16:12 -0600 Subject: [PATCH] No emitter --- src/components/Dialog/index.tsx | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/components/Dialog/index.tsx b/src/components/Dialog/index.tsx index 9feb080dec..27f43afd3a 100644 --- a/src/components/Dialog/index.tsx +++ b/src/components/Dialog/index.tsx @@ -7,7 +7,6 @@ import BottomSheet, { BottomSheetView, } from '@gorhom/bottom-sheet' import {useSafeAreaInsets} from 'react-native-safe-area-context' -import EventEmitter from 'eventemitter3' import {useTheme, atoms as a, flatten} from '#/alf' import {Portal} from '#/components/Portal' @@ -36,7 +35,7 @@ export function Outer({ const sheetOptions = nativeOptions?.sheet || {} const hasSnapPoints = !!sheetOptions.snapPoints const insets = useSafeAreaInsets() - const events = React.useRef(new EventEmitter<'close'>()).current + const closeCallback = React.useRef<() => void>() /* * Used to manage open/closed, but index is otherwise handled internally by `BottomSheet` @@ -56,15 +55,12 @@ export function Outer({ [setOpenIndex], ) - const close = React.useCallback( - cb => { - if (cb) { - events.on('close', cb) - } - sheet.current?.close() - }, - [events], - ) + const close = React.useCallback(cb => { + if (cb) { + closeCallback.current = cb + } + sheet.current?.close() + }, []) useImperativeHandle( control.ref, @@ -78,13 +74,13 @@ export function Outer({ const onChange = React.useCallback( (index: number) => { if (index === -1) { - events.emit('close') - events.removeAllListeners('close') + closeCallback.current?.() + closeCallback.current = undefined onClose?.() setOpenIndex(-1) } }, - [onClose, setOpenIndex, events], + [onClose, setOpenIndex], ) const context = React.useMemo(() => ({close}), [close])