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

PostDetailsScreen.jsx 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import React, { useEffect, useState } from "react";
  2. import { Text, Image, StyleSheet } from "react-native";
  3. import { getRequest } from "@request/index";
  4. import { globalStyles } from "@styles/global";
  5. import { windowWidth } from "@utils/Dimensions";
  6. import Layout from "@components/Layout/Layout";
  7. import { useTheme } from "@styles";
  8. const PostDetailsScreen = ({ navigation, route }) => {
  9. const [post, setPost] = useState({});
  10. const { colors } = useTheme();
  11. const fetchPost = async () => {
  12. const { data } = await getRequest(
  13. `api/posts/${route.params.id}?populate=*`
  14. );
  15. if (data) {
  16. setPost(data.data);
  17. }
  18. };
  19. useEffect(() => {
  20. fetchPost();
  21. }, []);
  22. return (
  23. <Layout>
  24. <Image
  25. style={styles.image}
  26. source={{
  27. uri: `https://strapi.dilig.net${post?.attributes?.profileImage.data.attributes.url}`,
  28. }}
  29. />
  30. <Text
  31. style={[
  32. globalStyles.boldText,
  33. styles.title,
  34. { color: colors.textPrimary },
  35. ]}
  36. >
  37. {post?.attributes?.title}
  38. </Text>
  39. <Text
  40. style={[
  41. globalStyles.regularText,
  42. styles.description,
  43. { color: colors.textPrimary },
  44. ]}
  45. >
  46. {post?.attributes?.description}
  47. </Text>
  48. </Layout>
  49. );
  50. };
  51. const styles = StyleSheet.create({
  52. image: {
  53. width: windowWidth,
  54. height: 300,
  55. },
  56. title: {
  57. marginTop: 20,
  58. textAlign: "center",
  59. },
  60. description: {
  61. marginHorizontal: 20,
  62. },
  63. });
  64. export default PostDetailsScreen;