From 98ec9e0d77ebce18c69282e4c9a177b5c50c4792 Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Thu, 11 Mar 2021 14:57:51 +0500 Subject: [PATCH] resizing image component onLoad --- src/components/postCard/view/postCardView.js | 58 ++++---------------- 1 file changed, 10 insertions(+), 48 deletions(-) diff --git a/src/components/postCard/view/postCardView.js b/src/components/postCard/view/postCardView.js index a5baae94b..f69c02f76 100644 --- a/src/components/postCard/view/postCardView.js +++ b/src/components/postCard/view/postCardView.js @@ -38,11 +38,8 @@ const PostCardView = ({ intl, activeVotes, }) => { - // const [rebloggedBy, setRebloggedBy] = useState(get(content, 'reblogged_by[0]', null)); const [activeVotesCount, setActiveVotesCount] = useState(activeVotes.length || 0); - // const [images, setImages] = useState({}); - // const [calcImgHeight, setCalcImgHeight] = useState(300); - const calcImgHeight = 300; + const [calcImgHeight, setCalcImgHeight] = useState(300); // Component Functions @@ -70,47 +67,6 @@ const PostCardView = ({ setActiveVotesCount(activeVotesCount + 1); }; - // useEffect(() => { - // if (content) { - // const _rebloggedBy = get(content, 'reblogged_by[0]', null); - // setRebloggedBy(_rebloggedBy); - - // if (content.thumbnail) { - // if (isNsfwPost && content.nsfw) { - // setImages({ image: NSFW_IMAGE, thumbnail: NSFW_IMAGE }); - // } - // console.log(content) - // let ratio = 10 / 7; - // ImageSize.getSize(content.thumbnail) - // .then((size) => { - // ratio = size.height / size.width; - // setCalcImgHeight(Math.floor(ratio * (dim.width - 18))); - // }) - // .catch((er) => { - // setCalcImgHeight(Math.floor(ratio * (dim.width - 18))); - // bugsnag.notify(er, (report) => { - // report.metadata = { - // content, - // }; - // }); - // }); - // setImages({ image: content.image, thumbnail: content.thumbnail }); - // } - // else { - // setImages({ image: DEFAULT_IMAGE, thumbnail: DEFAULT_IMAGE }); - // } - - // if (activeVotes) { - // setActiveVot(get(content, 'active_votes')); - // } - // } - // return () => { - // setImages({ image: DEFAULT_IMAGE, thumbnail: DEFAULT_IMAGE }); - // setCalcImgHeight(300); - // setActiveVot([]); - // }; - // }, []); - const rebloggedBy = get(content, 'reblogged_by[0]', null); var images = { image: DEFAULT_IMAGE, thumbnail: DEFAULT_IMAGE }; if (content.thumbnail) { @@ -146,12 +102,18 @@ const PostCardView = ({ {!isHideImage && ( { + setCalcImgHeight((evt.nativeEvent.height / evt.nativeEvent.width) * dim.width - 18); + }} /> )}