The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 09:15 UTC
refactor(mobile): use shared Menu for markdown long presses (#20019)
Julius Marminge committed
Oct 15, 2026 at 15:51 UTC
9fbc753ec4033435719dd204f0ad7e6618fb962e
1 file changed
+26
-34
apps/mobile/src/native/EnrichedMarkdownText.tsx
+26
-34
@@ -5,8 +5,8 @@ import {
5
formatComposerContextReference,
6
} from "@t3tools/shared/composerContextReferences";
7
import { markdownWithHtml } from "../lib/markdownDocument";
8
-import { useCallback, useMemo, useState } from "react";
9
-import { ActionSheetIOS, Platform, Share, StyleSheet, View } from "react-native";
8
+import { useCallback, useMemo, useState, type ReactNode } from "react";
9
+import { Platform, Share, StyleSheet, View } from "react-native";
10
import {
11
EnrichedMarkdownText,
12
type DocumentAssetsEvent,
@@ -16,7 +16,7 @@ import {
16
import type { SelectableMarkdownTextProps } from "./SelectableMarkdownText.types";
17
18
import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
19
-import { AndroidAnchoredMenu } from "../components/AndroidAnchoredMenu";
19
+import { Menu } from "../components/Menu";
20
import { useEnrichedLinkVariants } from "./useEnrichedLinkVariants";
21
import { copyTextWithHaptic } from "../lib/copyTextWithHaptic";
22
import {
@@ -262,37 +262,20 @@ export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) {
262
[resolveImageSource],
263
);
264
const renderMarkdown = (openAndroidMenu?: () => void) => {
265
- const onLinkLongPress = props.fileContextMenu
266
- ? ({ url }: { url: string }) => {
267
- const menu = props.fileContextMenu?.(url) ?? {
268
- title: url,
269
- actions: [
270
- { id: "enriched-open-link", title: "Open link" },
271
- { id: "enriched-copy-link", title: "Copy link" },
272
- ],
273
- };
274
- const actions = menu.actions;
275
- if (Platform.OS === "ios") {
276
- ActionSheetIOS.showActionSheetWithOptions(
277
- {
278
- title: menu.title,
279
- options: [...actions.map((action) => action.title), "Cancel"],
280
- cancelButtonIndex: actions.length,
281
- disabledButtonIndices: actions.flatMap((action, index) =>
282
- action.disabled ? [index] : [],
283
- ),
284
- },
285
- (index) => {
286
- const action = actions[index];
287
- if (action && !action.disabled) performMenuAction(url, action.id);
288
- },
289
- );
290
- } else {
265
+ const onLinkLongPress =
266
+ Platform.OS === "android" && props.fileContextMenu
267
+ ? ({ url }: { url: string }) => {
268
+ const menu = props.fileContextMenu?.(url) ?? {
269
+ title: url,
270
+ actions: [
271
+ { id: "enriched-open-link", title: "Open link" },
272
+ { id: "enriched-copy-link", title: "Copy link" },
273
+ ],
274
+ };
275
setActiveMenu({ url, menu });
276
openAndroidMenu?.();
277
}
294
- }
295
- : undefined;
278
+ : undefined;
279
280
return (
281
<View
@@ -338,7 +321,8 @@ export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) {
321
};
322
323
return Platform.OS === "android" && props.fileContextMenu ? (
341
- <AndroidAnchoredMenu
324
+ <Menu
325
+ shouldOpenOnLongPress
326
title={activeMenu?.menu.title}
327
actions={
328
activeMenu?.menu.actions.map((action) => ({
@@ -352,9 +336,17 @@ export function MobileEnrichedMarkdownText(props: SelectableMarkdownTextProps) {
336
}}
337
style={{ flexShrink: 1, minWidth: 0 }}
338
>
355
- {renderMarkdown}
356
- </AndroidAnchoredMenu>
339
+ <MarkdownMenuAnchor renderMarkdown={renderMarkdown} />
340
+ </Menu>
341
) : (
342
renderMarkdown()
343
);
344
}
345
+
346
+/** Adapts the rich-text link gesture to Menu's long-press trigger without wrapping text in a Pressable. */
347
+function MarkdownMenuAnchor(props: {
348
+ readonly renderMarkdown: (openMenu?: () => void) => ReactNode;
349
+ readonly onLongPress?: () => void;
350
+}) {
351
+ return props.renderMarkdown(props.onLongPress);
352
+}