import {RouteProp} from '@react-navigation/core'; import {useNavigation} from '@react-navigation/native'; import React, {useCallback, useEffect, useRef, useState} from 'react'; import { Image, StyleSheet, TouchableOpacity, TouchableWithoutFeedback, View, } from 'react-native'; import {useFocusEffect} from '@react-navigation/native'; import {Button} from 'react-native-elements'; import Video from 'react-native-video'; import {MainStackParams} from 'src/routes'; import BackArrow from '../../assets/icons/back-arrow.svg'; import {CaptionScreenHeader, MomentTags} from '../../components'; import {TagFriendsFooter} from '../../components/moments'; import {TAGG_LIGHT_BLUE_2} from '../../constants'; import {MomentTagType} from '../../types'; import { SCREEN_WIDTH, SCREEN_HEIGHT, HeaderHeight, isIPhoneX, normalize, } from '../../utils'; type TagFriendsScreenRouteProps = RouteProp< MainStackParams, 'TagFriendsScreen' >; interface TagFriendsScreenProps { route: TagFriendsScreenRouteProps; } const TagFriendsScreen: React.FC = ({route}) => { const {media, selectedTags} = route.params; const navigation = useNavigation(); const imageRef = useRef(null); const [tags, setTags] = useState([]); const [imageWidth, setImageWidth] = useState(0); const [imageHeight, setImageHeight] = useState(0); // Calculate boundary (if any) for drag from bottom let bottomBound; if (SCREEN_HEIGHT / 2 - imageHeight / 2 < SCREEN_HEIGHT * 0.15) { if (SCREEN_HEIGHT / 2 - imageHeight / 2 < 0) { bottomBound = SCREEN_HEIGHT * 0.15; } else { bottomBound = SCREEN_HEIGHT * 0.15 - (SCREEN_HEIGHT / 2 - imageHeight / 2); } } else { bottomBound = 0; } /* * Update list of tagged users from route params */ useEffect(() => { setTags(selectedTags ? selectedTags : []); }, [selectedTags]); /* * Hide Tab Bar */ useFocusEffect( useCallback(() => { navigation.dangerouslyGetParent()?.setOptions({ tabBarVisible: false, }); return () => { navigation.dangerouslyGetParent()?.setOptions({ tabBarVisible: true, }); }; }, [navigation]), ); /* * Navigate back to Tag Users Screen, send selected users */ const handleDone = () => { navigation.navigate('CaptionScreen', { ...route.params, selectedTags: tags, }); }; const setMediaDimensions = (width: number, height: number) => { const imageAspectRatio = width / height; const screenRatio = SCREEN_WIDTH / SCREEN_HEIGHT; // aspectRatio: >= 1 [Landscape] [1:1] if (imageAspectRatio >= screenRatio) { setImageWidth(SCREEN_WIDTH); setImageHeight(SCREEN_WIDTH / imageAspectRatio); } // aspectRatio: < 1 [Portrait] if (imageAspectRatio < screenRatio) { setImageHeight(SCREEN_HEIGHT); setImageWidth(SCREEN_HEIGHT * imageAspectRatio); } }; /* * Calculating image width and height with respect to it's enclosing view's dimensions. Only works for images. */ useEffect(() => { if (imageRef && imageRef.current && !media.isVideo) { Image.getSize( media.uri, (w, h) => { setMediaDimensions(w, h); }, (err) => console.log(err), ); } }, []); return ( navigation.navigate('TagSelectionScreen', { selectedTags: tags, }) }> {media.isVideo ? ( ) : ( )} { navigation.goBack(); }} style={styles.backArrow}> {tags.length !== 0 && (