Skip to content

Commit

Permalink
use onClose instead of onChange for close callback (#3116)
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyok authored Mar 6, 2024
1 parent 20b88f4 commit 57854e6
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions src/components/Dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,21 @@ export function Outer({
[open, close],
)

const onChange = React.useCallback(
(index: number) => {
if (index === -1) {
Keyboard.dismiss()
try {
closeCallback.current?.()
} catch (e: any) {
logger.error(`Dialog closeCallback failed`, {
message: e.message,
})
} finally {
closeCallback.current = undefined
}

setDialogIsOpen(control.id, false)
onClose?.()
setOpenIndex(-1)
}
},
[onClose, setOpenIndex, setDialogIsOpen, control.id],
)
const onCloseInner = React.useCallback(() => {
Keyboard.dismiss()
try {
closeCallback.current?.()
} catch (e: any) {
logger.error(`Dialog closeCallback failed`, {
message: e.message,
})
} finally {
closeCallback.current = undefined
}
setDialogIsOpen(control.id, false)
onClose?.()
setOpenIndex(-1)
}, [control.id, onClose, setDialogIsOpen])

const context = React.useMemo(() => ({close}), [close])

Expand Down Expand Up @@ -167,7 +161,7 @@ export function Outer({
backdropComponent={Backdrop}
handleIndicatorStyle={{backgroundColor: t.palette.primary_500}}
handleStyle={{display: 'none'}}
onChange={onChange}>
onClose={onCloseInner}>
<Context.Provider value={context}>
<View
style={[
Expand Down

0 comments on commit 57854e6

Please sign in to comment.