import React , { forwardRef , memo } from 'react' ; import { Pressable as RNPressable } from 'react-native' ; import { composeEventHandlers } from '../../../utils' ; import type { IPressableProps } from './types' ; import { useHasResponsiveProps } from '../../../hooks/useHasResponsiveProps' ; import { makeStyledComponent } from '../../../utils/styled' ; import { usePropsResolution } from '../../../hooks/useThemeProps' ; import { useFocusRing } from '@react-native-aria/focus' ; export const useHover = ( ) => { const [ isHovered , setHovered ] = React . useState ( false ) ; return { hoverProps : { onHoverIn : ( ) => setHovered ( true ) , onHoverOut : ( ) => setHovered ( false ) , } , isHovered , } ; } ; export const useFocus = ( ) => { const [ isFocused , setFocused ] = React . useState ( false ) ; return { focusProps : { onFocus : ( ) => setFocused ( true ) , onBlur : ( ) => setFocused ( false ) , } , isFocused , } ; } ; export const useIsPressed = ( ) => { const [ isPressed , setIsPressed ] = React . useState ( false ) ; return { pressableProps : { onPressIn : ( ) => setIsPressed ( true ) , onPressOut : ( ) => setIsPressed ( false ) , } , isPressed , } ; } ; const StyledPressable = makeStyledComponent ( RNPressable ) ; const Pressable = ( { children , isDisabled , disabled , ... props } , ref ) => { const { hoverProps , isHovered } = useHover ( ) ; const { pressableProps , isPressed } = useIsPressed ( ) ; const { focusProps , isFocused } = useFocus ( ) ; const { isFocusVisible , focusProps : focusRingProps } = useFocusRing ( ) ; const { onPressIn , onPressOut , onHoverIn , onHoverOut , onFocus , onBlur , ... resolvedProps } = usePropsResolution ( 'Pressable' , props , { isPressed , isFocused , isHovered , isFocusVisible , isDisabled : disabled || isDisabled , } ) ; if ( useHasResponsiveProps ( props ) ) { return null ; } return ( < StyledPressable ref = { ref } onPressIn = { composeEventHandlers ( onPressIn , pressableProps . onPressIn ) } onPressOut = { composeEventHandlers ( onPressOut , pressableProps . onPressOut ) } onHoverIn = { composeEventHandlers ( onHoverIn , hoverProps . onHoverIn ) } onHoverOut = { composeEventHandlers ( onHoverOut , hoverProps . onHoverOut ) } onFocus = { composeEventHandlers ( composeEventHandlers ( onFocus , focusProps . onFocus ) , focusRingProps . onFocus ) } onBlur = { composeEventHandlers ( composeEventHandlers ( onBlur , focusProps . onBlur ) , focusRingProps . onBlur ) } disabled = { disabled || isDisabled } { ... resolvedProps } > { typeof children !== 'function' ? children : children ( { isPressed , isHovered , isFocused , } ) } < /StyledPressable>); } ; export default memo ( forwardRef ( Pressable ) ) ;