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

PostDetailsScreen.jsx 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import React, { useContext, useEffect, useState } from "react";
  2. import { View, Text, Image, StyleSheet } from "react-native";
  3. import { AuthContext } from "../context/AuthContext";
  4. import { singlePostApi } from "../service/post";
  5. import { globalStyles } from "../styles/global";
  6. import { windowWidth } from "../utils/Dimensions";
  7. const PostDetailsScreen = ({ navigation, route }) => {
  8. const { userInfo } = useContext(AuthContext);
  9. const [post, setPost] = useState({});
  10. const fetchPost = async () => {
  11. if (userInfo.jwt && route.params.id) {
  12. singlePostApi(userInfo.jwt, route.params?.id)
  13. .then((res) => setPost(res.data))
  14. .catch((e) => console.log(e));
  15. }
  16. };
  17. useEffect(() => {
  18. fetchPost();
  19. }, []);
  20. return (
  21. <View style={{ flex: 1 }}>
  22. <Image
  23. style={styles.image}
  24. source={{
  25. uri: `http://localhost:1337${post?.attributes?.profileImage.data.attributes.url}`,
  26. }}
  27. />
  28. <Text style={[globalStyles.boldText, styles.title]}>
  29. {post?.attributes?.title}
  30. </Text>
  31. <Text style={[globalStyles.regularText ,styles.description]}>{post?.attributes?.description}</Text>
  32. </View>
  33. );
  34. };
  35. const styles = StyleSheet.create({
  36. image: {
  37. width: windowWidth,
  38. height: 300,
  39. },
  40. title: {
  41. marginTop: 20,
  42. textAlign: "center",
  43. },
  44. description: {
  45. marginHorizontal: 20
  46. }
  47. });
  48. export default PostDetailsScreen;