xref: /MusicFree/src/pages/artistDetail/components/header.tsx (revision 7cee35b58b501a7106abb58f28f65635818368ef)
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';
14e7fa3837S猫头猫import {useParams} from '@/entry/router';
15be474dd8S猫头猫
1620e2869eS猫头猫const headerHeight = rpx(350);
17*7cee35b5S猫头猫
18*7cee35b5S猫头猫interface IHeaderProps {
19*7cee35b5S猫头猫    neverFold?: boolean;
20*7cee35b5S猫头猫}
21*7cee35b5S猫头猫
22*7cee35b5S猫头猫export default function Header(props: IHeaderProps) {
23*7cee35b5S猫头猫    const {neverFold} = props;
24*7cee35b5S猫头猫
25e7fa3837S猫头猫    const {artistItem} = useParams<'artist-detail'>();
2620e2869eS猫头猫
2720e2869eS猫头猫    const heightValue = useSharedValue(headerHeight);
2820e2869eS猫头猫    const opacityValue = useSharedValue(1);
2920e2869eS猫头猫    const scrollToTopState = useAtomValue(scrollToTopAtom);
3020e2869eS猫头猫
3120e2869eS猫头猫    const heightStyle = useAnimatedStyle(() => {
3220e2869eS猫头猫        return {
3320e2869eS猫头猫            height: heightValue.value,
3420e2869eS猫头猫            opacity: opacityValue.value,
3520e2869eS猫头猫        };
3620e2869eS猫头猫    });
3720e2869eS猫头猫
3820e2869eS猫头猫    const avatar = artistItem.avatar?.startsWith('//')
3920e2869eS猫头猫        ? `https:${artistItem.avatar}`
4020e2869eS猫头猫        : artistItem.avatar;
4120e2869eS猫头猫
4220e2869eS猫头猫    /** 折叠 */
4320e2869eS猫头猫    useEffect(() => {
44*7cee35b5S猫头猫        if (neverFold) {
45*7cee35b5S猫头猫            heightValue.value = withTiming(headerHeight);
46*7cee35b5S猫头猫            opacityValue.value = withTiming(1);
47*7cee35b5S猫头猫            return;
48*7cee35b5S猫头猫        }
4920e2869eS猫头猫        if (scrollToTopState) {
5020e2869eS猫头猫            heightValue.value = withTiming(headerHeight);
5120e2869eS猫头猫            opacityValue.value = withTiming(1);
5220e2869eS猫头猫        } else {
5320e2869eS猫头猫            heightValue.value = withTiming(0);
5420e2869eS猫头猫            opacityValue.value = withTiming(0);
5520e2869eS猫头猫        }
56*7cee35b5S猫头猫    }, [scrollToTopState, neverFold]);
5720e2869eS猫头猫
5820e2869eS猫头猫    return (
5920e2869eS猫头猫        <Animated.View style={[style.wrapper, heightStyle]}>
6020e2869eS猫头猫            <View style={style.headerWrapper}>
614060c00aS猫头猫                <Avatar.Image size={rpx(144)} source={{uri: avatar}} />
6220e2869eS猫头猫                <View style={style.info}>
6320e2869eS猫头猫                    <View style={style.title}>
6420e2869eS猫头猫                        <ThemeText
6520e2869eS猫头猫                            fontSize="title"
6620e2869eS猫头猫                            style={style.titleText}
6720e2869eS猫头猫                            numberOfLines={1}
6820e2869eS猫头猫                            ellipsizeMode="tail">
69c9fce3b5S猫头猫                            {artistItem?.name ?? ''}
7020e2869eS猫头猫                        </ThemeText>
71c9fce3b5S猫头猫                        {artistItem.platform ? (
724060c00aS猫头猫                            <Tag tagName={artistItem.platform} />
731fbef60aS猫头猫                        ) : null}
7420e2869eS猫头猫                    </View>
7520e2869eS猫头猫
76c9fce3b5S猫头猫                    {artistItem.fans ? (
7720e2869eS猫头猫                        <ThemeText fontSize="subTitle" fontColor="secondary">
7820e2869eS猫头猫                            粉丝数: {artistItem.fans}
7920e2869eS猫头猫                        </ThemeText>
801fbef60aS猫头猫                    ) : null}
8120e2869eS猫头猫                </View>
8220e2869eS猫头猫            </View>
8320e2869eS猫头猫
8420e2869eS猫头猫            <ThemeText
8520e2869eS猫头猫                style={style.description}
8620e2869eS猫头猫                numberOfLines={2}
8720e2869eS猫头猫                ellipsizeMode="tail"
8820e2869eS猫头猫                fontColor="secondary"
8920e2869eS猫头猫                fontSize="description">
90c9fce3b5S猫头猫                {artistItem?.description ?? ''}
9120e2869eS猫头猫            </ThemeText>
9220e2869eS猫头猫        </Animated.View>
9320e2869eS猫头猫    );
94be474dd8S猫头猫}
95be474dd8S猫头猫
96be474dd8S猫头猫const style = StyleSheet.create({
97be474dd8S猫头猫    wrapper: {
98be474dd8S猫头猫        width: rpx(750),
9920e2869eS猫头猫        height: headerHeight,
10020e2869eS猫头猫        backgroundColor: 'rgba(28, 28, 28, 0.1)',
10120e2869eS猫头猫        zIndex: 1,
10220e2869eS猫头猫    },
10320e2869eS猫头猫    headerWrapper: {
10420e2869eS猫头猫        width: rpx(750),
10520e2869eS猫头猫        paddingTop: rpx(24),
10620e2869eS猫头猫        paddingHorizontal: rpx(24),
10720e2869eS猫头猫        height: rpx(240),
10820e2869eS猫头猫        flexDirection: 'row',
10920e2869eS猫头猫        alignItems: 'center',
11020e2869eS猫头猫    },
11120e2869eS猫头猫    info: {
11220e2869eS猫头猫        marginLeft: rpx(24),
11320e2869eS猫头猫        justifyContent: 'space-around',
11420e2869eS猫头猫        height: rpx(144),
11520e2869eS猫头猫    },
11620e2869eS猫头猫    title: {
11720e2869eS猫头猫        flexDirection: 'row',
11820e2869eS猫头猫        alignItems: 'center',
11920e2869eS猫头猫    },
12020e2869eS猫头猫    titleText: {
12120e2869eS猫头猫        marginRight: rpx(18),
12220e2869eS猫头猫        maxWidth: rpx(400),
12320e2869eS猫头猫    },
12420e2869eS猫头猫    description: {
12520e2869eS猫头猫        marginTop: rpx(24),
12620e2869eS猫头猫        width: rpx(750),
12720e2869eS猫头猫        paddingHorizontal: rpx(24),
128be474dd8S猫头猫    },
129be474dd8S猫头猫});
130