diff options
author | Shravya Ramesh <shravs1208@gmail.com> | 2021-06-22 12:22:18 -0700 |
---|---|---|
committer | Shravya Ramesh <shravs1208@gmail.com> | 2021-06-22 12:22:18 -0700 |
commit | 05f77ce887b5e8886451186e3ddba87bc108dc5e (patch) | |
tree | 4bd4ce62449836f55735dd46189a8c965785b39b /src/components/comments | |
parent | 543bc0eb5fb39bdc69145da3a75c0c683e2f30d2 (diff) |
Add comments for new cropper
Diffstat (limited to 'src/components/comments')
-rw-r--r-- | src/components/comments/ZoomInCropper.tsx | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/components/comments/ZoomInCropper.tsx b/src/components/comments/ZoomInCropper.tsx index 25301e6a..94e772b6 100644 --- a/src/components/comments/ZoomInCropper.tsx +++ b/src/components/comments/ZoomInCropper.tsx @@ -1,6 +1,7 @@ import {RouteProp} from '@react-navigation/core'; +import {useFocusEffect} from '@react-navigation/native'; import {StackNavigationProp} from '@react-navigation/stack'; -import {default as React, useEffect, useState} from 'react'; +import {default as React, useCallback, useEffect, useState} from 'react'; import {Image, StyleSheet, TouchableOpacity} from 'react-native'; import {normalize} from 'react-native-elements'; import ImageZoom, {IOnMove} from 'react-native-image-pan-zoom'; @@ -27,17 +28,27 @@ export const ZoomInCropper: React.FC<ZoomInCropperProps> = ({ const {screenType, title, image} = route.params; const [aspectRatio, setAspectRatio] = useState<number>(1); + // Stores the coordinates of the cropped image const [x0, setX0] = useState<number>(); const [x1, setX1] = useState<number>(); const [y0, setY0] = useState<number>(); const [y1, setY1] = useState<number>(); - useEffect(() => { - navigation.dangerouslyGetParent()?.setOptions({ - tabBarVisible: false, - }); - }, []); + // Removes bottom navigation bar on current screen and add it back when navigating away + useFocusEffect( + useCallback(() => { + navigation.dangerouslyGetParent()?.setOptions({ + tabBarVisible: false, + }); + return () => { + navigation.dangerouslyGetParent()?.setOptions({ + tabBarVisible: true, + }); + }; + }, [navigation]), + ); + // Setting original aspect ratio of image useEffect(() => { if (image.sourceURL) { Image.getSize( @@ -50,6 +61,7 @@ export const ZoomInCropper: React.FC<ZoomInCropperProps> = ({ } }, []); + // Crops original image based of (x0, y0) and (x1, y1) coordinates const handleNext = () => { if ( x0 !== undefined && @@ -87,6 +99,9 @@ export const ZoomInCropper: React.FC<ZoomInCropperProps> = ({ } }; + /* Records (x0, y0) and (x1, y1) coordinates used later for cropping, + * based on(x, y) - the center of the image and scale of zoom + */ const onMove = (position: IOnMove) => { Image.getSize( image.path, |