import { forwardRef } from 'react'; import { Pressable, View, type GestureResponderEvent } from 'react-native'; import * as Slot from '../slot'; import type { RootProps, RootRef, ThumbProps, ThumbRef } from './switch.types'; // -------------------------------------------------- const Root = forwardRef( ( { asChild, isSelected, onSelectedChange, isDisabled, 'onPress': onPressProp, 'aria-valuetext': ariaValueText, ...props }, ref ) => { function onPress(ev: GestureResponderEvent) { if (isDisabled) return; const newValue = !isSelected; onSelectedChange?.(newValue); onPressProp?.(ev); } const Component = asChild ? Slot.Pressable : Pressable; return ( ); } ); Root.displayName = 'HeroUINative.Primitive.Switch.Root'; // -------------------------------------------------- const Thumb = forwardRef(({ asChild, ...props }, ref) => { const Component = asChild ? Slot.View : View; return ; }); Thumb.displayName = 'HeroUINative.Primitive.Switch.Thumb'; export { Root, Thumb };