Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web/mobile): render project images in nested markdown file previews and harden markdown images #7857

Closedflamboh(GitHub profile, opens in a new tab)wants to merge 13 commits intomain fromrefs/pull/7857/headopened View on GitHub

Showing 13 changed files with 163 additions and 0 deletions (loading 12).

x
0 of 13 viewed, 13 left
163 additions and 0 deletionsapps/mobile/src/components/markdownImages.tsxAdded
View file
@@ -0,0 +1,163 @@
+import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
+import { useEffect, useRef, useState } from "react";
+import { ActivityIndicator, Image, StyleSheet, View, type ViewStyle } from "react-native";
+import { TouchableOpacity } from "react-native-gesture-handler";
+​
+import { useThemeColor } from "../lib/useThemeColor";
+import { useAssetUrlState } from "../state/assets";
+import {
+ MARKDOWN_IMAGE_MAX_WIDTH,
+ resolveMarkdownImageDisplaySize,
+} from "../features/threads/markdownImageSize";
+import { AppText as Text } from "./AppText";
+​
+export function ThreadMarkdownImageView(props: {
+ readonly uri: string | null;
+ readonly sourceKey: string;
+ readonly unavailable: boolean;
+ readonly alt: string | null;
+ readonly onPressImage?: ((uri: string) => void) | undefined;
+}) {
+ const codeBackground = useThemeColor("--color-md-code-bg");
+ const [availableWidth, setAvailableWidth] = useState(0);
+ const [sourceSize, setSourceSize] = useState<{ width: number; height: number } | null>(null);
+ const [failedUri, setFailedUri] = useState<string | null>(null);
+ const activeUriRef = useRef(props.uri);
+ activeUriRef.current = props.uri;
+​
+ useEffect(() => {
+ setSourceSize(null);
+ }, [props.sourceKey]);