@devries-cameron20 / t3code Mirror · read-only / commits / 1a9336bcda
Fork 0

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 24, 02:45 UTC

refactor(mobile): name shared markdown renderer without iOS suffixes (#11128)

Dara Adedeji committed Sep 10, 2026 at 18:48 UTC 1a9336bcda98e75814c1985e9274d919e580dbc5
5 files changed +107 -122
apps/mobile/modules/t3-markdown-text/package.json
+1 -1
@@ -25,7 +25,7 @@
25 "./links": "./src/markdownLinks.ts",
26 "./markdown": "./src/nativeMarkdownText.ts",
27 "./primitive": "./src/MarkdownTextPrimitive.tsx",
28 - "./renderer": "./src/SelectableMarkdownText.ios.tsx",
28 + "./renderer": "./src/SelectableMarkdownText.tsx",
29 "./types": "./src/SelectableMarkdownText.types.ts"
30 },
31 "peerDependencies": {
apps/mobile/modules/t3-markdown-text/src/NativeMarkdownBlock.tsx renamed
+1 -1
@@ -5,7 +5,7 @@ import type { MarkdownNode } from "react-native-nitro-markdown/headless";
5 import { CopyTextButton } from "./CopyTextButton";
6 import { MarkdownTextPrimitive } from "./MarkdownTextPrimitive";
7 import { nativeMarkdownDocumentRuns, nativeMarkdownListItemBlocks } from "./nativeMarkdownText";
8 -import { NativeMarkdownSelectableText } from "./NativeMarkdownSelectableText.ios";
8 +import { NativeMarkdownSelectableText } from "./NativeMarkdownSelectableText";
9 import type {
10 MarkdownCodeHighlighter,
11 MarkdownHighlightedToken,
apps/mobile/modules/t3-markdown-text/src/NativeMarkdownSelectableText.tsx renamed
apps/mobile/modules/t3-markdown-text/src/SelectableMarkdownText.ios.tsx deleted
-117
@@ -1,117 +0,0 @@
1 -import { useMemo } from "react";
2 -import { View } from "react-native";
3 -import { parseMarkdownWithOptions } from "react-native-nitro-markdown/headless";
4 -
5 -import {
6 - nativeMarkdownChunkSpacing,
7 - nativeMarkdownDocumentChunks,
8 - nativeMarkdownDocumentRuns,
9 - nativeMarkdownWithPreservedSoftBreaks,
10 -} from "./nativeMarkdownText";
11 -import { MarkdownImageRendererContext, NativeMarkdownBlock } from "./NativeMarkdownBlock.ios";
12 -import {
13 - MarkdownFileContextMenuContext,
14 - NativeMarkdownSelectableText,
15 - type MarkdownFileContextMenuHandlers,
16 -} from "./NativeMarkdownSelectableText.ios";
17 -import type {
18 - SelectableMarkdownSkill,
19 - SelectableMarkdownTextProps,
20 -} from "./SelectableMarkdownText.types";
21 -
22 -const EMPTY_SKILLS: ReadonlyArray<SelectableMarkdownSkill> = [];
23 -
24 -export type {
25 - MarkdownCodeHighlighter,
26 - MarkdownHighlightedToken,
27 - MarkdownImageRenderer,
28 - MarkdownImageRequest,
29 - NativeMarkdownTextStyle,
30 - SelectableMarkdownSkill,
31 - SelectableMarkdownTextProps,
32 -} from "./SelectableMarkdownText.types";
33 -
34 -export function hasNativeSelectableMarkdownText(): boolean {
35 - return true;
36 -}
37 -
38 -export function SelectableMarkdownText({
39 - markdown,
40 - skills = EMPTY_SKILLS,
41 - textStyle,
42 - highlightCode,
43 - preserveSoftBreaks = false,
44 - onLinkPress,
45 - fileContextMenu,
46 - onFileContextMenuAction,
47 - renderImage,
48 - marginTop = 0,
49 - marginBottom = 0,
50 -}: SelectableMarkdownTextProps) {
51 - const chunks = useMemo(() => {
52 - const parsedDocument = parseMarkdownWithOptions(markdown, {
53 - gfm: true,
54 - html: true,
55 - math: false,
56 - });
57 - const document = preserveSoftBreaks
58 - ? nativeMarkdownWithPreservedSoftBreaks(parsedDocument)
59 - : parsedDocument;
60 - return nativeMarkdownDocumentChunks(document).map((chunk) =>
61 - chunk.kind === "selectable"
62 - ? {
63 - ...chunk,
64 - runs: nativeMarkdownDocumentRuns(chunk.node, skills),
65 - }
66 - : chunk,
67 - );
68 - }, [markdown, preserveSoftBreaks, skills]);
69 -
70 - const fileContextMenuHandlers = useMemo<MarkdownFileContextMenuHandlers | null>(
71 - () =>
72 - fileContextMenu && onFileContextMenuAction
73 - ? { fileContextMenu, onFileContextMenuAction }
74 - : null,
75 - [fileContextMenu, onFileContextMenuAction],
76 - );
77 -
78 - return (
79 - <MarkdownImageRendererContext.Provider value={renderImage ?? null}>
80 - <MarkdownFileContextMenuContext.Provider value={fileContextMenuHandlers}>
81 - {/* A percentage width here creates a cyclic intrinsic measurement inside
82 - shrink-to-fit containers such as user-message bubbles. Yoga then gives
83 - the native text node an unbounded second pass and the parent only clips
84 - the resulting single-line width instead of reflowing it. */}
85 - <View style={{ flexShrink: 1, minWidth: 0, marginTop, marginBottom }}>
86 - {chunks.map((chunk, index) => {
87 - const content =
88 - chunk.kind === "rich" ? (
89 - <NativeMarkdownBlock
90 - node={chunk.node}
91 - skills={skills}
92 - textStyle={textStyle}
93 - highlightCode={highlightCode}
94 - onLinkPress={onLinkPress}
95 - />
96 - ) : (
97 - <NativeMarkdownSelectableText
98 - runs={chunk.runs}
99 - textStyle={textStyle}
100 - onLinkPress={onLinkPress}
101 - />
102 - );
103 -
104 - return (
105 - <View
106 - key={chunk.key}
107 - style={{ paddingTop: nativeMarkdownChunkSpacing(chunks[index - 1], chunk) }}
108 - >
109 - {content}
110 - </View>
111 - );
112 - })}
113 - </View>
114 - </MarkdownFileContextMenuContext.Provider>
115 - </MarkdownImageRendererContext.Provider>
116 - );
117 -}
apps/mobile/modules/t3-markdown-text/src/SelectableMarkdownText.tsx
+105 -3
@@ -1,4 +1,25 @@
1 -import type { SelectableMarkdownTextProps } from "./SelectableMarkdownText.types";
1 +import { useMemo } from "react";
2 +import { View } from "react-native";
3 +import { parseMarkdownWithOptions } from "react-native-nitro-markdown/headless";
4 +
5 +import {
6 + nativeMarkdownChunkSpacing,
7 + nativeMarkdownDocumentChunks,
8 + nativeMarkdownDocumentRuns,
9 + nativeMarkdownWithPreservedSoftBreaks,
10 +} from "./nativeMarkdownText";
11 +import { MarkdownImageRendererContext, NativeMarkdownBlock } from "./NativeMarkdownBlock";
12 +import {
13 + MarkdownFileContextMenuContext,
14 + NativeMarkdownSelectableText,
15 + type MarkdownFileContextMenuHandlers,
16 +} from "./NativeMarkdownSelectableText";
17 +import type {
18 + SelectableMarkdownSkill,
19 + SelectableMarkdownTextProps,
20 +} from "./SelectableMarkdownText.types";
21 +
22 +const EMPTY_SKILLS: ReadonlyArray<SelectableMarkdownSkill> = [];
23
24 export type {
25 MarkdownCodeHighlighter,
@@ -10,6 +31,87 @@ export type {
31 SelectableMarkdownTextProps,
32 } from "./SelectableMarkdownText.types";
33
13 -export function SelectableMarkdownText(_props: SelectableMarkdownTextProps) {
14 - return null;
34 +export function hasNativeSelectableMarkdownText(): boolean {
35 + return true;
36 +}
37 +
38 +export function SelectableMarkdownText({
39 + markdown,
40 + skills = EMPTY_SKILLS,
41 + textStyle,
42 + highlightCode,
43 + preserveSoftBreaks = false,
44 + onLinkPress,
45 + fileContextMenu,
46 + onFileContextMenuAction,
47 + renderImage,
48 + marginTop = 0,
49 + marginBottom = 0,
50 +}: SelectableMarkdownTextProps) {
51 + const chunks = useMemo(() => {
52 + const parsedDocument = parseMarkdownWithOptions(markdown, {
53 + gfm: true,
54 + html: true,
55 + math: false,
56 + });
57 + const document = preserveSoftBreaks
58 + ? nativeMarkdownWithPreservedSoftBreaks(parsedDocument)
59 + : parsedDocument;
60 + return nativeMarkdownDocumentChunks(document).map((chunk) =>
61 + chunk.kind === "selectable"
62 + ? {
63 + ...chunk,
64 + runs: nativeMarkdownDocumentRuns(chunk.node, skills),
65 + }
66 + : chunk,
67 + );
68 + }, [markdown, preserveSoftBreaks, skills]);
69 +
70 + const fileContextMenuHandlers = useMemo<MarkdownFileContextMenuHandlers | null>(
71 + () =>
72 + fileContextMenu && onFileContextMenuAction
73 + ? { fileContextMenu, onFileContextMenuAction }
74 + : null,
75 + [fileContextMenu, onFileContextMenuAction],
76 + );
77 +
78 + return (
79 + <MarkdownImageRendererContext.Provider value={renderImage ?? null}>
80 + <MarkdownFileContextMenuContext.Provider value={fileContextMenuHandlers}>
81 + {/* A percentage width here creates a cyclic intrinsic measurement inside
82 + shrink-to-fit containers such as user-message bubbles. Yoga then gives
83 + the native text node an unbounded second pass and the parent only clips
84 + the resulting single-line width instead of reflowing it. */}
85 + <View style={{ flexShrink: 1, minWidth: 0, marginTop, marginBottom }}>
86 + {chunks.map((chunk, index) => {
87 + const content =
88 + chunk.kind === "rich" ? (
89 + <NativeMarkdownBlock
90 + node={chunk.node}
91 + skills={skills}
92 + textStyle={textStyle}
93 + highlightCode={highlightCode}
94 + onLinkPress={onLinkPress}
95 + />
96 + ) : (
97 + <NativeMarkdownSelectableText
98 + runs={chunk.runs}
99 + textStyle={textStyle}
100 + onLinkPress={onLinkPress}
101 + />
102 + );
103 +
104 + return (
105 + <View
106 + key={chunk.key}
107 + style={{ paddingTop: nativeMarkdownChunkSpacing(chunks[index - 1], chunk) }}
108 + >
109 + {content}
110 + </View>
111 + );
112 + })}
113 + </View>
114 + </MarkdownFileContextMenuContext.Provider>
115 + </MarkdownImageRendererContext.Provider>
116 + );
117 }