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:
Whitewater
2025-04-27 15:17:50 +08:00
committed by GitHub
parent 165c7ab06e
commit 1fad306f67
4 changed files with 7 additions and 3 deletions
@@ -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)
}
+1 -1
View File
@@ -29,5 +29,5 @@ export type BottomToastProps = Partial<ToastProps> & {
}
export interface ToastRef {
dimiss: () => Promise<void>
dismiss: () => Promise<void>
}
+1
View File
@@ -48,6 +48,7 @@ export const toast = {
type,
message,
variant: "center-replace",
duration: options.duration ?? 1500,
...options,
})
}