No emitter

This commit is contained in:
Eric Bailey
2024-02-20 18:16:12 -06:00
parent 0c9fd4a6c6
commit 67fbb92c71
+10 -14
View File
@@ -7,7 +7,6 @@ import BottomSheet, {
BottomSheetView, BottomSheetView,
} from '@gorhom/bottom-sheet' } from '@gorhom/bottom-sheet'
import {useSafeAreaInsets} from 'react-native-safe-area-context' import {useSafeAreaInsets} from 'react-native-safe-area-context'
import EventEmitter from 'eventemitter3'
import {useTheme, atoms as a, flatten} from '#/alf' import {useTheme, atoms as a, flatten} from '#/alf'
import {Portal} from '#/components/Portal' import {Portal} from '#/components/Portal'
@@ -36,7 +35,7 @@ export function Outer({
const sheetOptions = nativeOptions?.sheet || {} const sheetOptions = nativeOptions?.sheet || {}
const hasSnapPoints = !!sheetOptions.snapPoints const hasSnapPoints = !!sheetOptions.snapPoints
const insets = useSafeAreaInsets() 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` * Used to manage open/closed, but index is otherwise handled internally by `BottomSheet`
@@ -56,15 +55,12 @@ export function Outer({
[setOpenIndex], [setOpenIndex],
) )
const close = React.useCallback<DialogControlProps['close']>( const close = React.useCallback<DialogControlProps['close']>(cb => {
cb => { if (cb) {
if (cb) { closeCallback.current = cb
events.on('close', cb) }
} sheet.current?.close()
sheet.current?.close() }, [])
},
[events],
)
useImperativeHandle( useImperativeHandle(
control.ref, control.ref,
@@ -78,13 +74,13 @@ export function Outer({
const onChange = React.useCallback( const onChange = React.useCallback(
(index: number) => { (index: number) => {
if (index === -1) { if (index === -1) {
events.emit('close') closeCallback.current?.()
events.removeAllListeners('close') closeCallback.current = undefined
onClose?.() onClose?.()
setOpenIndex(-1) setOpenIndex(-1)
} }
}, },
[onClose, setOpenIndex, events], [onClose, setOpenIndex],
) )
const context = React.useMemo(() => ({close}), [close]) const context = React.useMemo(() => ({close}), [close])