From b3d4c64c8a2d742455b5f96cc9e4b7b8973e10e9 Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Wed, 23 Jun 2021 07:02:44 -0700 Subject: Fix moment tags crash issue on tag friends screen --- src/screens/moments/TagFriendsScreen.tsx | 46 ++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/screens/moments/TagFriendsScreen.tsx b/src/screens/moments/TagFriendsScreen.tsx index 6956dc0d..15926b5a 100644 --- a/src/screens/moments/TagFriendsScreen.tsx +++ b/src/screens/moments/TagFriendsScreen.tsx @@ -34,6 +34,8 @@ const TagFriendsScreen: React.FC = ({route}) => { const navigation = useNavigation(); const imageRef = useRef(null); const [tags, setTags] = useState([]); + const [imageWidth, setImageWidth] = useState(0); + const [imageHeight, setImageHeight] = useState(0); /* * Update list of tagged users from route params @@ -52,6 +54,32 @@ const TagFriendsScreen: React.FC = ({route}) => { }); }; + /* + * Calculating image width and height with respect to it's enclosing view's dimensions + */ + useEffect(() => { + if (imageRef && imageRef.current) { + Image.getSize( + imagePath, + (w, h) => { + const imageAspectRatio = w / h; + + // aspectRatio: >= 1 [Landscape] [1:1] + if (imageAspectRatio >= 1) { + setImageWidth(SCREEN_WIDTH); + setImageHeight(SCREEN_WIDTH / imageAspectRatio); + } + // aspectRatio: < 1 [Portrait] + else if (imageAspectRatio < 1) { + setImageHeight(SCREEN_WIDTH); + setImageWidth(SCREEN_WIDTH * imageAspectRatio); + } + }, + (err) => console.log(err), + ); + } + }, []); + return ( @@ -84,9 +112,16 @@ const TagFriendsScreen: React.FC = ({route}) => { }> {tags.length !== 0 && ( @@ -131,12 +166,7 @@ const styles = StyleSheet.create({ header: { marginVertical: 20, }, - image: { - position: 'relative', - width: SCREEN_WIDTH, - aspectRatio: 1, - marginBottom: '3%', - }, + image: {zIndex: 0, justifyContent: 'center', alignSelf: 'center'}, text: { position: 'relative', backgroundColor: 'white', -- cgit v1.2.3-70-g09d2