// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React, {useCallback, useRef, useState} from 'react'; import {Dimensions, StyleSheet, View} from 'react-native'; import File from '@components/files/file'; import {useIsTablet} from '@hooks/device'; import {getViewPortWidth} from '@utils/images'; import TabletOptions from './file_options/tablet_options'; import type {GalleryAction} from '@typings/screens/gallery'; export type XyOffset = {x: number; y: number} | undefined; const styles = StyleSheet.create({ container: { flex: 1, marginHorizontal: 20, }, }); type Props = { canDownloadFiles: boolean; channelName?: string; fileInfo: FileInfo; index: number; numOptions: number; onOptionsPress: (finfo: FileInfo) => void; onPress: (idx: number) => void; publicLinkEnabled: boolean; setAction: (action: GalleryAction) => void; updateFileForGallery: (idx: number, file: FileInfo) => void; } const galleryIdentifier = 'search-files-location'; const FileResult = ({ canDownloadFiles, channelName, fileInfo, index, numOptions, onOptionsPress, onPress, publicLinkEnabled, setAction, updateFileForGallery, }: Props) => { const elementsRef = useRef(null); const isTablet = useIsTablet(); const isReplyPost = false; const [showOptions, setShowOptions] = useState(false); const [openUp, setOpenUp] = useState(false); const [xyOffset, setXYoffset] = useState(undefined); const {height} = Dimensions.get('window'); const handleOptionsPress = useCallback((fInfo: FileInfo) => { elementsRef.current?.measureInWindow((x, y) => { setOpenUp((y > height / 2)); setXYoffset({x, y}); setShowOptions(true); onOptionsPress(fInfo); }); }, []); const handleSetAction = useCallback((action: GalleryAction) => { setAction(action); if (showOptions && action !== 'none') { setShowOptions(false); } }, [setAction, showOptions]); return ( <> {isTablet && showOptions && xyOffset && } ); }; export default FileResult;