import React , { memo , forwardRef , useRef } from 'react' ; import { usePropsResolution } from '../../../hooks/useThemeProps' ; import type { ITextProps } from './types' ; import { useHover } from '@react-native-aria/interactions' ; import { mergeRefs } from '../../../utils/mergeRefs' ; import { makeStyledComponent } from '../../../utils/styled' ; import { useResolvedFontFamily } from '../../../hooks/useResolvedFontFamily' ; import { Text as NativeText } from 'react-native' ; import { useHasResponsiveProps } from '../../../hooks/useHasResponsiveProps' ; const StyledText = makeStyledComponent ( NativeText ) ; const TextAncestorContext = React . createContext ( false ) ; const Text = ( { children , ... props } , ref ) => { const hasTextAncestor = React . useContext ( TextAncestorContext ) ; const { isTruncated , noOfLines , bold , italic , sub , highlight , underline , strikeThrough , fontFamily : propFontFamily , fontWeight : propFontWeight , fontStyle : propFontStyle , _hover , fontSize , numberOfLines , ... reslovedProps } = usePropsResolution ( 'Text' , props , { } , { resolveResponsively : [ 'noOfLines' , 'numberOfLines' ] , componentTheme : hasTextAncestor ? { } : undefined , } ) ; const _ref = useRef ( null ) ; const { isHovered } = useHover ( { } , _hover ? _ref : null ) ; let fontFamily = propFontFamily ; const fontStyle = italic ? 'italic' : propFontStyle ; const fontWeight = bold ? 'bold' : propFontWeight ; const resolvedFontFamily = useResolvedFontFamily ( { fontFamily , fontWeight : fontWeight ?? ( hasTextAncestor ? undefined : 400 ) , fontStyle : fontStyle ?? ( hasTextAncestor ? undefined : 'normal' ) , } ) ; if ( resolvedFontFamily ) { fontFamily = resolvedFontFamily ; } if ( useHasResponsiveProps ( props ) ) { return null ; } const propsToSpread = { ... reslovedProps , numberOfLines : numberOfLines || noOfLines ? numberOfLines || noOfLines : isTruncated ? 1 : undefined , ... resolvedFontFamily , bg : highlight ? 'warning.300' : reslovedProps . bg , textDecorationLine : underline && strikeThrough ? 'underline line-through' : underline ? 'underline' : strikeThrough ? 'line-through' : reslovedProps . textDecorationLine , fontSize : sub ? 10 : fontSize , ref : mergeRefs ( [ ref , _ref ] ) , ... ( isHovered && _hover ) , } ; return hasTextAncestor ? ( < StyledText { ... propsToSpread } > { children } < /StyledText>) : (<TextAncestorContext.Provider value={true}> < StyledText { ... propsToSpread } > { children } < /StyledText> < /TextAncestorContext.Provider>); } ; export default memo ( forwardRef ( Text ) ) ; export type { ITextProps } ;