AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
feat(mobile): swipe between images in the fullscreen preview (#687)
Cotton9cc9d0e80f2e
diff --git a/apps/mobile/src/components/LocalTiptapEditor.tsx b/apps/mobile/src/components/LocalTiptapEditor.tsxindex c8268673..16048551 100644--- a/apps/mobile/src/components/LocalTiptapEditor.tsx+++ b/apps/mobile/src/components/LocalTiptapEditor.tsx@@ -304,6 +304,32 @@ const buildImageResourceTargetJson = (figure: HTMLElement): string | null => {} satisfies EditorResourceTarget);};+const buildMobileImagePreviewPayload = (figure: HTMLElement): string => {+ const source = figure.dataset.resourceHref ?? "";+ const alt = figure.dataset.resourceFilename || "";+ const allFigures = typeof document !== "undefined"+ ? Array.from(document.querySelectorAll<HTMLElement>("figure.edgeever-image-node[data-resource-href]"))+ : [];+ const images = allFigures+ .map((fig) => ({+ alt: fig.dataset.resourceFilename || "",+ source: fig.dataset.resourceHref || "",+ }))+ .filter((img) => Boolean(img.source));++ let index = allFigures.indexOf(figure);+ if (index < 0 && source) {+ index = images.findIndex((img) => img.source === source);+ }++ return JSON.stringify({+ alt,+ source,+ index: Math.max(0, index),+ images: images.length > 0 ? images : [{ alt, source }],+ });+};+const handleMobileResourceEvent = (event: Event,onResourcePress?: (targetJson: string) => Promise<void>,@@ -343,10 +369,7 @@ const handleMobileResourceEvent = (if (options?.allowImagePreview && options.onImagePreview && !imageActionRequested) {event.preventDefault();event.stopPropagation();- void options.onImagePreview(JSON.stringify({- alt: imageFigure.dataset.resourceFilename || "",- source: imageHref,- }));+ void options.onImagePreview(buildMobileImagePreviewPayload(imageFigure));return true;}@@ -2596,10 +2619,7 @@ const createProtectedImageExtension = (if (!options?.onImagePreview) return false;const source = figure.dataset.resourceHref ?? "";if (!source) return false;- void options.onImagePreview(JSON.stringify({- alt: figure.dataset.resourceFilename || "",- source,- }));+ void options.onImagePreview(buildMobileImagePreviewPayload(figure));return true;};diff --git a/apps/mobile/src/components/ZoomableImagePreview.tsx b/apps/mobile/src/components/ZoomableImagePreview.tsxindex b5793afc..b8b8ca54 100644--- a/apps/mobile/src/components/ZoomableImagePreview.tsx+++ b/apps/mobile/src/components/ZoomableImagePreview.tsx@@ -1,26 +1,54 @@import { useCallback, useEffect, useState, type ReactNode } from "react";-import { PixelRatio, StyleSheet, View } from "react-native";+import { PixelRatio, Pressable, StyleSheet, Text, View } from "react-native";import { Gesture, GestureDetector, GestureHandlerRootView } from "react-native-gesture-handler";-import Animated, { useAnimatedStyle, useSharedValue } from "react-native-reanimated";-import { clampImageTranslation, fitPreviewImage, previewResizeMultiplier, zoomImageTranslation, type ImageSize } from "../lib/mobile-image-zoom";+import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withSpring, withTiming } from "react-native-reanimated";+import { ChevronLeft, ChevronRight } from "./icons";+import {+ clampImageTranslation,+ fitPreviewImage,+ previewResizeMultiplier,+ resolveNextPreviewIndex,+ resolveSwipeDirection,+ zoomImageTranslation,+ type ImageSize,+ type PreviewImageItem,+} from "../lib/mobile-image-zoom";type Props = {accessibilityHint: string;accessibilityLabel: string;+ currentIndex?: number;+ images?: PreviewImageItem[];+ onIndexChange?: (index: number) => void;onLongPress: () => void;renderImage: (onDimensions: (size: ImageSize) => void, resizeMultiplier: number) => ReactNode;};-export const ZoomableImagePreview = ({ accessibilityHint, accessibilityLabel, onLongPress, renderImage }: Props) => {+export const ZoomableImagePreview = ({+ accessibilityHint,+ accessibilityLabel,+ currentIndex = 0,+ images,+ onIndexChange,+ onLongPress,+ renderImage,+}: Props) => {const [viewport, setViewport] = useState<ImageSize>({ width: 0, height: 0 });const [image, setImage] = useState<ImageSize>({ width: 0, height: 0 });++ const total = images && images.length > 0 ? images.length : 1;+ const activeIndex = Math.max(0, Math.min(total - 1, currentIndex));+ const currentItem = images && images.length > activeIndex ? images[activeIndex] : null;+ const currentSource = currentItem?.source ?? "";+const onDimensions = useCallback((size: ImageSize) => {// Android reports decoded dimensions, which can change after requesting more detail.// Capture the aspect once so that this reload never resets an ongoing gesture.if (size.width > 0 && size.height > 0) {- setImage((previous) => previous.width > 0 ? previous : size);+ setImage((previous) => (previous.width > 0 ? previous : size));}}, []);+const fitted = fitPreviewImage(image, viewport);const scale = useSharedValue(1);const x = useSharedValue(0);@@ -33,12 +61,20 @@ export const ZoomableImagePreview = ({ accessibilityHint, accessibilityLabel, onconst pinching = useSharedValue(false);const maxScale = 32;+ useEffect(() => {+ setImage({ width: 0, height: 0 });+ scale.value = 1;+ x.value = 0;+ y.value = 0;+ pinching.value = false;+ }, [currentSource, activeIndex]);+useEffect(() => {scale.value = 1;x.value = 0;y.value = 0;pinching.value = false;- }, [viewport.width, viewport.height, image.width, image.height, scale, x, y, pinching]);+ }, [viewport.width, viewport.height]);const pinch = Gesture.Pinch().onStart((event) => {@@ -62,12 +98,77 @@ export const ZoomableImagePreview = ({ accessibilityHint, accessibilityLabel, onscale.value = next;}).onFinalize(() => { pinching.value = false; });+const pan = Gesture.Pan().minDistance(8)+ .onStart(() => {+ startX.value = x.value;+ startY.value = y.value;+ }).onChange((event) => {- if (pinching.value || event.numberOfPointers !== 1 || scale.value <= 1) return;- x.value = clampImageTranslation(x.value + event.changeX, fitted.width, viewport.width, scale.value);- y.value = clampImageTranslation(y.value + event.changeY, fitted.height, viewport.height, scale.value);+ if (pinching.value || event.numberOfPointers !== 1) return;++ if (scale.value > 1) {+ x.value = clampImageTranslation(x.value + event.changeX, fitted.width, viewport.width, scale.value);+ y.value = clampImageTranslation(y.value + event.changeY, fitted.height, viewport.height, scale.value);+ return;+ }++ if (total <= 1) {+ x.value = event.translationX * 0.2;+ y.value = event.translationY * 0.2;+ return;+ }++ const absX = Math.abs(event.translationX);+ const absY = Math.abs(event.translationY);+ const hasPrev = activeIndex > 0;+ const hasNext = activeIndex < total - 1;++ if (absX >= absY) {+ const isBoundary = (event.translationX > 0 && !hasPrev) || (event.translationX < 0 && !hasNext);+ x.value = isBoundary ? event.translationX * 0.25 : event.translationX;+ y.value = 0;+ } else {+ const isBoundary = (event.translationY > 0 && !hasPrev) || (event.translationY < 0 && !hasNext);+ y.value = isBoundary ? event.translationY * 0.25 : event.translationY;+ x.value = 0;+ }+ })+ .onEnd((event) => {+ if (pinching.value || scale.value > 1) return;++ if (total <= 1 || !onIndexChange) {+ x.value = withTiming(0, { duration: 200 });+ y.value = withTiming(0, { duration: 200 });+ return;+ }++ const dir = resolveSwipeDirection(event.translationX, event.translationY, event.velocityX, event.velocityY);+ const nextIndex = resolveNextPreviewIndex(activeIndex, total, dir);++ if (nextIndex !== activeIndex) {+ const isHorizontal = Math.abs(event.translationX) >= Math.abs(event.translationY);+ if (isHorizontal) {+ const targetX = dir === "next" ? -viewport.width : viewport.width;+ x.value = withTiming(targetX, { duration: 150 }, () => {+ x.value = 0;+ y.value = 0;+ runOnJS(onIndexChange)(nextIndex);+ });+ } else {+ const targetY = dir === "next" ? -viewport.height : viewport.height;+ y.value = withTiming(targetY, { duration: 150 }, () => {+ x.value = 0;+ y.value = 0;+ runOnJS(onIndexChange)(nextIndex);+ });+ }+ } else {+ x.value = withSpring(0, { damping: 20, stiffness: 200 });+ y.value = withSpring(0, { damping: 20, stiffness: 200 });+ }});+const doubleTap = Gesture.Tap().numberOfTaps(2).maxDistance(8).onEnd((event, success) => {if (!success) return;@@ -76,20 +177,61 @@ export const ZoomableImagePreview = ({ accessibilityHint, accessibilityLabel, ony.value = clampImageTranslation(zoomImageTranslation(y.value, event.y - viewport.height / 2, scale.value, next), fitted.height, viewport.height, next);scale.value = next;});+const longPress = Gesture.LongPress().minDuration(400).maxDistance(8).numberOfPointers(1).runOnJS(true).onStart(onLongPress);+const gesture = Gesture.Race(Gesture.Simultaneous(pinch, pan), doubleTap, longPress);const animatedStyle = useAnimatedStyle(() => ({transform: [{ translateX: x.value }, { translateY: y.value }, { scale: scale.value }],}));+ const fullAccessibilityLabel = total > 1+ ? `${accessibilityLabel} (${activeIndex + 1} / ${total})`+ : accessibilityLabel;+return (<GestureHandlerRootView style={styles.root}>+ {total > 1 ? (+ <View pointerEvents="none" style={styles.counterContainer}>+ <View style={styles.counterBadge}>+ <Text style={styles.counterText}>+ {`${activeIndex + 1} / ${total}`}+ </Text>+ </View>+ </View>+ ) : null}++ {total > 1 && onIndexChange ? (+ <>+ {activeIndex > 0 ? (+ <Pressable+ accessibilityLabel="Previous image"+ accessibilityRole="button"+ onPress={() => onIndexChange(activeIndex - 1)}+ style={[styles.navButton, styles.navButtonLeft]}+ >+ <ChevronLeft color="#ffffff" size={24} />+ </Pressable>+ ) : null}+ {activeIndex < total - 1 ? (+ <Pressable+ accessibilityLabel="Next image"+ accessibilityRole="button"+ onPress={() => onIndexChange(activeIndex + 1)}+ style={[styles.navButton, styles.navButtonRight]}+ >+ <ChevronRight color="#ffffff" size={24} />+ </Pressable>+ ) : null}+ </>+ ) : null}+<GestureDetector gesture={gesture}><ViewaccessibleaccessibilityHint={accessibilityHint}- accessibilityLabel={accessibilityLabel}+ accessibilityLabel={fullAccessibilityLabel}accessibilityRole="image"accessibilityActions={[{ name: "increment" }, { name: "decrement" }, { name: "longpress" }]}onAccessibilityAction={({ nativeEvent }) => {@@ -97,12 +239,28 @@ export const ZoomableImagePreview = ({ accessibilityHint, accessibilityLabel, ononLongPress();return;}- if (nativeEvent.actionName !== "increment" && nativeEvent.actionName !== "decrement") return;- const next = nativeEvent.actionName === "increment"- ? Math.min(maxScale, scale.value * 2) : Math.max(1, scale.value / 2);- x.value = clampImageTranslation(x.value * next / scale.value, fitted.width, viewport.width, next);- y.value = clampImageTranslation(y.value * next / scale.value, fitted.height, viewport.height, next);- scale.value = next;+ if (nativeEvent.actionName === "increment") {+ if (scale.value <= 1 && total > 1 && onIndexChange && activeIndex < total - 1) {+ onIndexChange(activeIndex + 1);+ return;+ }+ const next = Math.min(maxScale, scale.value * 2);+ x.value = clampImageTranslation(x.value * next / scale.value, fitted.width, viewport.width, next);+ y.value = clampImageTranslation(y.value * next / scale.value, fitted.height, viewport.height, next);+ scale.value = next;+ return;+ }+ if (nativeEvent.actionName === "decrement") {+ if (scale.value <= 1 && total > 1 && onIndexChange && activeIndex > 0) {+ onIndexChange(activeIndex - 1);+ return;+ }+ const next = Math.max(1, scale.value / 2);+ x.value = clampImageTranslation(x.value * next / scale.value, fitted.width, viewport.width, next);+ y.value = clampImageTranslation(y.value * next / scale.value, fitted.height, viewport.height, next);+ scale.value = next;+ return;+ }}}onLayout={(event) => setViewport(event.nativeEvent.layout)}style={styles.viewport}@@ -121,4 +279,47 @@ export const ZoomableImagePreview = ({ accessibilityHint, accessibilityLabel, onconst styles = StyleSheet.create({root: { flex: 1, width: "100%" },viewport: { flex: 1, alignItems: "center", justifyContent: "center", overflow: "hidden" },+ counterContainer: {+ alignItems: "center",+ justifyContent: "center",+ left: 0,+ position: "absolute",+ right: 0,+ top: 58,+ zIndex: 10,+ },+ counterBadge: {+ backgroundColor: "rgba(15, 23, 42, 0.78)",+ borderColor: "rgba(255, 255, 255, 0.15)",+ borderRadius: 999,+ borderWidth: StyleSheet.hairlineWidth,+ paddingHorizontal: 14,+ paddingVertical: 6,+ },+ counterText: {+ color: "#ffffff",+ fontSize: 14,+ fontWeight: "600",+ letterSpacing: 0.5,+ },+ navButton: {+ alignItems: "center",+ backgroundColor: "rgba(15, 23, 42, 0.65)",+ borderColor: "rgba(255, 255, 255, 0.15)",+ borderRadius: 22,+ borderWidth: StyleSheet.hairlineWidth,+ height: 44,+ justifyContent: "center",+ marginTop: -22,+ position: "absolute",+ top: "50%",+ width: 44,+ zIndex: 10,+ },+ navButtonLeft: {+ left: 12,+ },+ navButtonRight: {+ right: 12,+ },});diff --git a/apps/mobile/src/lib/mobile-image-zoom.test.ts b/apps/mobile/src/lib/mobile-image-zoom.test.tsindex cdc8f4e0..8ec7ae67 100644--- a/apps/mobile/src/lib/mobile-image-zoom.test.ts+++ b/apps/mobile/src/lib/mobile-image-zoom.test.ts@@ -1,5 +1,13 @@import { describe, expect, test } from "bun:test";-import { clampImageTranslation, fitPreviewImage, previewResizeMultiplier, zoomImageTranslation } from "./mobile-image-zoom";+import {+ clampImageTranslation,+ extractImagesFromTiptapDoc,+ fitPreviewImage,+ previewResizeMultiplier,+ resolveNextPreviewIndex,+ resolveSwipeDirection,+ zoomImageTranslation,+} from "./mobile-image-zoom";describe("fullscreen image geometry", () => {const viewport = { width: 400, height: 800 };@@ -33,3 +41,101 @@ describe("fullscreen image geometry", () => {expect(previewResizeMultiplier({ width: 0, height: 0 }, viewport, 3)).toBe(1);});});++describe("swipe direction and navigation resolution", () => {+ test("resolves horizontal swipe directions based on distance", () => {+ expect(resolveSwipeDirection(-70, 10, 0, 0, 60)).toBe("next");+ expect(resolveSwipeDirection(70, -10, 0, 0, 60)).toBe("prev");+ expect(resolveSwipeDirection(30, 10, 0, 0, 60)).toBeNull();+ });++ test("resolves horizontal swipe directions based on velocity", () => {+ expect(resolveSwipeDirection(-20, 0, -600, 0, 60, 500)).toBe("next");+ expect(resolveSwipeDirection(20, 0, 600, 0, 60, 500)).toBe("prev");+ });++ test("resolves vertical swipe directions based on distance", () => {+ expect(resolveSwipeDirection(10, -80, 0, 0, 60)).toBe("next");+ expect(resolveSwipeDirection(-10, 80, 0, 0, 60)).toBe("prev");+ expect(resolveSwipeDirection(0, 30, 0, 0, 60)).toBeNull();+ });++ test("resolves vertical swipe directions based on velocity", () => {+ expect(resolveSwipeDirection(0, -20, 0, -700, 60, 500)).toBe("next");+ expect(resolveSwipeDirection(0, 20, 0, 700, 60, 500)).toBe("prev");+ });++ test("calculates clamped next/prev preview index", () => {+ expect(resolveNextPreviewIndex(0, 3, "prev")).toBe(0);+ expect(resolveNextPreviewIndex(0, 3, "next")).toBe(1);+ expect(resolveNextPreviewIndex(1, 3, "next")).toBe(2);+ expect(resolveNextPreviewIndex(2, 3, "next")).toBe(2);+ expect(resolveNextPreviewIndex(2, 3, "prev")).toBe(1);+ expect(resolveNextPreviewIndex(1, 3, null)).toBe(1);+ });+});++describe("extractImagesFromTiptapDoc", () => {+ test("handles empty and non-object documents", () => {+ expect(extractImagesFromTiptapDoc(null)).toEqual([]);+ expect(extractImagesFromTiptapDoc(undefined)).toEqual([]);+ expect(extractImagesFromTiptapDoc({})).toEqual([]);+ expect(extractImagesFromTiptapDoc({ type: "doc", content: [] })).toEqual([]);+ });++ test("extracts standalone, gallery, and nested images in order", () => {+ const doc = {+ type: "doc",+ content: [+ {+ type: "paragraph",+ content: [{ type: "text", text: "Intro note" }],+ },+ {+ type: "image",+ attrs: { src: "blob:image-1", alt: "First image" },+ },+ {+ type: "edgeeverImageGallery",+ attrs: { layout: "2" },+ content: [+ {+ type: "image",+ attrs: { src: "blob:image-2", alt: "Second image" },+ },+ {+ type: "image",+ attrs: { src: "blob:image-3", alt: "" },+ },+ ],+ },+ {+ type: "table",+ content: [+ {+ type: "tableRow",+ content: [+ {+ type: "tableCell",+ content: [+ {+ type: "image",+ attrs: { src: "blob:image-4", alt: "Table image" },+ },+ ],+ },+ ],+ },+ ],+ },+ ],+ };++ expect(extractImagesFromTiptapDoc(doc)).toEqual([+ { alt: "First image", source: "blob:image-1" },+ { alt: "Second image", source: "blob:image-2" },+ { alt: "", source: "blob:image-3" },+ { alt: "Table image", source: "blob:image-4" },+ ]);+ });+});diff --git a/apps/mobile/src/lib/mobile-image-zoom.ts b/apps/mobile/src/lib/mobile-image-zoom.tsindex 56238c55..f3527e80 100644--- a/apps/mobile/src/lib/mobile-image-zoom.ts+++ b/apps/mobile/src/lib/mobile-image-zoom.ts@@ -1,5 +1,12 @@export type ImageSize = { width: number; height: number };+export type PreviewImageItem = {+ alt: string;+ source: string;+};++export type SwipeDirection = "prev" | "next" | null;+export const fitPreviewImage = (image: ImageSize, viewport: ImageSize): ImageSize => {if (image.width <= 0 || image.height <= 0) return viewport;const ratio = Math.min(viewport.width / image.width, viewport.height / image.height);@@ -27,3 +34,89 @@ export const previewResizeMultiplier = (fitted: ImageSize, viewport: ImageSize,Math.sqrt(8_000_000 / (fitted.width * fitted.height * density * density)),));};++/**+ * Resolves swipe direction from pan gesture deltas and velocities.+ * Supports both horizontal (left/right) and vertical (up/down) swipe transitions.+ */+export const resolveSwipeDirection = (+ deltaX: number,+ deltaY: number,+ velocityX = 0,+ velocityY = 0,+ threshold = 60,+ velocityThreshold = 500,+): SwipeDirection => {+ "worklet";+ const absX = Math.abs(deltaX);+ const absY = Math.abs(deltaY);++ if (absX >= absY) {+ if (deltaX < -threshold || velocityX < -velocityThreshold) {+ return "next";+ }+ if (deltaX > threshold || velocityX > velocityThreshold) {+ return "prev";+ }+ } else {+ if (deltaY < -threshold || velocityY < -velocityThreshold) {+ return "next";+ }+ if (deltaY > threshold || velocityY > velocityThreshold) {+ return "prev";+ }+ }++ return null;+};++/**+ * Calculates next image index clamped to [0, total - 1].+ */+export const resolveNextPreviewIndex = (+ currentIndex: number,+ total: number,+ direction: SwipeDirection,+): number => {+ "worklet";+ if (direction === "next" && currentIndex < total - 1) {+ return currentIndex + 1;+ }+ if (direction === "prev" && currentIndex > 0) {+ return currentIndex - 1;+ }+ return currentIndex;+};++/**+ * Extracts all image source/alt pairs from a Tiptap document tree.+ * Handles top-level images, image galleries, and nested structures (tables, blocks).+ */+export const extractImagesFromTiptapDoc = (node: unknown): PreviewImageItem[] => {+ if (!node || typeof node !== "object") return [];+ const results: PreviewImageItem[] = [];++ const traverse = (curr: unknown) => {+ if (!curr || typeof curr !== "object") return;+ const typed = curr as { type?: unknown; attrs?: Record<string, unknown>; content?: unknown[] };+ if (+ typed.type === "image" &&+ typed.attrs &&+ typeof typed.attrs.src === "string" &&+ typed.attrs.src.trim()+ ) {+ results.push({+ alt: typeof typed.attrs.alt === "string" ? typed.attrs.alt : "",+ source: typed.attrs.src.trim(),+ });+ }+ if (Array.isArray(typed.content)) {+ for (const child of typed.content) {+ traverse(child);+ }+ }+ };++ traverse(node);+ return results;+};diff --git a/apps/mobile/src/screens/WorkspaceMemoDetail.tsx b/apps/mobile/src/screens/WorkspaceMemoDetail.tsxindex e6a087d4..9a8baa00 100644--- a/apps/mobile/src/screens/WorkspaceMemoDetail.tsx+++ b/apps/mobile/src/screens/WorkspaceMemoDetail.tsx@@ -25,7 +25,7 @@ import MobileNoteImageFontPicker from "../components/MobileNoteImageFontPicker";import { getMobileNoteImageFontLabel } from "../lib/note-image-font-options";import { MobileResourceActions } from "../components/MobileResourceActions";import { ZoomableImagePreview } from "../components/ZoomableImagePreview";-import type { ImageSize } from "../lib/mobile-image-zoom";+import { extractImagesFromTiptapDoc, type ImageSize, type PreviewImageItem } from "../lib/mobile-image-zoom";import { encodeMobileNoteImageFileUri } from "../lib/mobile-note-image-export";import { SAFE_DOM_WEBVIEW_PROPS } from "../lib/mobile-dom";import { getNextMobileNoteSearchIndex } from "../lib/mobile-note-search";@@ -502,7 +502,12 @@ export const MemoDetailModal = ({const [searchQuery, setSearchQuery] = useState("");const [bodySearchMatchCount, setBodySearchMatchCount] = useState(0);const [activeMatchIndex, setActiveMatchIndex] = useState(0);- const [imagePreview, setImagePreview] = useState<{ alt: string; source: string } | null>(null);+ const [imagePreview, setImagePreview] = useState<{+ alt: string;+ source: string;+ images: PreviewImageItem[];+ index: number;+ } | null>(null);const [resourceTarget, setResourceTarget] = useState<MobileResourceTarget | null>(null);const [viewerReady, setViewerReady] = useState(false);const [titleCollapsed, setTitleCollapsed] = useState(false);@@ -673,17 +678,56 @@ export const MemoDetailModal = ({const onImagePreview = useCallback(async (payloadJson: string) => {try {- const parsed = JSON.parse(payloadJson) as { alt?: unknown; source?: unknown };+ const parsed = JSON.parse(payloadJson) as {+ alt?: unknown;+ source?: unknown;+ images?: unknown;+ index?: unknown;+ };if (typeof parsed.source === "string" && parsed.source) {+ const source = parsed.source;+ const alt = typeof parsed.alt === "string" ? parsed.alt : "";++ let images: PreviewImageItem[] = [];+ if (Array.isArray(parsed.images) && parsed.images.length > 0) {+ images = parsed.images+ .filter((item): item is { source: string; alt?: unknown } =>+ Boolean(item && typeof item === "object" && typeof (item as any).source === "string" && (item as any).source)+ )+ .map((item) => ({+ alt: typeof item.alt === "string" ? item.alt : "",+ source: item.source,+ }));+ }++ if (images.length === 0 && memo?.contentJson) {+ images = extractImagesFromTiptapDoc(memo.contentJson);+ }++ if (images.length === 0) {+ images = [{ alt, source }];+ }++ let activeIndex =+ typeof parsed.index === "number" && parsed.index >= 0 && parsed.index < images.length+ ? parsed.index+ : images.findIndex((img) => img.source === source);+ if (activeIndex < 0) {+ images = [{ alt, source }, ...images];+ activeIndex = 0;+ }+setImagePreview({- alt: typeof parsed.alt === "string" ? parsed.alt : "",- source: parsed.source,+ alt: images[activeIndex].alt || alt,+ source: images[activeIndex].source || source,+ images,+ index: activeIndex,});}} catch {// Ignore malformed bridge payloads.}- }, []);+ }, [memo?.contentJson]);const memoTitle = localizeUntitledMemoTitle(memo?.title, resolvedLocale);const memoTagsText = memo?.tags.join(", ") ?? "";@@ -1858,29 +1902,50 @@ export const MemoDetailModal = ({<View style={resourceImageStyles.previewBackdrop}>{imagePreview ? (<ZoomableImagePreview- key={imagePreview.source}+ key="workspace-note-image-preview"accessibilityHint={getMobileCatalog(resolvedLocale).mobile.memoDetail.imageActionsHint}- accessibilityLabel={imagePreview.alt || getMobileCatalog(resolvedLocale).mobile.imageShare.preview}+ accessibilityLabel={+ (imagePreview.images[imagePreview.index]?.alt || imagePreview.alt) ||+ getMobileCatalog(resolvedLocale).mobile.imageShare.preview+ }+ currentIndex={imagePreview.index}+ images={imagePreview.images}+ onIndexChange={(nextIndex) => {+ setImagePreview((previous) => {+ if (!previous || !previous.images[nextIndex]) return previous;+ const nextItem = previous.images[nextIndex];+ return {+ ...previous,+ alt: nextItem.alt || "",+ source: nextItem.source,+ index: nextIndex,+ };+ });+ }}onLongPress={() => {// Long-press fullscreen preview → same resource sheet as ⋯ in the note.- const target = getMobileImageTarget(imagePreview.source, imagePreview.alt);+ const activeItem = imagePreview.images[imagePreview.index] ?? imagePreview;+ const target = getMobileImageTarget(activeItem.source, activeItem.alt);if (target) {setResourceTarget(target);}}}- renderImage={(onDimensions, resizeMultiplier) => (- <AuthenticatedResourceImage- alt={imagePreview.alt}- href={imagePreview.source}- loadResourceBlob={client?.getResourceBlob}- onLoadFailure={imageLoadFailureNotifier}- onDimensions={onDimensions}- resizeMultiplier={resizeMultiplier}- resizeMode="contain"- session={session}- style={resourceImageStyles.previewImage}- />- )}+ renderImage={(onDimensions, resizeMultiplier) => {+ const activeItem = imagePreview.images[imagePreview.index] ?? imagePreview;+ return (+ <AuthenticatedResourceImage+ alt={activeItem.alt}+ href={activeItem.source}+ loadResourceBlob={client?.getResourceBlob}+ onLoadFailure={imageLoadFailureNotifier}+ onDimensions={onDimensions}+ resizeMultiplier={resizeMultiplier}+ resizeMode="contain"+ session={session}+ style={resourceImageStyles.previewImage}+ />+ );+ }}/>) : null}<Pressable