expo-duooomi-app/@share/components/Text.tsx

49 lines
1.1 KiB
TypeScript

import React, { forwardRef } from 'react'
import {
type StyleProp,
Text as RNText,
type TextProps as RNTextProps,
type TextStyle,
TouchableOpacity,
type TouchableOpacityProps,
} from 'react-native'
import Animated from 'react-native-reanimated'
interface TextProps extends RNTextProps {
onClick?: () => void
touchProps?: TouchableOpacityProps
animated?: boolean
style?: StyleProp<TextStyle>
className?: string
}
const Text = forwardRef<RNText, TextProps>((props, ref) => {
const { onClick, touchProps = {}, animated, style, className = '', children, ...reset } = props
const textProps = {
className,
ref: ref,
...reset,
}
const handlePress = () => {
onClick && onClick()
}
if (animated) {
return <Animated.Text {...textProps}>{children}</Animated.Text>
}
if (onClick) {
return (
<TouchableOpacity activeOpacity={1} onPress={handlePress} {...touchProps}>
<RNText {...textProps}>{children}</RNText>
</TouchableOpacity>
)
}
return <RNText {...textProps}>{children}</RNText>
})
Text.displayName = 'Text'
export default Text