No emitter
This commit is contained in:
@@ -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<DialogControlProps['close']>(
|
||||
cb => {
|
||||
if (cb) {
|
||||
events.on('close', cb)
|
||||
}
|
||||
sheet.current?.close()
|
||||
},
|
||||
[events],
|
||||
)
|
||||
const close = React.useCallback<DialogControlProps['close']>(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])
|
||||
|
||||
Reference in New Issue
Block a user