From 09af7a87a3c91182bb9402b134db2cf547cde9b3 Mon Sep 17 00:00:00 2001 From: Joe Davis Date: Mon, 23 Nov 2026 19:28:34 -0500 Subject: [PATCH 1/2] fix(mobile): swiping through PR images no longer shows black screens or raw UUIDs --- .../ios/T3NativeControlsModule.swift | 4 + .../ios/T3NativeImageViewer.swift | 38 ++- .../ios/T3NativePresentation.swift | 54 +++- .../ui/NativePresentation.android.tsx | 6 +- .../src/components/ui/NativePresentation.tsx | 1 + .../pull-requests/PullRequestDescription.tsx | 49 +++- .../pull-requests/PullRequestMarkdown.tsx | 149 +++++++--- .../pull-requests/PullRequestMedia.test.tsx | 276 ++++++++++++++++++ .../pull-requests/PullRequestMedia.tsx | 67 +++-- .../pullRequestDescriptionContent.test.ts | 68 ++++- .../pullRequestDescriptionContent.ts | 108 +++++-- .../pullRequestMediaSource.test.ts | 121 +++++++- .../pull-requests/pullRequestMediaSource.ts | 89 +++++- .../threads/ThreadMarkdownImage.test.tsx | 55 +++- .../features/threads/ThreadMarkdownImage.tsx | 32 +- .../mobile/src/lib/filePreviewGallery.test.ts | 51 +++- apps/mobile/src/lib/filePreviewGallery.ts | 39 ++- apps/mobile/src/lib/markdownHtml.test.ts | 17 +- apps/mobile/src/lib/markdownImageSources.ts | 48 ++- apps/mobile/vite.config.ts | 1 + 20 files changed, 1128 insertions(+), 145 deletions(-) create mode 100644 apps/mobile/src/features/pull-requests/PullRequestMedia.test.tsx diff --git a/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift b/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift index c8ec3886974a9..0571d2c604f1c 100644 --- a/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift +++ b/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift @@ -134,6 +134,10 @@ public final class T3NativeControlsModule: Module { view.sources = self.presentationSources view.identifier = identifier } + Prop("fallbackIdentifier") { (view: T3PresentationSourceView, identifier: String?) in + view.sources = self.presentationSources + view.fallbackIdentifier = identifier ?? "" + } } View(T3FrostedCutoutView.self) { diff --git a/apps/mobile/modules/t3-native-controls/ios/T3NativeImageViewer.swift b/apps/mobile/modules/t3-native-controls/ios/T3NativeImageViewer.swift index 382e92875f303..259d68c43531d 100644 --- a/apps/mobile/modules/t3-native-controls/ios/T3NativeImageViewer.swift +++ b/apps/mobile/modules/t3-native-controls/ios/T3NativeImageViewer.swift @@ -126,8 +126,10 @@ final class T3NativeImageViewer: NSObject { private func decode(_ index: Int) { guard !finished, let file = file(at: index), !decoded.contains(index), decodes[index] == nil else { return } - let source = sourceView(index) - let previous = decodeQueue + // ImageIO reads SVG poorly or not at all; the thumbnail is vector, so redraw it at full-screen size + // without blocking the serial raster decode queue while waiting for reveal. + let isSVG = file.pathExtension.lowercased() == "svg" + let previous = isSVG ? nil : decodeQueue let task = Task { @MainActor [self] in await previous?.value var settled = false @@ -137,8 +139,6 @@ final class T3NativeImageViewer: NSObject { if !settled, !finished, isNearCurrent(index), !decoded.contains(index) { decode(index) } } guard !finished, !Task.isCancelled, isNearCurrent(index), files[index] == file else { return } - // ImageIO reads SVG poorly or not at all; the thumbnail is vector, so redraw it at full-screen size. - let isSVG = file.pathExtension.lowercased() == "svg" let image = isSVG ? nil : await Task.detached(priority: .userInitiated) { Self.decode(file) }.value guard !finished, !Task.isCancelled, isNearCurrent(index), files[index] == file else { return } if isSVG { @@ -147,7 +147,7 @@ final class T3NativeImageViewer: NSObject { guard !finished, !Task.isCancelled, isNearCurrent(index), files[index] == file else { return } } settled = true - if let image = image ?? (isSVG ? source.flatMap(Self.render(_:)) : nil) { + if let image = image ?? (isSVG ? sourceView(index).flatMap(Self.render(_:)) : nil) { decoded.insert(index) controller?.setImage(image, at: index, full: true) } else { @@ -161,7 +161,7 @@ final class T3NativeImageViewer: NSObject { } } decodes[index] = task - decodeQueue = task + if !isSVG { decodeQueue = task } } private func finish() { @@ -184,9 +184,8 @@ final class T3NativeImageViewer: NSObject { try? FileManager.default.removeItem(at: file.deletingLastPathComponent()) } - /// The decoded image a thumbnail already shows, uncropped, or a snapshot of a view that draws one. - /// The largest image view wins, so an overlaid icon is never mistaken for the picture. - private static func thumbnail(of view: UIView) -> UIImage? { + /// The largest decoded image already shown in `view`, uncropped at its native aspect ratio. + private static func decodedImage(in view: UIView) -> UIImage? { var queue = [view] var best: (image: UIImage, area: CGFloat)? while let candidate = queue.popLast() { @@ -196,10 +195,19 @@ final class T3NativeImageViewer: NSObject { if area > best?.area ?? 0 { best = (image, area) } } if let best, best.area >= view.bounds.width * view.bounds.height / 2 { return best.image } + return nil + } + + /// The decoded image a thumbnail already shows, uncropped, or a snapshot of a view that draws one. + /// The largest image view wins, so an overlaid icon is never mistaken for the picture. + private static func thumbnail(of view: UIView) -> UIImage? { + if let image = decodedImage(in: view) { return image } return snapshot(view, scale: view.window?.screen.scale ?? 2) } private static func render(_ view: UIView) -> UIImage? { + // Strip cards decode SVGs into an image view inside a fixed landscape box; keep the image's own aspect ratio. + if let image = decodedImage(in: view) { return image } let screen = view.window?.screen.bounds.size ?? CGSize(width: 1024, height: 1024) let fit = min(screen.width / max(view.bounds.width, 1), screen.height / max(view.bounds.height, 1)) // The thumbnail was shown again after the open transition, in a frame not yet on screen. @@ -211,9 +219,11 @@ final class T3NativeImageViewer: NSObject { let format = UIGraphicsImageRendererFormat() format.scale = scale format.opaque = false - return UIGraphicsImageRenderer(bounds: view.bounds, format: format).image { _ in - view.drawHierarchy(in: view.bounds, afterScreenUpdates: afterScreenUpdates) + var drew = false + let image = UIGraphicsImageRenderer(bounds: view.bounds, format: format).image { _ in + drew = view.drawHierarchy(in: view.bounds, afterScreenUpdates: afterScreenUpdates) } + return drew ? image : nil } /// Decodes off the main thread at no more than zooming needs, and keeps GIFs animated. @@ -644,9 +654,9 @@ final class T3ImageViewerController: UIViewController, UIScrollViewDelegate, UIG private var reduceMotion: Bool { UIAccessibility.isReduceMotionEnabled } private func visibleSource(_ index: Int) -> UIView? { - guard !reduceMotion, let source = sourceView(index), source.window === view.window, !source.isHidden else { return nil } - let frame = source.convert(source.bounds, to: view) - guard frame.width > 1, frame.height > 1, view.bounds.intersects(frame) else { return nil } + guard !reduceMotion, let source = sourceView(index), source.window === view.window, + isVisiblePresentationTarget(source, in: view) + else { return nil } return source } diff --git a/apps/mobile/modules/t3-native-controls/ios/T3NativePresentation.swift b/apps/mobile/modules/t3-native-controls/ios/T3NativePresentation.swift index 3b43334b1262d..8d62177f18992 100644 --- a/apps/mobile/modules/t3-native-controls/ios/T3NativePresentation.swift +++ b/apps/mobile/modules/t3-native-controls/ios/T3NativePresentation.swift @@ -1,6 +1,34 @@ import ExpoModulesCore import UIKit +/// Visible portion of `view` inside `container`, clipped by every `clipsToBounds` ancestor. +func clippedVisibleRect(of view: UIView, in container: UIView) -> CGRect { + guard let window = view.window, !view.isHidden, view.alpha > 0.01 else { return .null } + var rect = view.bounds + guard !rect.isEmpty else { return .null } + var current: UIView = view + while let parent = current.superview { + if parent.isHidden || parent.alpha <= 0.01 { return .null } + rect = current.convert(rect, to: parent) + if parent.clipsToBounds { + rect = rect.intersection(parent.bounds) + if rect.isNull || rect.isEmpty { return .null } + } + current = parent + if parent === window { break } + } + let inContainer = current.convert(rect, to: container) + return inContainer.intersection(container.bounds) +} + +/// Whether enough of `view` is visible inside `container` to serve as a zoom transition target. +func isVisiblePresentationTarget(_ view: UIView, in container: UIView) -> Bool { + let fullArea = view.bounds.width * view.bounds.height + guard fullArea > 1 else { return false } + let visible = clippedVisibleRect(of: view, in: container) + return visible.width > 1 && visible.height > 1 && visible.width * visible.height >= fullArea * 0.25 +} + final class T3PresentationSources { private class Entry { weak var view: UIView? @@ -23,11 +51,12 @@ final class T3PresentationSources { func view(for identifier: String) -> UIView? { let views = (entries[identifier] ?? []).compactMap(\.view) - // Prefer an on-screen copy, the latest first; use the child bounds, not the wrapper's stretched ones. + // Prefer a visible copy, the latest first; use the child bounds, not the wrapper's stretched ones. let source = views.last(where: { view in - guard let window = view.window else { return false } - return window.bounds.intersects(view.convert(view.bounds, to: window)) - }) ?? views.last + guard let window = view.window, let target = view.subviews.first else { return false } + return isVisiblePresentationTarget(target, in: window) + }) ?? views.last(where: { $0.window != nil && !$0.subviews.isEmpty }) + ?? views.last(where: { !$0.subviews.isEmpty }) return source?.subviews.first } } @@ -35,14 +64,23 @@ final class T3PresentationSources { final class T3PresentationSourceView: ExpoView { weak var sources: T3PresentationSources? var identifier = "" { - didSet { - sources?.remove(self, identifier: oldValue) - if !identifier.isEmpty { sources?.register(self, identifier: identifier) } + didSet { updateRegistration(old: oldValue, new: identifier) } + } + var fallbackIdentifier = "" { + didSet { updateRegistration(old: oldValue, new: fallbackIdentifier) } + } + + private func updateRegistration(old: String, new: String) { + guard old != new else { return } + if !old.isEmpty, old != identifier, old != fallbackIdentifier { + sources?.remove(self, identifier: old) } + if !new.isEmpty { sources?.register(self, identifier: new) } } deinit { - sources?.remove(self, identifier: identifier) + if !identifier.isEmpty { sources?.remove(self, identifier: identifier) } + if !fallbackIdentifier.isEmpty { sources?.remove(self, identifier: fallbackIdentifier) } } } diff --git a/apps/mobile/src/components/ui/NativePresentation.android.tsx b/apps/mobile/src/components/ui/NativePresentation.android.tsx index e342c6decc77a..8194c59e8dfd3 100644 --- a/apps/mobile/src/components/ui/NativePresentation.android.tsx +++ b/apps/mobile/src/components/ui/NativePresentation.android.tsx @@ -2,6 +2,10 @@ import { View } from "react-native"; import type { PresentationSourceProps } from "./NativePresentation"; -export function PresentationSource({ identifier: _identifier, ...props }: PresentationSourceProps) { +export function PresentationSource({ + identifier: _identifier, + fallbackIdentifier: _fallbackIdentifier, + ...props +}: PresentationSourceProps) { return ; } diff --git a/apps/mobile/src/components/ui/NativePresentation.tsx b/apps/mobile/src/components/ui/NativePresentation.tsx index 61ff2b2b226af..e05d1091fd1c2 100644 --- a/apps/mobile/src/components/ui/NativePresentation.tsx +++ b/apps/mobile/src/components/ui/NativePresentation.tsx @@ -5,6 +5,7 @@ import type { ViewProps } from "react-native"; export interface PresentationSourceProps extends ViewProps { readonly children: ReactElement; readonly identifier: string; + readonly fallbackIdentifier?: string; } const NativeSource: ComponentType = requireNativeView( diff --git a/apps/mobile/src/features/pull-requests/PullRequestDescription.tsx b/apps/mobile/src/features/pull-requests/PullRequestDescription.tsx index f0604d6b4ceb6..c43989404c289 100644 --- a/apps/mobile/src/features/pull-requests/PullRequestDescription.tsx +++ b/apps/mobile/src/features/pull-requests/PullRequestDescription.tsx @@ -6,10 +6,15 @@ import { } from "./PullRequestMedia"; import { PullRequestSectionHeading } from "./PullRequestSectionHeading"; import { T, useGT, useMessages } from "gt-react-native"; -import { useContext, useMemo, useState, type ComponentProps, type ReactNode } from "react"; +import { useContext, useId, useMemo, useState, type ComponentProps, type ReactNode } from "react"; import { Platform, Pressable, ScrollView, StyleSheet, View } from "react-native"; import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg"; -import { pullRequestImageSource } from "./pullRequestMediaSource"; +import { + pullRequestImageName, + pullRequestImageSource, + pullRequestScopedSourceIdentifier, +} from "./pullRequestMediaSource"; +import { filePreviewKey } from "../../lib/filePreviewGallery"; import { markdownReferenceDefinitions, parseMarkdownDocument } from "../../lib/markdownDocument"; import { SymbolView } from "../../components/ui/AppSymbol"; import { AppText as Text } from "../../components/ui/AppText"; @@ -35,7 +40,9 @@ export function PullRequestDescription(props: { const { collapse } = props; const expanded = collapse?.expanded ?? true; const gt = useGT(); + const imageFallback = gt("Image"); const messages = useMessages(); + const stripScope = `pr-attachment:${useId()}`; const [bodyHeight, setBodyHeight] = useState(0); const mediaContext = useContext(PullRequestMediaContext); const { themeVariables: colors } = useAppearancePreferences(); @@ -52,14 +59,30 @@ export function PullRequestDescription(props: { attachments: content.attachments.filter((attachment) => !isBotBadgeImage(attachment.uri)), }; }, [props.markdown, messages]); - const gallery: FilePreviewItem[] = content.attachments - .filter((attachment) => attachment.kind === "image") - .map((attachment) => { - return { - ...pullRequestImageSource(attachment.uri, mediaContext), - name: new URL(attachment.uri).pathname.split("/").pop() || gt("Image"), + const { gallery, galleryByUri } = useMemo(() => { + const byUri = new Map(); + const byKey = new Map(); + const items: FilePreviewItem[] = []; + for (const attachment of content.attachments) { + if (attachment.kind !== "image") continue; + const name = pullRequestImageName(attachment.uri, attachment.caption, imageFallback); + const source = pullRequestImageSource(attachment.uri, mediaContext, name); + const key = filePreviewKey(source); + const existing = byKey.get(key); + if (existing) { + byUri.set(attachment.uri, existing); + continue; + } + const item: FilePreviewItem = { + ...source, + sourceIdentifier: pullRequestScopedSourceIdentifier(stripScope, source), }; - }); + items.push(item); + byKey.set(key, item); + byUri.set(attachment.uri, item); + } + return { gallery: items, galleryByUri: byUri }; + }, [content.attachments, mediaContext, imageFallback, stripScope]); const canCollapse = collapse !== undefined && bodyHeight > COLLAPSED_HEIGHT; const collapsed = canCollapse && !expanded; return ( @@ -183,13 +206,7 @@ export function PullRequestDescription(props: { key={attachment.uri} url={attachment.uri} caption={attachment.caption} - source={ - gallery[ - content.attachments - .filter((item) => item.kind === "image") - .indexOf(attachment) - ]! - } + source={galleryByUri.get(attachment.uri)!} gallery={gallery} /> ), diff --git a/apps/mobile/src/features/pull-requests/PullRequestMarkdown.tsx b/apps/mobile/src/features/pull-requests/PullRequestMarkdown.tsx index c1852a6ee2601..5dc571ace34ce 100644 --- a/apps/mobile/src/features/pull-requests/PullRequestMarkdown.tsx +++ b/apps/mobile/src/features/pull-requests/PullRequestMarkdown.tsx @@ -3,17 +3,18 @@ import { type PullRequestBodySegment, } from "@t3tools/client-runtime/pull-request-markdown"; import { markdownTaskMarkerOffset } from "@t3tools/shared/markdownTaskList"; +import { useGT } from "gt-react-native"; import type { ReactNode } from "react"; import { View } from "react-native"; import { useProject } from "../../state/entities"; import { pullRequestTarget, type PullRequestParams } from "./usePullRequestDiff"; import { + PullRequestGalleryScopeContext, PullRequestMedia, PullRequestMediaContext, usePullRequestMediaUrl, } from "./PullRequestMedia"; -import { videoMimeType } from "@t3tools/shared/video"; -import { createContext, useContext, useMemo, useState } from "react"; +import { createContext, useContext, useId, useMemo, useState } from "react"; import { changeRequestReferenceAutolinker, resolveChangeRequestMediaUrl, @@ -27,15 +28,25 @@ import { nativePullRequestMarkdown } from "./pullRequestAutolinks"; import { useOpenPullRequest } from "../../native/useOpenPullRequest"; import { SelectableMarkdownText } from "../../native/SelectableMarkdownText"; import { useMarkdownPreviewStyles } from "../files/FileMarkdownPreview"; -import { markdownImageSources } from "../../lib/markdownImageSources"; import { markdownReferenceDefinitions } from "../../lib/markdownDocument"; import { FilePreviewGallery, useFilePreviewGallery } from "../../components/ui/FilePreviewGallery"; -import { pullRequestImageSource } from "./pullRequestMediaSource"; +import { filePreviewKey, filePreviewSourceIdentifier } from "../../lib/filePreviewGallery"; +import { + isPullRequestVideoUrl, + isPullRequestWebUrl, + pullRequestImageName, + pullRequestImageSource, + pullRequestMarkdownImages, + pullRequestMediaSource, + pullRequestScopedSourceIdentifier, + pullRequestVideoMimeType, +} from "./pullRequestMediaSource"; import { FilePreviewModal, type FilePreviewSource, type FilePreviewItem, } from "../../components/ui/FilePreviewModal"; +import { VideoPreviewModal, type VideoPreviewSource } from "../../components/ui/VideoPreviewModal"; import { ThreadMarkdownImageView } from "../threads/ThreadMarkdownImage"; import type { MarkdownImageRenderer } from "../../native/SelectableMarkdownText"; import type { SelectableMarkdownTextProps } from "../../native/SelectableMarkdownText.types"; @@ -85,23 +96,33 @@ export function PullRequestMarkdownRepository(props: { function MarkdownImage(props: { readonly href: string; readonly alt: string | null; + readonly title: string | null; readonly onPreview: (source: FilePreviewSource) => void; }) { + const gt = useGT(); const media = usePullRequestMediaUrl(props.href); const context = useContext(PullRequestMediaContext); + const galleryScope = useContext(PullRequestGalleryScopeContext); const withGallery = useFilePreviewGallery(); + const label = props.alt?.trim() || props.title?.trim() || null; + const name = pullRequestImageName(props.href, label, gt("Image")); + const previewSource = pullRequestImageSource(props.href, context, name); + const sourceIdentifier = galleryScope + ? pullRequestScopedSourceIdentifier(galleryScope, previewSource) + : filePreviewSourceIdentifier(previewSource); return ( props.onPreview( withGallery({ - ...pullRequestImageSource(props.href, context), - name: source.name, + ...previewSource, sourceIdentifier: source.sourceIdentifier, }), ) @@ -123,42 +144,58 @@ export function PullRequestMarkdown(props: { readonly checked: boolean; }) => boolean; }) { + const gt = useGT(); + const imageFallback = gt("Image"); + const galleryScope = `pr-markdown:${useId()}`; const mediaContext = useContext(PullRequestMediaContext); const changeRequestUrl = useContext(ChangeRequestUrlContext); const segments = useMemo( () => splitPullRequestBody(props.markdown, markdownReferenceDefinitions), [props.markdown], ); + const groupSegments = useMemo( + () => + props.imageGroupMarkdown === undefined || props.imageGroupMarkdown === props.markdown + ? segments + : splitPullRequestBody(props.imageGroupMarkdown, markdownReferenceDefinitions), + [props.imageGroupMarkdown, props.markdown, segments], + ); const [undoneTicks, setUndoneTicks] = useState(0); - const gallery: FilePreviewItem[] = markdownImageSources( - props.imageGroupMarkdown ?? props.markdown, - ) - .map((href) => (changeRequestUrl ? resolveChangeRequestMediaUrl(href, changeRequestUrl) : href)) - .filter( - (uri) => - /^https?:\/\//i.test(uri) && - videoMimeType({ name: uri.split(/[?#]/)[0] ?? uri, mimeType: "" }) === null, - ) - .map((uri) => pullRequestImageSource(uri, mediaContext)); + const gallery = useMemo( + () => + pullRequestMarkdownImages(groupSegments, (href) => + changeRequestUrl ? resolveChangeRequestMediaUrl(href, changeRequestUrl) : href, + ).map(({ uri, alt }) => { + const name = pullRequestImageName(uri, alt, imageFallback); + const source = pullRequestImageSource(uri, mediaContext, name); + return { + ...source, + sourceIdentifier: pullRequestScopedSourceIdentifier(galleryScope, source), + }; + }), + [groupSegments, changeRequestUrl, mediaContext, imageFallback, galleryScope], + ); const segmentProps = { - gallery, lineBreaks: props.lineBreaks, undoneTicks, onTaskListChange: props.onTaskListChange, onTaskListUndone: () => setUndoneTicks((count) => count + 1), }; return ( - - {segments.map((segment) => ( - - ))} - + + + + {segments.map((segment) => ( + + ))} + + + ); } function PullRequestBodySegmentView(props: { readonly segment: PullRequestBodySegment; - readonly gallery: FilePreviewItem[]; readonly lineBreaks: boolean | undefined; readonly undoneTicks: number; readonly onTaskListChange: @@ -175,7 +212,6 @@ function PullRequestBodySegmentView(props: { (null); - const renderImage: MarkdownImageRenderer = (image) => ( - - ); + const [video, setVideo] = useState(null); + const renderImage: MarkdownImageRenderer = (image) => { + const resolvedHref = resolveMediaUrl(image.href); + if (isPullRequestWebUrl(resolvedHref) && isPullRequestVideoUrl(resolvedHref)) { + return ( + + ); + } + return ( + + ); + }; const styles = useMarkdownPreviewStyles(); return ( - + <> - setPreview(pullRequestImageSource(resolveMediaUrl(href), mediaContext)) - } + onImagePress={(href) => { + const uri = resolveMediaUrl(href); + if (!isPullRequestWebUrl(uri)) return; + if (isPullRequestVideoUrl(uri)) { + setVideo({ + type: "media", + ...pullRequestMediaSource(uri, mediaContext), + name: uri.split(/[?#]/)[0]?.split("/").pop() || gt("Video"), + mimeType: pullRequestVideoMimeType(uri) ?? "video/mp4", + }); + return; + } + const source = pullRequestImageSource( + uri, + mediaContext, + pullRequestImageName(uri, null, gt("Image")), + ); + const key = filePreviewKey(source); + const match = gallery.find((item) => filePreviewKey(item) === key); + setPreview( + match + ? { ...match, sourceIdentifier: "" } + : { + ...source, + sourceIdentifier: "", + }, + ); + }} onTaskListItemPress={props.onTaskListItemPress} /> setPreview(null)} /> - + setVideo(null)} /> + ); } diff --git a/apps/mobile/src/features/pull-requests/PullRequestMedia.test.tsx b/apps/mobile/src/features/pull-requests/PullRequestMedia.test.tsx new file mode 100644 index 0000000000000..eaf50622ccd9f --- /dev/null +++ b/apps/mobile/src/features/pull-requests/PullRequestMedia.test.tsx @@ -0,0 +1,276 @@ +import type { ReactNode } from "react"; +import { act } from "react"; +import { createRoot } from "react-dom/client"; +import { expect, it, vi } from "vite-plus/test"; +import type { FilePreviewSource } from "../../components/ui/FilePreviewModal.types"; +import type { VideoPreviewSource } from "../../components/ui/VideoPreviewModal"; +import type { MarkdownImageRenderer } from "../../native/SelectableMarkdownText"; + +const harness = vi.hoisted(() => ({ + imageOnLoad: null as (() => void) | null, + imageOnError: null as (() => void) | null, + presentationSources: [] as { identifier: string; fallbackIdentifier?: string }[], + previewSource: null as FilePreviewSource | null, + videoSource: null as VideoPreviewSource | null, + markdownProps: [] as { + markdown: string; + renderImage?: MarkdownImageRenderer; + onImagePress?: (href: string) => void; + }[], + videoPlayers: [] as { uri: string | null; name: string }[], + threadImages: [] as { + sourceKey: string; + sourceIdentifier?: string; + onPressPreview: (source: FilePreviewSource) => void; + }[], +})); + +vi.mock("react-native", () => ({ + Pressable: (props: { + children?: ReactNode; + onPress?: () => void; + accessibilityLabel?: string; + }) => ( + + ), + View: ({ children }: { children?: ReactNode }) =>
{children}
, +})); +vi.mock("expo-image", () => ({ + Image: (props: { onLoad?: () => void; onError?: () => void }) => { + harness.imageOnLoad = props.onLoad ?? null; + harness.imageOnError = props.onError ?? null; + return ; + }, +})); +vi.mock("../../components/ui/AppText", () => ({ + AppText: ({ children }: { children?: ReactNode }) => {children}, +})); +vi.mock("../../components/ui/NativePresentation", () => ({ + PresentationSource: (props: { + identifier: string; + fallbackIdentifier?: string; + children?: ReactNode; + }) => { + harness.presentationSources.push({ + identifier: props.identifier, + ...(props.fallbackIdentifier !== undefined + ? { fallbackIdentifier: props.fallbackIdentifier } + : {}), + }); + return
{props.children}
; + }, +})); +vi.mock("../../components/ui/FilePreviewModal", () => ({ + FilePreviewModal: (props: { source: FilePreviewSource | null }) => { + harness.previewSource = props.source; + return null; + }, +})); +vi.mock("../../components/ui/VideoPreviewModal", () => ({ + VideoPreviewModal: (props: { source: VideoPreviewSource | null }) => { + harness.videoSource = props.source; + return null; + }, +})); +vi.mock("../../components/MediaVideoPlayer", () => ({ + MediaVideoPlayer: (props: { uri: string | null; name: string }) => { + harness.videoPlayers.push({ uri: props.uri, name: props.name }); + return
; + }, +})); +vi.mock("../../components/VideoAttachmentTile", () => ({ + VideoAttachmentTile: () => null, +})); +vi.mock("../threads/ThreadMarkdownImage", () => ({ + ThreadMarkdownImageView: (props: { + sourceKey: string; + sourceIdentifier?: string; + onPressPreview: (source: FilePreviewSource) => void; + }) => { + harness.threadImages.push(props); + return ( + - ), - View: ({ children }: { children?: ReactNode }) =>
{children}
, -})); -vi.mock("expo-image", () => ({ - Image: (props: { onLoad?: () => void; onError?: () => void }) => { - harness.imageOnLoad = props.onLoad ?? null; - harness.imageOnError = props.onError ?? null; - return ; - }, -})); -vi.mock("../../components/ui/AppText", () => ({ - AppText: ({ children }: { children?: ReactNode }) => {children}, -})); -vi.mock("../../components/ui/NativePresentation", () => ({ - PresentationSource: (props: { - identifier: string; - fallbackIdentifier?: string; - children?: ReactNode; - }) => { - harness.presentationSources.push({ - identifier: props.identifier, - ...(props.fallbackIdentifier !== undefined - ? { fallbackIdentifier: props.fallbackIdentifier } - : {}), - }); - return
{props.children}
; - }, -})); -vi.mock("../../components/ui/FilePreviewModal", () => ({ - FilePreviewModal: (props: { source: FilePreviewSource | null }) => { - harness.previewSource = props.source; - return null; - }, -})); -vi.mock("../../components/ui/VideoPreviewModal", () => ({ - VideoPreviewModal: (props: { source: VideoPreviewSource | null }) => { - harness.videoSource = props.source; - return null; - }, -})); -vi.mock("../../components/MediaVideoPlayer", () => ({ - MediaVideoPlayer: (props: { uri: string | null; name: string }) => { - harness.videoPlayers.push({ uri: props.uri, name: props.name }); - return
; - }, -})); -vi.mock("../../components/VideoAttachmentTile", () => ({ - VideoAttachmentTile: () => null, -})); -vi.mock("../threads/ThreadMarkdownImage", () => ({ - ThreadMarkdownImageView: (props: { - sourceKey: string; - sourceIdentifier?: string; - onPressPreview: (source: FilePreviewSource) => void; - }) => { - harness.threadImages.push(props); - return ( -