import { useGT } from "gt-react-native"; import { cn } from "../../lib/cn"; import { MOBILE_MOTION, MOBILE_SHAPE } from "../../lib/designTokens"; import { type ReactNode, useCallback, useEffect, useLayoutEffect, useState } from "react"; import { AccessibilityInfo, Platform, Pressable, StyleSheet, View, useWindowDimensions, } from "react-native"; import { GestureDetector, usePanGesture } from "react-native-gesture-handler"; import Animated, { cancelAnimation, Easing, FadeOut, ReduceMotion, runOnJS, useAnimatedStyle, useDerivedValue, useSharedValue, withTiming, type EntryAnimationsValues, } from "react-native-reanimated"; import { AppText } from "./AppText"; import { Button } from "./Button"; import { GlassSurface } from "./GlassSurface"; import { useControlTheme } from "./useControlTheme"; import { IconButton } from "./IconButton"; import { AppActivityIndicator } from "./AppActivityIndicator"; import { SymbolView } from "./AppSymbol"; export type ToastProps = { readonly message: string; readonly description?: string; readonly singleLine?: boolean; readonly tone?: "default" | "success" | "warning" | "danger"; readonly busy?: boolean; readonly action?: { readonly label: string; readonly onPress: () => void }; /** Details a chevron beside the message reveals below it while `expanded`. */ readonly children?: ReactNode; readonly expanded?: boolean; readonly onExpandedChange?: (expanded: boolean) => void; } & ( | { readonly dismissMode: "swipe"; readonly onDismiss: () => void } | { readonly dismissMode?: "button"; readonly onDismiss?: () => void } ); export function Toast(props: ToastProps) { return props.dismissMode === "swipe" ? ( ) : ( ); } function ToastContent(props: ToastProps & { readonly glassReady?: boolean }) { const gt = useGT(); const { fontScale } = useWindowDimensions(); const { colorScheme } = useControlTheme(); const borderRadius = Platform.OS === "ios" ? 28 : MOBILE_SHAPE.toast; // Explicit single-line notices reserve the action's width and truncate the text. const inlineAction = props.singleLine || (!props.description && fontScale < 1.5); const message = props.singleLine && props.description ? `${props.message}: ${props.description}` : props.message; const action = props.action ? (