1*19dc08ecS猫头猫import React from 'react'; 2*19dc08ecS猫头猫import {StyleSheet, View} from 'react-native'; 3*19dc08ecS猫头猫import rpx from '@/utils/rpx'; 4*19dc08ecS猫头猫import {List} from 'react-native-paper'; 5*19dc08ecS猫头猫import Tag from './tag'; 6*19dc08ecS猫头猫import ThemeText from './themeText'; 7*19dc08ecS猫头猫import Image from './image'; 8*19dc08ecS猫头猫import IconButton from './iconButton'; 9*19dc08ecS猫头猫 10*19dc08ecS猫头猫interface ILeftProps { 11*19dc08ecS猫头猫 /** 序号 */ 12*19dc08ecS猫头猫 index?: number | string; 13*19dc08ecS猫头猫 /** 封面图 */ 14*19dc08ecS猫头猫 artwork?: string; 15*19dc08ecS猫头猫 /** 封面图的兜底 */ 16*19dc08ecS猫头猫 fallback?: any; 17*19dc08ecS猫头猫 /** icon */ 18*19dc08ecS猫头猫 icon?: Parameters<typeof IconButton>[0]; 19*19dc08ecS猫头猫 /** 宽度 */ 20*19dc08ecS猫头猫 width?: number; 21*19dc08ecS猫头猫 /** 组件 */ 22*19dc08ecS猫头猫 component?: () => JSX.Element; 23*19dc08ecS猫头猫} 24*19dc08ecS猫头猫 25*19dc08ecS猫头猫function Left(props?: ILeftProps) { 26*19dc08ecS猫头猫 const { 27*19dc08ecS猫头猫 index, 28*19dc08ecS猫头猫 artwork, 29*19dc08ecS猫头猫 fallback, 30*19dc08ecS猫头猫 icon, 31*19dc08ecS猫头猫 width = rpx(100), 32*19dc08ecS猫头猫 component: Component, 33*19dc08ecS猫头猫 } = props ?? {}; 34*19dc08ecS猫头猫 35*19dc08ecS猫头猫 return props && Object.keys(props).length ? ( 36*19dc08ecS猫头猫 Component ? ( 37*19dc08ecS猫头猫 <Component></Component> 38*19dc08ecS猫头猫 ) : ( 39*19dc08ecS猫头猫 <View style={[leftStyle.artworkWrapper, {width}]}> 40*19dc08ecS猫头猫 {index !== undefined ? ( 41*19dc08ecS猫头猫 <ThemeText fontColor="secondary" style={{fontStyle: 'italic'}}> 42*19dc08ecS猫头猫 {index} 43*19dc08ecS猫头猫 </ThemeText> 44*19dc08ecS猫头猫 ) : icon !== undefined ? ( 45*19dc08ecS猫头猫 <IconButton {...icon}></IconButton> 46*19dc08ecS猫头猫 ) : ( 47*19dc08ecS猫头猫 <Image 48*19dc08ecS猫头猫 style={leftStyle.artwork} 49*19dc08ecS猫头猫 uri={artwork} 50*19dc08ecS猫头猫 fallback={fallback}></Image> 51*19dc08ecS猫头猫 )} 52*19dc08ecS猫头猫 </View> 53*19dc08ecS猫头猫 ) 54*19dc08ecS猫头猫 ) : ( 55*19dc08ecS猫头猫 <></> 56*19dc08ecS猫头猫 ); 57*19dc08ecS猫头猫} 58*19dc08ecS猫头猫 59*19dc08ecS猫头猫const leftStyle = StyleSheet.create({ 60*19dc08ecS猫头猫 artworkWrapper: { 61*19dc08ecS猫头猫 justifyContent: 'center', 62*19dc08ecS猫头猫 alignItems: 'center', 63*19dc08ecS猫头猫 }, 64*19dc08ecS猫头猫 artwork: { 65*19dc08ecS猫头猫 width: rpx(76), 66*19dc08ecS猫头猫 height: rpx(76), 67*19dc08ecS猫头猫 borderRadius: rpx(16), 68*19dc08ecS猫头猫 }, 69*19dc08ecS猫头猫}); 70*19dc08ecS猫头猫 71*19dc08ecS猫头猫/** 歌单item */ 72*19dc08ecS猫头猫interface IListItemProps { 73*19dc08ecS猫头猫 /** 标题 */ 74*19dc08ecS猫头猫 title: string; 75*19dc08ecS猫头猫 /** 描述 */ 76*19dc08ecS猫头猫 desc?: string | JSX.Element; 77*19dc08ecS猫头猫 /** 标签 */ 78*19dc08ecS猫头猫 tag?: string; 79*19dc08ecS猫头猫 left?: ILeftProps; 80*19dc08ecS猫头猫 /** 右侧按钮 */ 81*19dc08ecS猫头猫 right?: () => JSX.Element; 82*19dc08ecS猫头猫 itemPaddingHorizontal?: number; 83*19dc08ecS猫头猫 itemHeight?: number; 84*19dc08ecS猫头猫 onPress?: () => void; 85*19dc08ecS猫头猫} 86*19dc08ecS猫头猫 87*19dc08ecS猫头猫export default function ListItem(props: IListItemProps) { 88*19dc08ecS猫头猫 const { 89*19dc08ecS猫头猫 title, 90*19dc08ecS猫头猫 desc, 91*19dc08ecS猫头猫 tag, 92*19dc08ecS猫头猫 right, 93*19dc08ecS猫头猫 itemHeight, 94*19dc08ecS猫头猫 onPress, 95*19dc08ecS猫头猫 left, 96*19dc08ecS猫头猫 itemPaddingHorizontal = rpx(24), 97*19dc08ecS猫头猫 } = props; 98*19dc08ecS猫头猫 return ( 99*19dc08ecS猫头猫 <List.Item 100*19dc08ecS猫头猫 left={() => <Left {...(left ?? {})}></Left>} 101*19dc08ecS猫头猫 style={[ 102*19dc08ecS猫头猫 style.wrapper, 103*19dc08ecS猫头猫 { 104*19dc08ecS猫头猫 paddingHorizontal: itemPaddingHorizontal, 105*19dc08ecS猫头猫 height: itemHeight ?? rpx(120), 106*19dc08ecS猫头猫 paddingVertical: 0, 107*19dc08ecS猫头猫 }, 108*19dc08ecS猫头猫 ]} 109*19dc08ecS猫头猫 title={() => ( 110*19dc08ecS猫头猫 <View 111*19dc08ecS猫头猫 style={{ 112*19dc08ecS猫头猫 alignItems: 'stretch', 113*19dc08ecS猫头猫 justifyContent: 'center', 114*19dc08ecS猫头猫 height: itemHeight ?? rpx(120), 115*19dc08ecS猫头猫 marginRight: right ? rpx(18) : 0, 116*19dc08ecS猫头猫 }}> 117*19dc08ecS猫头猫 <View style={style.titleWrapper}> 118*19dc08ecS猫头猫 <ThemeText numberOfLines={1} style={style.textWidth}> 119*19dc08ecS猫头猫 {title} 120*19dc08ecS猫头猫 </ThemeText> 121*19dc08ecS猫头猫 {tag ? <Tag tagName={tag}></Tag> : <></>} 122*19dc08ecS猫头猫 </View> 123*19dc08ecS猫头猫 {desc ? ( 124*19dc08ecS猫头猫 <ThemeText 125*19dc08ecS猫头猫 fontColor="secondary" 126*19dc08ecS猫头猫 fontSize="description" 127*19dc08ecS猫头猫 numberOfLines={1} 128*19dc08ecS猫头猫 style={[style.textWidth, {marginTop: rpx(18)}]}> 129*19dc08ecS猫头猫 {desc} 130*19dc08ecS猫头猫 </ThemeText> 131*19dc08ecS猫头猫 ) : ( 132*19dc08ecS猫头猫 <></> 133*19dc08ecS猫头猫 )} 134*19dc08ecS猫头猫 </View> 135*19dc08ecS猫头猫 )} 136*19dc08ecS猫头猫 titleStyle={{ 137*19dc08ecS猫头猫 paddingVertical: 0, 138*19dc08ecS猫头猫 marginLeft: 0, 139*19dc08ecS猫头猫 marginVertical: 0, 140*19dc08ecS猫头猫 }} 141*19dc08ecS猫头猫 right={right ? right : () => <></>} 142*19dc08ecS猫头猫 onPress={onPress}></List.Item> 143*19dc08ecS猫头猫 ); 144*19dc08ecS猫头猫} 145*19dc08ecS猫头猫const style = StyleSheet.create({ 146*19dc08ecS猫头猫 wrapper: { 147*19dc08ecS猫头猫 justifyContent: 'center', 148*19dc08ecS猫头猫 }, 149*19dc08ecS猫头猫 titleWrapper: { 150*19dc08ecS猫头猫 flexDirection: 'row', 151*19dc08ecS猫头猫 alignItems: 'center', 152*19dc08ecS猫头猫 justifyContent: 'space-between', 153*19dc08ecS猫头猫 }, 154*19dc08ecS猫头猫 textWidth: { 155*19dc08ecS猫头猫 maxWidth: rpx(460), 156*19dc08ecS猫头猫 }, 157*19dc08ecS猫头猫 artworkWrapper: { 158*19dc08ecS猫头猫 width: rpx(76), 159*19dc08ecS猫头猫 justifyContent: 'center', 160*19dc08ecS猫头猫 alignItems: 'center', 161*19dc08ecS猫头猫 marginRight: rpx(12), 162*19dc08ecS猫头猫 }, 163*19dc08ecS猫头猫 artwork: { 164*19dc08ecS猫头猫 width: rpx(76), 165*19dc08ecS猫头猫 height: rpx(76), 166*19dc08ecS猫头猫 borderRadius: rpx(16), 167*19dc08ecS猫头猫 }, 168*19dc08ecS猫头猫}); 169