1a22fe20fS猫头猫import React, {useState} from 'react'; 2*f01fe338S猫头猫import {GestureResponderEvent, StyleSheet, TextProps} from 'react-native'; 30cffb46aS猫头猫import {fontSizeConst, fontWeightConst} from '@/constants/uiConst'; 40cffb46aS猫头猫import openUrl from '@/utils/openUrl'; 50cffb46aS猫头猫import ThemeText from './themeText'; 6a22fe20fS猫头猫import Color from 'color'; 70cffb46aS猫头猫 80cffb46aS猫头猫type ILinkTextProps = TextProps & { 90cffb46aS猫头猫 fontSize?: keyof typeof fontSizeConst; 100cffb46aS猫头猫 fontWeight?: keyof typeof fontWeightConst; 110cffb46aS猫头猫 linkTo?: string; 12*f01fe338S猫头猫 onPress?: (event: GestureResponderEvent) => void; 130cffb46aS猫头猫}; 140cffb46aS猫头猫 150cffb46aS猫头猫export default function LinkText(props: ILinkTextProps) { 16a22fe20fS猫头猫 const [isPressed, setIsPressed] = useState(false); 17a22fe20fS猫头猫 180cffb46aS猫头猫 return ( 19a22fe20fS猫头猫 <ThemeText 20a22fe20fS猫头猫 {...props} 21a22fe20fS猫头猫 style={[style.linkText, isPressed ? style.pressed : null]} 22a22fe20fS猫头猫 onPressIn={() => { 23a22fe20fS猫头猫 setIsPressed(true); 24a22fe20fS猫头猫 }} 25*f01fe338S猫头猫 onPress={evt => { 26*f01fe338S猫头猫 if (props.onPress) { 27*f01fe338S猫头猫 props.onPress(evt); 28*f01fe338S猫头猫 } else { 290cffb46aS猫头猫 props?.linkTo && openUrl(props.linkTo); 30*f01fe338S猫头猫 } 31a22fe20fS猫头猫 }} 32a22fe20fS猫头猫 onPressOut={() => { 33a22fe20fS猫头猫 setIsPressed(false); 340cffb46aS猫头猫 }}> 350cffb46aS猫头猫 {props.children} 360cffb46aS猫头猫 </ThemeText> 370cffb46aS猫头猫 ); 380cffb46aS猫头猫} 390cffb46aS猫头猫 400cffb46aS猫头猫const style = StyleSheet.create({ 410cffb46aS猫头猫 linkText: { 420cffb46aS猫头猫 color: '#66ccff', 430cffb46aS猫头猫 textDecorationLine: 'underline', 440cffb46aS猫头猫 }, 45a22fe20fS猫头猫 pressed: { 46a22fe20fS猫头猫 color: Color('#66ccff').alpha(0.4).toString(), 47a22fe20fS猫头猫 }, 480cffb46aS猫头猫}); 49