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
fix(mobile): keep a swiped preview from flashing the previous image
tianma-ifcbedcc0b4c30
diff --git a/apps/mobile/src/components/ZoomableImagePreview.tsx b/apps/mobile/src/components/ZoomableImagePreview.tsxindex b8b8ca54..31a466fe 100644--- a/apps/mobile/src/components/ZoomableImagePreview.tsx+++ b/apps/mobile/src/components/ZoomableImagePreview.tsx@@ -1,4 +1,4 @@-import { useCallback, useEffect, useState, type ReactNode } from "react";+import { useCallback, useEffect, useLayoutEffect, useState, type ReactNode } from "react";import { PixelRatio, Pressable, StyleSheet, Text, View } from "react-native";import { Gesture, GestureDetector, GestureHandlerRootView } from "react-native-gesture-handler";import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withSpring, withTiming } from "react-native-reanimated";@@ -19,7 +19,9 @@ type Props = {accessibilityLabel: string;currentIndex?: number;images?: PreviewImageItem[];+ nextImageLabel: string;onIndexChange?: (index: number) => void;+ previousImageLabel: string;onLongPress: () => void;renderImage: (onDimensions: (size: ImageSize) => void, resizeMultiplier: number) => ReactNode;};@@ -29,8 +31,10 @@ export const ZoomableImagePreview = ({accessibilityLabel,currentIndex = 0,images,+ nextImageLabel,onIndexChange,onLongPress,+ previousImageLabel,renderImage,}: Props) => {const [viewport, setViewport] = useState<ImageSize>({ width: 0, height: 0 });@@ -59,14 +63,18 @@ export const ZoomableImagePreview = ({const anchorX = useSharedValue(0);const anchorY = useSharedValue(0);const pinching = useSharedValue(false);+ const opacity = useSharedValue(1);const maxScale = 32;- useEffect(() => {+ useLayoutEffect(() => {setImage({ width: 0, height: 0 });scale.value = 1;x.value = 0;y.value = 0;pinching.value = false;+ // A completed swipe hides the outgoing image before this commit.+ // Reveal only after the new source is in place.+ opacity.value = 1;}, [currentSource, activeIndex]);useEffect(() => {@@ -146,18 +154,24 @@ export const ZoomableImagePreview = ({const dir = resolveSwipeDirection(event.translationX, event.translationY, event.velocityX, event.velocityY);const nextIndex = resolveNextPreviewIndex(activeIndex, total, dir);- if (nextIndex !== activeIndex) {+ if (nextIndex !== activeIndex && onIndexChange) {const isHorizontal = Math.abs(event.translationX) >= Math.abs(event.translationY);+ // Hide first, then recenter. Resetting while visible paints the+ // outgoing image in the middle before React swaps the source.if (isHorizontal) {const targetX = dir === "next" ? -viewport.width : viewport.width;- x.value = withTiming(targetX, { duration: 150 }, () => {+ x.value = withTiming(targetX, { duration: 150 }, (finished) => {+ if (finished === false) return;+ opacity.value = 0;x.value = 0;y.value = 0;runOnJS(onIndexChange)(nextIndex);});} else {const targetY = dir === "next" ? -viewport.height : viewport.height;- y.value = withTiming(targetY, { duration: 150 }, () => {+ y.value = withTiming(targetY, { duration: 150 }, (finished) => {+ if (finished === false) return;+ opacity.value = 0;x.value = 0;y.value = 0;runOnJS(onIndexChange)(nextIndex);@@ -183,6 +197,7 @@ export const ZoomableImagePreview = ({const gesture = Gesture.Race(Gesture.Simultaneous(pinch, pan), doubleTap, longPress);const animatedStyle = useAnimatedStyle(() => ({+ opacity: opacity.value,transform: [{ translateX: x.value }, { translateY: y.value }, { scale: scale.value }],}));@@ -206,7 +221,7 @@ export const ZoomableImagePreview = ({<>{activeIndex > 0 ? (<Pressable- accessibilityLabel="Previous image"+ accessibilityLabel={previousImageLabel}accessibilityRole="button"onPress={() => onIndexChange(activeIndex - 1)}style={[styles.navButton, styles.navButtonLeft]}@@ -216,7 +231,7 @@ export const ZoomableImagePreview = ({) : null}{activeIndex < total - 1 ? (<Pressable- accessibilityLabel="Next image"+ accessibilityLabel={nextImageLabel}accessibilityRole="button"onPress={() => onIndexChange(activeIndex + 1)}style={[styles.navButton, styles.navButtonRight]}@@ -239,28 +254,13 @@ export const ZoomableImagePreview = ({onLongPress();return;}- 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;- }+ 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;}}onLayout={(event) => setViewport(event.nativeEvent.layout)}style={styles.viewport}diff --git a/apps/mobile/src/screens/WorkspaceMemoDetail.tsx b/apps/mobile/src/screens/WorkspaceMemoDetail.tsxindex 9a8baa00..2dfd768c 100644--- a/apps/mobile/src/screens/WorkspaceMemoDetail.tsx+++ b/apps/mobile/src/screens/WorkspaceMemoDetail.tsx@@ -1910,6 +1910,8 @@ export const MemoDetailModal = ({}currentIndex={imagePreview.index}images={imagePreview.images}+ nextImageLabel={getMobileCatalog(resolvedLocale).mobile.memoDetail.nextImage}+ previousImageLabel={getMobileCatalog(resolvedLocale).mobile.memoDetail.previousImage}onIndexChange={(nextIndex) => {setImagePreview((previous) => {if (!previous || !previous.images[nextIndex]) return previous;diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.tsindex 443f1744..44f9f135 100644--- a/packages/shared/src/i18n/en-US.ts+++ b/packages/shared/src/i18n/en-US.ts@@ -3508,6 +3508,8 @@ export const enUS = {memoDetail: {closeImagePreview: "Close image preview",imageActionsHint: "Long press for image actions",+ nextImage: "Next image",+ previousImage: "Previous image",notSignedIn: "Not signed in.",noteActions: "Note actions",noteIdCopied: "Note ID copied",diff --git a/packages/shared/src/i18n/ja.ts b/packages/shared/src/i18n/ja.tsindex bd48125c..cc4c3928 100644--- a/packages/shared/src/i18n/ja.ts+++ b/packages/shared/src/i18n/ja.ts@@ -3497,6 +3497,8 @@ export const ja = {memoDetail: {closeImagePreview: "画像のプレビューを閉じる",imageActionsHint: "長押しで画像の操作を開きます",+ nextImage: "次の画像",+ previousImage: "前の画像",notSignedIn: "サインインしていません。",noteActions: "ノートの操作",noteIdCopied: "ノート ID をコピーしました",diff --git a/packages/shared/src/i18n/pl.ts b/packages/shared/src/i18n/pl.tsindex ba187efe..934be101 100644--- a/packages/shared/src/i18n/pl.ts+++ b/packages/shared/src/i18n/pl.ts@@ -3497,6 +3497,8 @@ export const pl = {memoDetail: {closeImagePreview: "Zamknij podgląd obrazu",imageActionsHint: "Przytrzymaj, aby otworzyć działania na obrazie",+ nextImage: "Następny obraz",+ previousImage: "Poprzedni obraz",notSignedIn: "Nie zalogowano.",noteActions: "Działania na notatce",noteIdCopied: "Skopiowano ID notatki",diff --git a/packages/shared/src/i18n/ru.ts b/packages/shared/src/i18n/ru.tsindex fba7106b..f3e297bd 100644--- a/packages/shared/src/i18n/ru.ts+++ b/packages/shared/src/i18n/ru.ts@@ -3508,6 +3508,8 @@ export const ru = {memoDetail: {closeImagePreview: "Закрыть просмотр изображения",imageActionsHint: "Удерживайте, чтобы открыть действия с изображением",+ nextImage: "Следующее изображение",+ previousImage: "Предыдущее изображение",notSignedIn: "Вход не выполнен.",noteActions: "Действия с заметкой",noteIdCopied: "ID заметки скопирован",diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.tsindex 967736aa..daed86e6 100644--- a/packages/shared/src/i18n/zh-CN.ts+++ b/packages/shared/src/i18n/zh-CN.ts@@ -3506,6 +3506,8 @@ export const zhCN = {memoDetail: {closeImagePreview: "关闭图片预览",imageActionsHint: "长按打开图片操作",+ nextImage: "下一张",+ previousImage: "上一张",notSignedIn: "未登录。",noteActions: "笔记操作",noteIdCopied: "笔记 ID 已复制",