about summary refs log tree commit diff
path: root/src/view/com/util/Toast.tsx
diff options
context:
space:
mode:
authorSamuel Newman <mozzius@protonmail.com>2025-07-30 18:18:36 +0300
committerGitHub <noreply@github.com>2025-07-30 08:18:36 -0700
commitdb7bdae51a1a06e67856b887e4e63a183fa5f479 (patch)
tree16b993271eb6eb5f55f4fe8808f781ff1da53120 /src/view/com/util/Toast.tsx
parentee7f50871744ac03864cc3feabee6cc23016aab6 (diff)
downloadvoidsky-db7bdae51a1a06e67856b887e4e63a183fa5f479.tar.zst
Convert old toast types to new ones, mark as deprecated (#8746)
* convert old types to new types

* add depreciation warning for old warnings

* rm as consts
Diffstat (limited to 'src/view/com/util/Toast.tsx')
-rw-r--r--src/view/com/util/Toast.tsx27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/view/com/util/Toast.tsx b/src/view/com/util/Toast.tsx
index 4c999ca2a..54ef7042d 100644
--- a/src/view/com/util/Toast.tsx
+++ b/src/view/com/util/Toast.tsx
@@ -20,7 +20,9 @@ import {useSafeAreaInsets} from 'react-native-safe-area-context'
 
 import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
 import {
+  convertLegacyToastType,
   getToastTypeStyles,
+  type LegacyToastType,
   TOAST_ANIMATION_CONFIG,
   TOAST_TYPE_TO_ICON,
   type ToastType,
@@ -30,14 +32,30 @@ import {Text} from '#/components/Typography'
 
 const TIMEOUT = 2e3
 
-export function show(message: string, type: ToastType = 'default') {
+// Use type overloading to mark certain types as deprecated -sfn
+// https://stackoverflow.com/a/78325851/13325987
+export function show(message: string, type?: ToastType): void
+/**
+ * @deprecated type is deprecated - use one of `'default' | 'success' | 'error' | 'warning' | 'info'`
+ */
+export function show(message: string, type?: LegacyToastType): void
+export function show(
+  message: string,
+  type: ToastType | LegacyToastType = 'default',
+): void {
   if (process.env.NODE_ENV === 'test') {
     return
   }
 
   AccessibilityInfo.announceForAccessibility(message)
   const item = new RootSiblings(
-    <Toast message={message} type={type} destroy={() => item.destroy()} />,
+    (
+      <Toast
+        message={message}
+        type={convertLegacyToastType(type)}
+        destroy={() => item.destroy()}
+      />
+    ),
   )
 }
 
@@ -57,9 +75,8 @@ function Toast({
   const [cardHeight, setCardHeight] = useState(0)
 
   const toastStyles = getToastTypeStyles(t)
-  const colors = toastStyles[type as keyof typeof toastStyles]
-  const IconComponent =
-    TOAST_TYPE_TO_ICON[type as keyof typeof TOAST_TYPE_TO_ICON]
+  const colors = toastStyles[type]
+  const IconComponent = TOAST_TYPE_TO_ICON[type]
 
   // for the exit animation to work on iOS the animated component
   // must not be the root component