xref: /MusicFree/src/components/base/linkText.tsx (revision a22fe20fec36f6663a9f0517917d68661349bfca)
1*a22fe20fS猫头猫import React, {useState} from 'react';
20cffb46aS猫头猫import {StyleSheet, TextProps} from 'react-native';
30cffb46aS猫头猫import {fontSizeConst, fontWeightConst} from '@/constants/uiConst';
40cffb46aS猫头猫import openUrl from '@/utils/openUrl';
50cffb46aS猫头猫import ThemeText from './themeText';
6*a22fe20fS猫头猫import Color from 'color';
70cffb46aS猫头猫
80cffb46aS猫头猫type ILinkTextProps = TextProps & {
90cffb46aS猫头猫    fontSize?: keyof typeof fontSizeConst;
100cffb46aS猫头猫    fontWeight?: keyof typeof fontWeightConst;
110cffb46aS猫头猫    linkTo?: string;
120cffb46aS猫头猫};
130cffb46aS猫头猫
140cffb46aS猫头猫export default function LinkText(props: ILinkTextProps) {
15*a22fe20fS猫头猫    const [isPressed, setIsPressed] = useState(false);
16*a22fe20fS猫头猫
170cffb46aS猫头猫    return (
18*a22fe20fS猫头猫        <ThemeText
19*a22fe20fS猫头猫            {...props}
20*a22fe20fS猫头猫            style={[style.linkText, isPressed ? style.pressed : null]}
21*a22fe20fS猫头猫            onPressIn={() => {
22*a22fe20fS猫头猫                setIsPressed(true);
23*a22fe20fS猫头猫            }}
240cffb46aS猫头猫            onPress={() => {
250cffb46aS猫头猫                props?.linkTo && openUrl(props.linkTo);
26*a22fe20fS猫头猫            }}
27*a22fe20fS猫头猫            onPressOut={() => {
28*a22fe20fS猫头猫                setIsPressed(false);
290cffb46aS猫头猫            }}>
300cffb46aS猫头猫            {props.children}
310cffb46aS猫头猫        </ThemeText>
320cffb46aS猫头猫    );
330cffb46aS猫头猫}
340cffb46aS猫头猫
350cffb46aS猫头猫const style = StyleSheet.create({
360cffb46aS猫头猫    linkText: {
370cffb46aS猫头猫        color: '#66ccff',
380cffb46aS猫头猫        textDecorationLine: 'underline',
390cffb46aS猫头猫    },
40*a22fe20fS猫头猫    pressed: {
41*a22fe20fS猫头猫        color: Color('#66ccff').alpha(0.4).toString(),
42*a22fe20fS猫头猫    },
430cffb46aS猫头猫});
44