import { FileType } from "@openchat/types" import { useRef } from "react" import {…
- User
import { FileType } from "@openchat/types" import { useRef } from "react" import { Image, LayoutAnimation, TouchableOpacity, View } from "react-native" import { FlatList } from "react-native-gesture-handler" import Video, { VideoRef } from "react-native-video" import { AppColors } from "../../../app/app.colors" import { Icon } from "../../../ui-components/icon/icon.component" import { StyledText } from "../../../ui-components/styled-text/styled-text" import { useStyles } from "./message-attachment-uploaded-files-preview.style"
export const MessageAttachmentUploadedFilesPreview = ({ files, onFileRemove, screen, isEnabled = false, }: { files: FileType[] onFileRemove: (fileId: string) => void screen?: string isEnabled?: boolean }) => { // ------------------------------------------------------------------------------------ // variables // ------------------------------------------------------------------------------------
const styles = useStyles() const videoRef = useRef(null) const flatListRef = useRef<FlatList>(null) const layoutAnimConfig = { duration: 300, update: { type: LayoutAnimation.Types.easeInEaseOut, }, delete: { duration: 100, type: LayoutAnimation.Types.easeInEaseOut, property: LayoutAnimation.Properties.opacity, }, }
// ------------------------------------------------------------------------------------ // functions // ------------------------------------------------------------------------------------ function formatSizeUnits(bytes: number) { let size if (bytes >= 1073741824) { size = (bytes / 1073741824).toFixed(2) + " GB" } else if (bytes >= 1048576) { size = (bytes / 1048576).toFixed(2) + " MB" } else if (bytes >= 1024) { size = (bytes / 1024).toFixed(2) + " KB" } else if (bytes > 1) { size = bytes + " bytes" } else if (bytes == 1) { size = bytes + " byte" } else { size = "0 byte" } return size }
// ------------------------------------------------------------------------------------ return ( <> <FlatList showsHorizontalScrollIndicator={false} ref={flatListRef} contentContainerStyle={[ styles.scrollWrapper, { gap: screen === "MessageBoardCardInfo" ? 5 : 10 }, ]} horizontal={true} scrollEnabled={isEnabled ? false : true} data={files} keyExtractor={(file) => file.id} renderItem={({ item: file }) => { return ( {file.mimeType.startsWith("image") && ( <Image resizeMode="cover" style={styles.media} source={{ uri: file.data }} /> )} {file.mimeType.startsWith("video") && ( // <Image // resizeMode="cover" // style={styles.media} // source={{ uri: file.data }} // /> <Video // resizeMode="cover" // Can be a URL or a local file. source={{ uri: file.data }} // Store reference ref={videoRef} // Callback when remote video is buffering // onBuffer={onBuffer} // Callback when video cannot be loaded // onError={onError}
code - Assistant