fix: toast message handling on android (#3604)
* fix(toast): ensure default duration is applied when showing toast messages * fix: handle potential undefined toastRefs and improve conflict warning * chore: correct spelling of 'dismiss' in ToastRef and related usages
This commit is contained in:
@@ -14,7 +14,7 @@ export const CenteredToast = (props: ToastProps) => {
|
||||
const { register } = useContext(ToastActionContext)
|
||||
useEffect(() => {
|
||||
const disposer = register(props.currentIndex, {
|
||||
dimiss: async () => {},
|
||||
dismiss: async () => {},
|
||||
})
|
||||
return () => {
|
||||
disposer()
|
||||
|
||||
@@ -28,6 +28,9 @@ export class ToastManager {
|
||||
private toastRefs = {} as Record<number, ToastRef>
|
||||
|
||||
private register(currentIndex: number, ref: ToastRef) {
|
||||
if (currentIndex in this.toastRefs) {
|
||||
console.warn("Conflict toast ref", currentIndex, this.toastRefs[currentIndex], ref)
|
||||
}
|
||||
this.toastRefs[currentIndex] = ref
|
||||
return () => {
|
||||
delete this.toastRefs[currentIndex]
|
||||
@@ -71,7 +74,7 @@ export class ToastManager {
|
||||
}
|
||||
|
||||
setTimeout(async () => {
|
||||
await this.toastRefs[index]!.dimiss()
|
||||
await this.toastRefs[index]?.dismiss()
|
||||
this.remove(index)
|
||||
}, props.duration)
|
||||
}
|
||||
|
||||
@@ -29,5 +29,5 @@ export type BottomToastProps = Partial<ToastProps> & {
|
||||
}
|
||||
|
||||
export interface ToastRef {
|
||||
dimiss: () => Promise<void>
|
||||
dismiss: () => Promise<void>
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ export const toast = {
|
||||
type,
|
||||
message,
|
||||
variant: "center-replace",
|
||||
duration: options.duration ?? 1500,
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user