1*20e2869eS猫头猫import React, {useEffect, useRef} from 'react'; 2be474dd8S猫头猫import {StyleSheet, Text, View} from 'react-native'; 3be474dd8S猫头猫import rpx from '@/utils/rpx'; 4*20e2869eS猫头猫import Animated, { 5*20e2869eS猫头猫 useAnimatedStyle, 6*20e2869eS猫头猫 useSharedValue, 7*20e2869eS猫头猫 withTiming, 8*20e2869eS猫头猫} from 'react-native-reanimated'; 9*20e2869eS猫头猫import {useAtomValue} from 'jotai'; 10*20e2869eS猫头猫import {scrollToTopAtom} from '../store/atoms'; 11*20e2869eS猫头猫import {Avatar} from 'react-native-paper'; 12*20e2869eS猫头猫import Image from '@/components/base/image'; 13*20e2869eS猫头猫import {fontSizeConst} from '@/constants/uiConst'; 14*20e2869eS猫头猫import ThemeText from '@/components/base/themeText'; 15*20e2869eS猫头猫import Tag from '@/components/base/tag'; 16*20e2869eS猫头猫import { useRoute } from '@react-navigation/native'; 17be474dd8S猫头猫 18*20e2869eS猫头猫interface IHeaderProps { 19*20e2869eS猫头猫} 20*20e2869eS猫头猫 21*20e2869eS猫头猫const headerHeight = rpx(350); 22be474dd8S猫头猫export default function Header(props: IHeaderProps) { 23*20e2869eS猫头猫 const route = useRoute<any>(); 24*20e2869eS猫头猫 const artistItem: IArtist.IArtistItem = route.params?.artistItem ?? null; 25*20e2869eS猫头猫 26*20e2869eS猫头猫 const heightValue = useSharedValue(headerHeight); 27*20e2869eS猫头猫 const opacityValue = useSharedValue(1); 28*20e2869eS猫头猫 const scrollToTopState = useAtomValue(scrollToTopAtom); 29*20e2869eS猫头猫 30*20e2869eS猫头猫 const heightStyle = useAnimatedStyle(() => { 31*20e2869eS猫头猫 return { 32*20e2869eS猫头猫 height: heightValue.value, 33*20e2869eS猫头猫 opacity: opacityValue.value, 34*20e2869eS猫头猫 }; 35*20e2869eS猫头猫 }); 36*20e2869eS猫头猫 37*20e2869eS猫头猫 const avatar = artistItem.avatar?.startsWith('//') 38*20e2869eS猫头猫 ? `https:${artistItem.avatar}` 39*20e2869eS猫头猫 : artistItem.avatar; 40*20e2869eS猫头猫 41*20e2869eS猫头猫 /** 折叠 */ 42*20e2869eS猫头猫 useEffect(() => { 43*20e2869eS猫头猫 if (scrollToTopState) { 44*20e2869eS猫头猫 heightValue.value = withTiming(headerHeight); 45*20e2869eS猫头猫 opacityValue.value = withTiming(1); 46*20e2869eS猫头猫 } else { 47*20e2869eS猫头猫 heightValue.value = withTiming(0); 48*20e2869eS猫头猫 opacityValue.value = withTiming(0); 49*20e2869eS猫头猫 } 50*20e2869eS猫头猫 }, [scrollToTopState]); 51*20e2869eS猫头猫 52*20e2869eS猫头猫 return ( 53*20e2869eS猫头猫 <Animated.View style={[style.wrapper, heightStyle]}> 54*20e2869eS猫头猫 <View style={style.headerWrapper}> 55*20e2869eS猫头猫 <Avatar.Image size={rpx(144)} source={{uri: avatar}}></Avatar.Image> 56*20e2869eS猫头猫 <View style={style.info}> 57*20e2869eS猫头猫 <View style={style.title}> 58*20e2869eS猫头猫 <ThemeText 59*20e2869eS猫头猫 fontSize="title" 60*20e2869eS猫头猫 style={style.titleText} 61*20e2869eS猫头猫 numberOfLines={1} 62*20e2869eS猫头猫 ellipsizeMode="tail"> 63*20e2869eS猫头猫 {artistItem.name} 64*20e2869eS猫头猫 </ThemeText> 65*20e2869eS猫头猫 {artistItem.platform && <Tag tagName={artistItem.platform}></Tag>} 66*20e2869eS猫头猫 </View> 67*20e2869eS猫头猫 68*20e2869eS猫头猫 {artistItem.fans && ( 69*20e2869eS猫头猫 <ThemeText fontSize="subTitle" fontColor="secondary"> 70*20e2869eS猫头猫 粉丝数: {artistItem.fans} 71*20e2869eS猫头猫 </ThemeText> 72*20e2869eS猫头猫 )} 73*20e2869eS猫头猫 </View> 74*20e2869eS猫头猫 </View> 75*20e2869eS猫头猫 76*20e2869eS猫头猫 <ThemeText 77*20e2869eS猫头猫 style={style.description} 78*20e2869eS猫头猫 numberOfLines={2} 79*20e2869eS猫头猫 ellipsizeMode="tail" 80*20e2869eS猫头猫 fontColor="secondary" 81*20e2869eS猫头猫 fontSize="description"> 82*20e2869eS猫头猫 {artistItem.description} 83*20e2869eS猫头猫 </ThemeText> 84*20e2869eS猫头猫 </Animated.View> 85*20e2869eS猫头猫 ); 86be474dd8S猫头猫} 87be474dd8S猫头猫 88be474dd8S猫头猫const style = StyleSheet.create({ 89be474dd8S猫头猫 wrapper: { 90be474dd8S猫头猫 width: rpx(750), 91*20e2869eS猫头猫 height: headerHeight, 92*20e2869eS猫头猫 backgroundColor: 'rgba(28, 28, 28, 0.1)', 93*20e2869eS猫头猫 zIndex: 1, 94*20e2869eS猫头猫 }, 95*20e2869eS猫头猫 headerWrapper: { 96*20e2869eS猫头猫 width: rpx(750), 97*20e2869eS猫头猫 paddingTop: rpx(24), 98*20e2869eS猫头猫 paddingHorizontal: rpx(24), 99*20e2869eS猫头猫 height: rpx(240), 100*20e2869eS猫头猫 flexDirection: 'row', 101*20e2869eS猫头猫 alignItems: 'center', 102*20e2869eS猫头猫 }, 103*20e2869eS猫头猫 info: { 104*20e2869eS猫头猫 marginLeft: rpx(24), 105*20e2869eS猫头猫 justifyContent: 'space-around', 106*20e2869eS猫头猫 height: rpx(144), 107*20e2869eS猫头猫 }, 108*20e2869eS猫头猫 title: { 109*20e2869eS猫头猫 flexDirection: 'row', 110*20e2869eS猫头猫 alignItems: 'center', 111*20e2869eS猫头猫 }, 112*20e2869eS猫头猫 titleText: { 113*20e2869eS猫头猫 marginRight: rpx(18), 114*20e2869eS猫头猫 maxWidth: rpx(400), 115*20e2869eS猫头猫 }, 116*20e2869eS猫头猫 description: { 117*20e2869eS猫头猫 marginTop: rpx(24), 118*20e2869eS猫头猫 width: rpx(750), 119*20e2869eS猫头猫 paddingHorizontal: rpx(24), 120be474dd8S猫头猫 }, 121be474dd8S猫头猫}); 122