Fix Android crash by try/catch dialog open (#9335)
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
type DialogControlRefProps,
|
||||
type DialogOuterProps,
|
||||
} from '#/components/Dialog/types'
|
||||
import {IS_DEV} from '#/env'
|
||||
import {BottomSheetSnapPoint} from '../../../modules/bottom-sheet/src/BottomSheet.types'
|
||||
|
||||
export const Context = createContext<DialogContextProps>({
|
||||
@@ -50,10 +51,28 @@ export function useDialogControl(): DialogOuterProps['control'] {
|
||||
id,
|
||||
ref: control,
|
||||
open: () => {
|
||||
control.current.open()
|
||||
if (control.current) {
|
||||
control.current.open()
|
||||
} else {
|
||||
if (IS_DEV) {
|
||||
console.warn(
|
||||
'Attemped to open a dialog control that was not attached to a dialog!\n' +
|
||||
'Please ensure that the Dialog is mounted when calling open/close',
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
close: cb => {
|
||||
control.current.close(cb)
|
||||
if (control.current) {
|
||||
control.current.close(cb)
|
||||
} else {
|
||||
if (IS_DEV) {
|
||||
console.warn(
|
||||
'Attemped to close a dialog control that was not attached to a dialog!\n' +
|
||||
'Please ensure that the Dialog is mounted when calling open/close',
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
}),
|
||||
[id, control],
|
||||
|
||||
Reference in New Issue
Block a user