chooseCarForChargingRow.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { View, Text, Image, StyleSheet, Pressable, Dimensions } from 'react-native';
  2. import React from 'react';
  3. import { StarSvg } from './SVG';
  4. import { router } from 'expo-router';
  5. const { width, height } = Dimensions.get('window');
  6. const imageHeight = height < 700 ? 100 : 130;
  7. const imageWidth = width < 400 ? 120 : 146;
  8. const carHeight = height < 700 ? 48 : 72;
  9. const carWidth = width < 400 ? 100 : 140;
  10. const truncateText = (text, maxLength) => {
  11. if (text.length <= maxLength) return text;
  12. return text.substr(0, maxLength) + '...';
  13. };
  14. const ChooseCarForChargingRow = ({
  15. image,
  16. VehicleName,
  17. isDefault,
  18. onPress,
  19. isSelected
  20. }: {
  21. isSelected?: boolean;
  22. image?: any;
  23. VehicleName: string;
  24. isDefault: boolean;
  25. onPress: () => void;
  26. }) => (
  27. <Pressable onPress={onPress}>
  28. <View
  29. className={`bg-white rounded-lg ${isSelected ? 'border-4 border-[#34657b]' : ''}`}
  30. style={[styles.container, { height: imageHeight, width: imageWidth }]}
  31. >
  32. {isDefault && (
  33. <>
  34. <View style={styles.topLeftTriangle} />
  35. <View className="absolute top-1 left-1">
  36. <StarSvg />
  37. </View>
  38. </>
  39. )}
  40. <View className="items-center justify-center pt-4 space-y-2 ">
  41. <Image source={{ uri: image }} style={{ height: carHeight, width: carWidth }} />
  42. <Text
  43. style={{
  44. fontSize: height < 700 ? 14 : 16,
  45. color: '#222222'
  46. }}
  47. >
  48. {truncateText(VehicleName, 10)}
  49. </Text>
  50. </View>
  51. </View>
  52. </Pressable>
  53. );
  54. export default ChooseCarForChargingRow;
  55. const styles = StyleSheet.create({
  56. container: {
  57. overflow: 'hidden',
  58. borderRadius: 8,
  59. alignItems: 'center',
  60. justifyContent: 'center',
  61. marginRight: 12,
  62. position: 'relative'
  63. },
  64. grayColor: {
  65. color: '#888888'
  66. },
  67. topLeftTriangle: {
  68. width: 0,
  69. height: 0,
  70. borderLeftWidth: 50,
  71. borderBottomWidth: 50,
  72. borderLeftColor: '#02677D',
  73. borderBottomColor: 'transparent',
  74. position: 'absolute',
  75. top: 0,
  76. left: 0
  77. },
  78. text: {
  79. fontWeight: 300,
  80. color: '#000000'
  81. }
  82. });