xref: /MusicFree/src/pages/artistDetail/components/header.tsx (revision e7fa3837138cc7f9a5fa0fb610c27f442edfacc2)
14060c00aS猫头猫import React, {useEffect} from 'react';
24060c00aS猫头猫import {StyleSheet, View} from 'react-native';
3be474dd8S猫头猫import rpx from '@/utils/rpx';
420e2869eS猫头猫import Animated, {
520e2869eS猫头猫    useAnimatedStyle,
620e2869eS猫头猫    useSharedValue,
720e2869eS猫头猫    withTiming,
820e2869eS猫头猫} from 'react-native-reanimated';
920e2869eS猫头猫import {useAtomValue} from 'jotai';
1020e2869eS猫头猫import {scrollToTopAtom} from '../store/atoms';
1120e2869eS猫头猫import {Avatar} from 'react-native-paper';
1220e2869eS猫头猫import ThemeText from '@/components/base/themeText';
1320e2869eS猫头猫import Tag from '@/components/base/tag';
14*e7fa3837S猫头猫import {useParams} from '@/entry/router';
15be474dd8S猫头猫
1620e2869eS猫头猫const headerHeight = rpx(350);
174060c00aS猫头猫export default function Header() {
18*e7fa3837S猫头猫    const {artistItem} = useParams<'artist-detail'>();
1920e2869eS猫头猫
2020e2869eS猫头猫    const heightValue = useSharedValue(headerHeight);
2120e2869eS猫头猫    const opacityValue = useSharedValue(1);
2220e2869eS猫头猫    const scrollToTopState = useAtomValue(scrollToTopAtom);
2320e2869eS猫头猫
2420e2869eS猫头猫    const heightStyle = useAnimatedStyle(() => {
2520e2869eS猫头猫        return {
2620e2869eS猫头猫            height: heightValue.value,
2720e2869eS猫头猫            opacity: opacityValue.value,
2820e2869eS猫头猫        };
2920e2869eS猫头猫    });
3020e2869eS猫头猫
3120e2869eS猫头猫    const avatar = artistItem.avatar?.startsWith('//')
3220e2869eS猫头猫        ? `https:${artistItem.avatar}`
3320e2869eS猫头猫        : artistItem.avatar;
3420e2869eS猫头猫
3520e2869eS猫头猫    /** 折叠 */
3620e2869eS猫头猫    useEffect(() => {
3720e2869eS猫头猫        if (scrollToTopState) {
3820e2869eS猫头猫            heightValue.value = withTiming(headerHeight);
3920e2869eS猫头猫            opacityValue.value = withTiming(1);
4020e2869eS猫头猫        } else {
4120e2869eS猫头猫            heightValue.value = withTiming(0);
4220e2869eS猫头猫            opacityValue.value = withTiming(0);
4320e2869eS猫头猫        }
4420e2869eS猫头猫    }, [scrollToTopState]);
4520e2869eS猫头猫
4620e2869eS猫头猫    return (
4720e2869eS猫头猫        <Animated.View style={[style.wrapper, heightStyle]}>
4820e2869eS猫头猫            <View style={style.headerWrapper}>
494060c00aS猫头猫                <Avatar.Image size={rpx(144)} source={{uri: avatar}} />
5020e2869eS猫头猫                <View style={style.info}>
5120e2869eS猫头猫                    <View style={style.title}>
5220e2869eS猫头猫                        <ThemeText
5320e2869eS猫头猫                            fontSize="title"
5420e2869eS猫头猫                            style={style.titleText}
5520e2869eS猫头猫                            numberOfLines={1}
5620e2869eS猫头猫                            ellipsizeMode="tail">
5720e2869eS猫头猫                            {artistItem.name}
5820e2869eS猫头猫                        </ThemeText>
594060c00aS猫头猫                        {artistItem.platform && (
604060c00aS猫头猫                            <Tag tagName={artistItem.platform} />
614060c00aS猫头猫                        )}
6220e2869eS猫头猫                    </View>
6320e2869eS猫头猫
6420e2869eS猫头猫                    {artistItem.fans && (
6520e2869eS猫头猫                        <ThemeText fontSize="subTitle" fontColor="secondary">
6620e2869eS猫头猫                            粉丝数: {artistItem.fans}
6720e2869eS猫头猫                        </ThemeText>
6820e2869eS猫头猫                    )}
6920e2869eS猫头猫                </View>
7020e2869eS猫头猫            </View>
7120e2869eS猫头猫
7220e2869eS猫头猫            <ThemeText
7320e2869eS猫头猫                style={style.description}
7420e2869eS猫头猫                numberOfLines={2}
7520e2869eS猫头猫                ellipsizeMode="tail"
7620e2869eS猫头猫                fontColor="secondary"
7720e2869eS猫头猫                fontSize="description">
7820e2869eS猫头猫                {artistItem.description}
7920e2869eS猫头猫            </ThemeText>
8020e2869eS猫头猫        </Animated.View>
8120e2869eS猫头猫    );
82be474dd8S猫头猫}
83be474dd8S猫头猫
84be474dd8S猫头猫const style = StyleSheet.create({
85be474dd8S猫头猫    wrapper: {
86be474dd8S猫头猫        width: rpx(750),
8720e2869eS猫头猫        height: headerHeight,
8820e2869eS猫头猫        backgroundColor: 'rgba(28, 28, 28, 0.1)',
8920e2869eS猫头猫        zIndex: 1,
9020e2869eS猫头猫    },
9120e2869eS猫头猫    headerWrapper: {
9220e2869eS猫头猫        width: rpx(750),
9320e2869eS猫头猫        paddingTop: rpx(24),
9420e2869eS猫头猫        paddingHorizontal: rpx(24),
9520e2869eS猫头猫        height: rpx(240),
9620e2869eS猫头猫        flexDirection: 'row',
9720e2869eS猫头猫        alignItems: 'center',
9820e2869eS猫头猫    },
9920e2869eS猫头猫    info: {
10020e2869eS猫头猫        marginLeft: rpx(24),
10120e2869eS猫头猫        justifyContent: 'space-around',
10220e2869eS猫头猫        height: rpx(144),
10320e2869eS猫头猫    },
10420e2869eS猫头猫    title: {
10520e2869eS猫头猫        flexDirection: 'row',
10620e2869eS猫头猫        alignItems: 'center',
10720e2869eS猫头猫    },
10820e2869eS猫头猫    titleText: {
10920e2869eS猫头猫        marginRight: rpx(18),
11020e2869eS猫头猫        maxWidth: rpx(400),
11120e2869eS猫头猫    },
11220e2869eS猫头猫    description: {
11320e2869eS猫头猫        marginTop: rpx(24),
11420e2869eS猫头猫        width: rpx(750),
11520e2869eS猫头猫        paddingHorizontal: rpx(24),
116be474dd8S猫头猫    },
117be474dd8S猫头猫});
118