您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ListItem.jsx 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import React from "react";
  2. import { View, Text, Image, TouchableOpacity, StyleSheet } from "react-native";
  3. import { globalStyles } from "@styles/global";
  4. import { windowWidth } from "@utils/Dimensions";
  5. import { useTheme } from "@styles";
  6. import { useTranslation } from "react-i18next";
  7. const ListItem = ({ photo, title, onPress, publishedAt }) => {
  8. const { colors } = useTheme();
  9. const { t } = useTranslation();
  10. const formatDate = (date) => {
  11. const tempDate = new Date(date);
  12. const fDate =
  13. tempDate.getDate() +
  14. "/" +
  15. (tempDate.getMonth() + 1) +
  16. "/" +
  17. tempDate.getFullYear();
  18. return fDate;
  19. };
  20. return (
  21. <View style={styles.cardContainer}>
  22. <View style={styles.imageContainer}>
  23. <Image
  24. style={styles.image}
  25. source={{ uri: `https://strapi.dilig.net${photo.small.url}` }}
  26. />
  27. <View style={{ width: windowWidth - 220 }}>
  28. <Text
  29. style={{
  30. color: colors.textPrimary,
  31. fontFamily: "poppins-regular",
  32. fontSize: 14,
  33. textTransform: "uppercase",
  34. }}
  35. >
  36. {title}
  37. </Text>
  38. <Text
  39. style={{
  40. color: colors.textPrimary,
  41. fontFamily: "poppins-regular",
  42. fontSize: 14,
  43. textTransform: "uppercase",
  44. }}
  45. >
  46. Published At {formatDate(publishedAt)}
  47. </Text>
  48. </View>
  49. </View>
  50. <TouchableOpacity style={globalStyles.button} onPress={onPress}>
  51. <Text style={styles.buttonText}>{t('common.readMore')}</Text>
  52. </TouchableOpacity>
  53. </View>
  54. );
  55. };
  56. const styles = StyleSheet.create({
  57. cardContainer: {
  58. flexDirection: "row",
  59. justifyContent: "space-between",
  60. alignItems: "center",
  61. marginBottom: 20,
  62. },
  63. imageContainer: {
  64. flexDirection: "row",
  65. alignItems: "center",
  66. flex: 1,
  67. },
  68. image: {
  69. width: 55,
  70. height: 55,
  71. borderRadius: 10,
  72. marginRight: 8,
  73. },
  74. buttonText: {
  75. color: "#fff",
  76. textAlign: "center",
  77. fontFamily: "poppins-regular",
  78. fontSize: 14,
  79. },
  80. });
  81. export default ListItem;