TransCard.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import { Image } from 'expo-image';
  2. import React from 'react';
  3. import { StyleSheet, Text, View } from 'react-native';
  4. import { Images } from '@/constants/images';
  5. interface TransCardProps {
  6. item: any;
  7. width?: number;
  8. height?: number;
  9. fill?: number;
  10. imageWidth?: number;
  11. imageHeight?: number;
  12. }
  13. const LEVEL_MAP: any = {
  14. A: { bg: Images.box.detail.levelA, productItem: Images.box.detail.productItemA },
  15. B: { bg: Images.box.detail.levelB, productItem: Images.box.detail.productItemB },
  16. C: { bg: Images.box.detail.levelC, productItem: Images.box.detail.productItemC },
  17. D: { bg: Images.box.detail.levelD, productItem: Images.box.detail.productItemD },
  18. };
  19. export default function TransCard({
  20. item,
  21. width = 67,
  22. height = 90,
  23. fill = 2,
  24. imageWidth = 55,
  25. imageHeight = 70,
  26. }: TransCardProps) {
  27. const itemWidth = width + fill * 2;
  28. const levelConfig = LEVEL_MAP[item.level] || LEVEL_MAP.D;
  29. return (
  30. <View style={[styles.item, { width: itemWidth, height: height }]}>
  31. <Image
  32. source={{ uri: levelConfig.bg }}
  33. style={[styles.super, { width: width /*, left: fill */ }]}
  34. contentFit="fill"
  35. />
  36. {item.isWinner && (
  37. <View style={{position:'absolute', top: 5, left: 5, zIndex: 100, backgroundColor:'red', padding: 2}}>
  38. <Text style={{color:'white', fontSize: 10, fontWeight:'bold'}}>WINNER</Text>
  39. </View>
  40. )}
  41. <Image
  42. source={{ uri: item.cover }}
  43. style={[styles.image, { width: imageWidth, height: imageHeight }]}
  44. contentFit="contain"
  45. />
  46. <Image
  47. source={{ uri: levelConfig.productItem }}
  48. style={styles.itemBottom}
  49. contentFit="fill"
  50. />
  51. <View style={styles.nameContainer}>
  52. <Text style={styles.nameText} numberOfLines={1}>
  53. {item.name}
  54. </Text>
  55. </View>
  56. </View>
  57. );
  58. }
  59. const styles = StyleSheet.create({
  60. item: {
  61. position: 'relative',
  62. justifyContent: 'center',
  63. alignItems: 'center',
  64. },
  65. super: {
  66. position: 'absolute',
  67. top: 0,
  68. height: '100%',
  69. },
  70. image: {
  71. zIndex: 1,
  72. },
  73. itemBottom: {
  74. position: 'absolute',
  75. bottom: 0,
  76. left: 0,
  77. width: '100%',
  78. height: 20,
  79. zIndex: 10,
  80. },
  81. nameContainer: {
  82. position: 'absolute',
  83. top: 8, // Moved to top as requested
  84. left: 0,
  85. width: '100%',
  86. alignItems: 'center',
  87. paddingHorizontal: 2,
  88. zIndex: 20,
  89. },
  90. nameText: {
  91. color: '#fff',
  92. fontSize: 8,
  93. textAlign: 'center',
  94. textShadowColor: 'rgba(0,0,0,0.8)',
  95. textShadowOffset: { width: 1, height: 1 },
  96. textShadowRadius: 1,
  97. fontWeight: 'bold',
  98. }
  99. });