'use client'; import { createToastHook } from '@gluestack-ui/core/toast/creator'; import type { VariantProps } from '@gluestack-ui/utils/nativewind-utils'; import { tva, useStyleContext, withStyleContext } from '@gluestack-ui/utils/nativewind-utils'; import { styled } from 'nativewind'; import React from 'react'; import { AccessibilityInfo, Text, View } from 'react-native'; import Animated, { SlideInUp } from 'react-native-reanimated'; const useToast = createToastHook(View); const SCOPE = 'TOAST'; const AnimatedView = Animated.createAnimatedComponent(View); const StyledAnimatedView = styled(AnimatedView, { className: 'style' }); const toastStyle = tva({ base: 'p-4 m-1 rounded-md gap-1 web:pointer-events-auto border-border', variants: { action: { error: 'bg-popover text-popover-foreground', warning: 'bg-popover text-popover-foreground', success: 'bg-popover text-popover-foreground', info: 'bg-popover text-popover-foreground', muted: 'bg-popover text-popover-foreground', }, variant: { solid: 'border border-border bg-popover shadow-soft-4', outline: 'border border-border bg-popover', }, }, }); const toastTitleStyle = tva({ base: 'font-medium font-body tracking-md text-left', variants: { isTruncated: { true: '', }, bold: { true: 'font-bold', }, underline: { true: 'underline', }, strikeThrough: { true: 'line-through', }, size: { '2xs': 'text-2xs', 'xs': 'text-xs', 'sm': 'text-sm', 'md': 'text-base', 'lg': 'text-lg', 'xl': 'text-xl', '2xl': 'text-2xl', '3xl': 'text-3xl', '4xl': 'text-4xl', '5xl': 'text-5xl', '6xl': 'text-6xl', }, }, parentVariants: { variant: { solid: '', outline: 'text-foreground', }, action: { error: '', warning: '', success: '', info: '', muted: '', }, }, parentCompoundVariants: [ { variant: 'solid', action: 'error', class: 'text-destructive-foreground', }, { variant: 'solid', action: 'warning', class: 'text-accent-foreground', }, { variant: 'solid', action: 'success', class: 'text-secondary-foreground', }, { variant: 'solid', action: 'info', class: 'text-popover-foreground', }, { variant: 'solid', action: 'muted', class: 'text-muted-foreground', }, { variant: 'outline', action: 'error', class: 'text-destructive', }, { variant: 'outline', action: 'warning', class: 'text-accent-foreground', }, { variant: 'outline', action: 'success', class: 'text-secondary-foreground', }, { variant: 'outline', action: 'info', class: 'text-popover-foreground', }, { variant: 'outline', action: 'muted', class: 'text-muted-foreground', }, ], }); const toastDescriptionStyle = tva({ base: 'font-normal font-body tracking-md text-left', variants: { isTruncated: { true: '', }, bold: { true: 'font-bold', }, underline: { true: 'underline', }, strikeThrough: { true: 'line-through', }, size: { '2xs': 'text-2xs', 'xs': 'text-xs', 'sm': 'text-sm', 'md': 'text-base', 'lg': 'text-lg', 'xl': 'text-xl', '2xl': 'text-2xl', '3xl': 'text-3xl', '4xl': 'text-4xl', '5xl': 'text-5xl', '6xl': 'text-6xl', }, }, parentVariants: { variant: { solid: 'text-muted-foreground', outline: 'text-muted-foreground', }, }, }); const Root = withStyleContext(StyledAnimatedView, SCOPE); type IToastProps = React.ComponentProps & { className?: string; } & VariantProps; const Toast = React.forwardRef, IToastProps>( function Toast( { className, variant = 'solid', action = 'muted', ...props }, ref ) { return ( ); } ); type IToastTitleProps = React.ComponentProps & { className?: string; } & VariantProps; const ToastTitle = React.forwardRef< React.ComponentRef, IToastTitleProps >(function ToastTitle({ className, size = 'md', children, ...props }, ref) { const { variant: parentVariant, action: parentAction } = useStyleContext(SCOPE); React.useEffect(() => { // Issue from react-native side // Hack for now, will fix this later AccessibilityInfo.announceForAccessibility(children as string); }, [children]); return ( {children} ); }); type IToastDescriptionProps = React.ComponentProps & { className?: string; } & VariantProps; const ToastDescription = React.forwardRef< React.ComponentRef, IToastDescriptionProps >(function ToastDescription({ className, size = 'md', ...props }, ref) { const { variant: parentVariant } = useStyleContext(SCOPE); return ( ); }); Toast.displayName = 'Toast'; ToastTitle.displayName = 'ToastTitle'; ToastDescription.displayName = 'ToastDescription'; export { Toast, ToastDescription, ToastTitle, useToast };