Files
discord-decomp/modules/media/native/AttachmentPreview.tsx
T
2026-11-01 12:12:55 +02:00

183 lines
6.3 KiB
TypeScript

// Metro module 9854 (f9855).
import { useMemo, memo } from "react";
import { Image as Image2, View } from "react-native";
import { createStyles } from "../../../design/components/Styles/native/createStyles";
import Module712 from "../../../_bundle/Module712";
import Module9855 from "../../../_bundle/Module9855";
import Module9856 from "../../../_bundle/Module9856";
import Module9857 from "../../../_bundle/Module9857";
import Module9858 from "../../../_bundle/Module9858";
import Module9859 from "../../../_bundle/Module9859";
import Module9860 from "../../../_bundle/Module9860";
import Module9861 from "../../../_bundle/Module9861";
import Module9862 from "../../../_bundle/Module9862";
import Module9863 from "../../../_bundle/Module9863";
import Module9864 from "../../../_bundle/Module9864";
import Module9865 from "../../../_bundle/Module9865";
import Module9866 from "../../../_bundle/Module9866";
import Module9867 from "../../../_bundle/Module9867";
import Module9868 from "../../../_bundle/Module9868";
import { classifyFileName } from "../../../utils/FileUtils";
import { Text } from "../../../design/components/Text/native/Text";
import * as _PlatformUtils from "../../../utils/PlatformUtils";
import { isAndroid } from "../../../utils/PlatformUtils";
import FastImage from "../../../components_native/common/FastImage";
import { ThumbnailImage } from "../../../design/void/native";
import { CirclePlayIcon } from "../../../design/components/Icon/native/redesign/generated/CirclePlayIcon";
import { VideoComponent } from "../../../components_native/common/Video";
let useStyles, c6543_9, FilenameText, DefaultAttachmentPreview, Component;
const AttachmentIcon = function AttachmentIcon(props) {
const fileName = props.fileName;
return <Image2 style={useStyles().attachmentFileIcon} source={useMemo(() => {
let r9 = fileName;
if (fileName == null) {
r9 = "";
}
let r12 = c6543_9[classifyFileName(r9)];
if (r12 == null) {
r12 = Module9866;
}
return r12;
}, [fileName])} />;
};
FilenameText = function FilenameText(props) {
const fileName2 = props.fileName;
const styles = useStyles();
const r5 = /(?:\.([^.]+))?$/;
let r15 = fileName2;
if (r15 == null) {
r15 = "";
}
const r16 = r5.exec(r15);
return <View>
{fileName2 != null && fileName2 !== "" && <Text style={styles.attachmentFileName} ellipsizeMode="middle" lineClamp={1} variant="text-xs/medium" color="mobile-text-heading-primary">{fileName2}</Text>}
<Text style={styles.attachmentFileName} lineClamp={1} variant="text-xs/medium" color="text-muted">
{r16 != null ? r16[1] != null ? r16[1].toUpperCase() : "UNKNOWN" : "UNKNOWN"}
</Text>
</View>;
};
DefaultAttachmentPreview = function DefaultAttachmentPreview(props) {
const { fileName: fileName2, maxFileWidth, borderRadius } = props;
return <View style={[useStyles().fileInfoAttachmentPreviewFile, {
maxWidth: maxFileWidth,
borderRadius
}]}>
<AttachmentIcon fileName={fileName2} />
<FilenameText fileName={fileName2} />
</View>;
};
useStyles = createStyles({
fileInfoAttachmentPreviewFile: {
flexDirection: "row",
alignItems: "center",
overflow: "hidden",
borderRadius: Module712.radii.sm,
height: 75,
padding: 12,
flex: 1,
gap: Module712.space.PX_8
},
attachmentFileIcon: {
height: 32,
width: 24
},
attachmentFileName: {
paddingRight: 4,
paddingLeft: 4,
maxWidth: 136
},
videoIcon: {
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0,
alignItems: "center",
justifyContent: "center"
}
});
c6543_9 = {
archive: Module9855,
acrobat: Module9856,
ae: Module9857,
ai: Module9858,
audio: Module9859,
code: Module9860,
document: Module9861,
image: Module9862,
photoshop: Module9863,
sketch: Module9864,
spreadsheet: Module9865,
unknown: Module9866,
video: Module9867,
webcode: Module9868
};
Component = memo(function({ uri, width, height, borderRadius, style, fileName: fileName2 }) {
let props;
const source = {
uri,
width,
height
};
const r10 = {
width,
height,
borderRadius
};
const r13 = fileName2 != null && fileName2 !== "" && /\.gif$/i.test(fileName2) && (_PlatformUtils.isIOS() && uri.startsWith("ph://") || isAndroid() && uri.startsWith("content://"));
const r34 = {
style: [r10, style, {
overflow: "hidden"
}],
children: null
};
if (r13) {
r34.children = <FastImage style={[r10, style]} source={source} resizeMode="cover" enableAnimation />;
props = r34;
} else {
r34.children = <ThumbnailImage style={[r10, style]} source={source} localImageSource={source} />;
props = r34;
}
return <View {...props} />;
});
export default function AttachmentPreview(props) {
let r44;
const { uri, isImage, isVideo, width = 75, height = 75, maxFileWidth, fileName: fileName2, borderRadius = Module712.radii.sm, showPlayOnVideoPreview = false, defaultPreview = <DefaultAttachmentPreview fileName={fileName2} maxFileWidth={maxFileWidth} borderRadius={borderRadius} /> } = props;
L25: {
const style = props.style;
const styles = useStyles();
if (isImage) {
r44 = <Component uri={uri} width={width} height={height} borderRadius={borderRadius} style={style} fileName={fileName2} />;
} else {
if (!(isVideo && isAndroid()) && !(_PlatformUtils.isIOS() && uri.startsWith("ph://"))) {
r44 = defaultPreview;
if (!isVideo) {
break L25;
}
const isIOS = _PlatformUtils.isIOS();
r44 = defaultPreview;
if (!isIOS) {
break L25;
}
r44 = <View style={style}>
<VideoComponent style={{
height,
width
}} source={{
uri
}} muted paused resizeMode="cover" preventsDisplaySleepDuringVideoPlayback={false} />
</View>;
break L25;
}
r44 = showPlayOnVideoPreview ? <View style={style}>
<Component uri={uri} width={width} height={height} borderRadius={borderRadius} style={style} fileName={fileName2} />
<View style={styles.videoIcon}>
<CirclePlayIcon size="md" color="white" secondaryColor="black" />
</View>
</View> : <Component uri={uri} width={width} height={height} borderRadius={borderRadius} style={style} fileName={fileName2} />;
}
}
return r44;
};
export { AttachmentIcon };