TransCard.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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>
  52. );
  53. }
  54. const styles = StyleSheet.create({
  55. item: {
  56. position: 'relative',
  57. justifyContent: 'center',
  58. alignItems: 'center',
  59. },
  60. super: {
  61. position: 'absolute',
  62. top: 0,
  63. height: '100%',
  64. },
  65. image: {
  66. zIndex: 1,
  67. },
  68. itemBottom: {
  69. position: 'absolute',
  70. bottom: 0,
  71. left: 0,
  72. width: '100%',
  73. height: 40,
  74. zIndex: 10,
  75. },
  76. });