import { createContext, forwardRef, useContext, useId } from 'react'; import { Pressable, Text, View, type GestureResponderEvent, } from 'react-native'; import * as Slot from '../slot'; import type { ActionProps, ActionRef, CloseProps, CloseRef, DescriptionProps, DescriptionRef, RootContext, RootProps, RootRef, TitleProps, TitleRef, } from './toast.types'; const ToastContext = createContext(null); const Root = forwardRef( ({ asChild, id, ...viewProps }, ref) => { const generatedId = useId(); const nativeID = id || generatedId; const Component = asChild ? Slot.View : View; return ( ); } ); function useRootContext() { const context = useContext(ToastContext); if (!context) { throw new Error( 'Toast compound components cannot be rendered outside the Toast component' ); } return context; } Root.displayName = 'HeroUINative.Primitive.Toast.Root'; // -------------------------------------------------- const Title = forwardRef((props, ref) => { const { nativeID } = useRootContext(); return ( ); }); Title.displayName = 'HeroUINative.Primitive.Toast.Title'; // -------------------------------------------------- const Description = forwardRef( (props, ref) => { const { nativeID } = useRootContext(); return ; } ); Description.displayName = 'HeroUINative.Primitive.Toast.Description'; // -------------------------------------------------- const Action = forwardRef( ({ asChild, altText, disabled = false, ...props }, ref) => { const Component = asChild ? Slot.Pressable : Pressable; return ( ); } ); Action.displayName = 'HeroUINative.Primitive.Toast.Action'; // -------------------------------------------------- const Close = forwardRef( ({ asChild, disabled = false, onPress: onPressProp, ...props }, ref) => { function onPress(ev: GestureResponderEvent) { if (disabled) return; onPressProp?.(ev); } const Component = asChild ? Slot.Pressable : Pressable; return ( ); } ); Close.displayName = 'HeroUINative.Primitive.Toast.Close'; // -------------------------------------------------- export { Action, Close, Description, Root, Title, useRootContext };