chooseCarForChargingRow.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. <Image source={require('../../assets/car.png')} style={{ height: carHeight, width: carWidth }} />
  43. <Text
  44. style={{
  45. fontSize: height < 700 ? 14 : 16,
  46. color: '#222222'
  47. }}
  48. >
  49. {truncateText(VehicleName, 10)}
  50. </Text>
  51. </View>
  52. </View>
  53. </Pressable>
  54. );
  55. export default ChooseCarForChargingRow;
  56. const styles = StyleSheet.create({
  57. container: {
  58. overflow: 'hidden',
  59. borderRadius: 8,
  60. alignItems: 'center',
  61. justifyContent: 'center',
  62. marginRight: 12,
  63. position: 'relative'
  64. },
  65. grayColor: {
  66. color: '#888888'
  67. },
  68. topLeftTriangle: {
  69. width: 0,
  70. height: 0,
  71. borderLeftWidth: 50,
  72. borderBottomWidth: 50,
  73. borderLeftColor: '#02677D',
  74. borderBottomColor: 'transparent',
  75. position: 'absolute',
  76. top: 0,
  77. left: 0
  78. },
  79. text: {
  80. fontWeight: 300,
  81. color: '#000000'
  82. }
  83. });