Repository navigation
fix(mobile): render code blocks and tables in markdown - #281
Merged
Merged
Conversation
A horizontal ScrollView keeps React Native's default flexGrow: 1. Inside a fit-content parent such as a chat bubble (alignItems: flex-start) it took a runaway height on iOS and Android, so code blocks, tables and diff fences showed as a tall empty box. Sideways scrollers now never grow. The mobile renderer is rebuilt from small components and shares the lexer (with math), safe-link rules and inline-element sentinels with the web through @canopy/domain/markdown. It adds language labels, tables with columns and alignment, task lists, strike, italics in Inter, link and image rules from the web, raw HTML as text, math as TeX source, markdown in user messages with mention badges, and markdown bodies for prose tools. Related: #246, #276
nixuuu
added a commit
that referenced
this pull request
Nov 12, 2026
Wide Markdown tables can lose horizontal drags to navigation on iOS, while Android readers can be left with clipped columns. Tables, unwrapped code, display math and diffs now share a native Gesture Handler scroller with Android nested scrolling, a horizontal indicator and an overflow shadow. Main-stack back navigation starts at the screen edge; dragging inside a block keeps the conversation open. ### Diagnosis and change - The main Expo Router stack left `fullScreenGestureEnabled` unset. The installed `react-native-screens` 4.30.1 explicitly treats that state as **enabled on iOS 26** (`RNSScreen.mm`, `isFullScreenSwipeEffectivelyEnabled`), despite the router documentation describing a false default. Set it to false in the main stack, preserving the native edge recognizer and leaving `gestureEnabled` intact. This covers threads, side threads and bot conversations. - The timeline is an inverted Reanimated `FlatList`, with a native iOS scroll view and `KeyboardChatScrollView` on Android. Embedded tables/code/diffs used React Native horizontal `ScrollView`s without Android nested scrolling. Replace them with one `HorizontalScroll` using Gesture Handler's installed v3 `ScrollView`, `nestedScrollEnabled` and iOS directional locking; also enable nesting on the timeline. Its local gesture root supports blocks rendered inside Android modal viewers. No competing pan was found on timeline rows. Native reproduction was unavailable, so Android interception and the exact failing gesture sequence remain device checks. - The sidebar is a column toggled by a button, without a screen-wide drawer pan. #549's archive PanResponder is attached only to sidebar thread rows. #554's disclosure changes animate height and anchoring without adding a pan recognizer. Neither introduced this conflict. #281 introduced the table/code scroll containers with the current screens version and missing nesting/navigation restriction. - Bound both header and body column widths to 72–224 dp plus padding; long headings wrap too. Memoize width estimates and avoid spreading every row into `Math.max`. Tall tables retain natural height so vertical drags scroll the timeline. The 16 dp right-edge overflow shadow disappears at the right end and when content fits. Scroll offsets and shadow opacity stay on the UI thread through Reanimated; no per-frame JS callback, pan loop, list reconfiguration or item-height estimate is added. - Gesture Handler 3.3.0 was already locked, installed and autolinked on both platforms through the existing dependency graph. Declare that exact version directly in mobile; the lock change only adds the workspace dependency entry. No native package version, native source, app config or EAS profile changes. Polish mobile documentation updated. Copy audit (`docs/copy.md` §8): no UI strings changed. No UI tests or diagnostic artifacts added. ### Verification - `bun install --frozen-lockfile` passed, followed by `bunx expo install [email protected] --bun` using the already installed version. - Mobile `bun run typecheck`, root `bun run lint apps/mobile`, `bun run format:check apps/mobile docs/mobile.md`, and `git diff --check` pass. Expo ESLint passes for all six changed TSX files, including the new scroller. - Mobile `bun run lint` (Expo ESLint) reports 63 errors and 10 warnings in existing source files. An independent archive of untouched `dev` with the same installed tooling reports the same 63 source errors and 10 warnings (direct `eslint .` additionally checks `metro.config.cjs` and reports its existing `__dirname` diagnostic). All six changed TSX files have zero ESLint errors/warnings. Repository oxlint is clean. No lint rules were disabled. - Production fingerprints generated before and after in the same checkout/environment with `bunx [email protected] fingerprint:generate --platform <ios|android> --build-profile production --json --non-interactive` are byte-for-byte identical: iOS `6ddec9ef559ee0095ac33e94ff9418a942053b17`; Android `5f6eae3ab278f1cd543e9ed763f923a319b65ec9`. These match the prior production-compatible baseline; this remains JS-only. - No device session, native frame-time/memory measurement, UI test, full `check:tmp`, web build, CNG prebuild or bundle export was run. Device behavior/performance is **unverified**, not inferred from static checks. CI owns the full repository checks, as requested. ### Maintainer device checklist Use the same installed native build and same thread for baseline versus this branch's JS. Record OS/device, app version/runtime/update ID and channel. Include an iPhone on iOS 26 and an Android phone; check an older supported iOS version if available. Test light/dark, portrait/landscape and a wide layout with the sidebar open/closed. 1. **Horizontal ownership:** open a three-column table like `Zgłoszenie | Nowy status | Dlaczego…`, with enough text to overflow. Start 20 alternating horizontal drags on header text, body text and blank cell padding, away from the left screen edge. Drag left to reveal the last column, right from halfway to recover the first, then right again at offset zero. Every interior drag should stay in the conversation; every column must be reachable. Repeat in an assistant answer, a human message, a bot bubble and expanded tool/summary content. Include short cells, a very long heading, long unbroken text, and a table that fits entirely. 2. **Back/sidebar:** from a thread with a previous screen, swipe right starting within the leftmost 16 dp of the display; native back must still work. Cancel one edge swipe and complete another. Interior swipes must never navigate, including when already at the table's left end. Repeat in a side thread and bot conversation. Toggle the wide sidebar, scroll its list vertically, and confirm its archive swipe still works only on sidebar rows. 3. **Tall tables and vertical feed:** use a table at least two screen-heights tall. Drag vertically starting over header/body/padding and diagonally with mostly vertical movement, including while horizontally offset. The outer inverted timeline should move through the full table without trapping the gesture, clipping the settled content or folding the composer from a horizontal-only drag. Repeat with keyboard open/closed, during a streaming response, after loading older history, and after closing/reopening a work disclosure. Confirm jump-to-latest still works. 4. **Other blocks and affordance:** repeat interior horizontal drags on a long code line, display math, stacked and split diffs, and a full-diff modal viewer. Toggle Wrap code/Wrap diffs and confirm wrapped content still scrolls vertically. The horizontal indicator should appear during scrolling; the subtle right shadow should show only while content remains to the right, disappear at the end, and update after rotation/font-size changes. Check both themes and Reduce Motion; no content or controls should move when the shadow changes. Check VoiceOver/TalkBack can reach all content and ignores the decorative edge. 5. **Long-thread performance:** on the same device/build mode, compare baseline and changed JS on the same 1,000-turn thread with multiple tables/code/diffs. After warmup, record three 30-second vertical flings and 20 horizontal table drags in the native profiler. Compare dropped frames/UI frame time, JS activity and settled memory after opening/closing many summaries. Expect no new React render or JS callback per horizontal-scroll frame and no repeatable frame-pacing/memory regression; record the measured result before merging. Restore normal settings afterward. Fixes: #281 Related: #549 Related: #554
This was referenced Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
Code blocks (and tables,
difffences) used a horizontalScrollView, which keeps React Native's defaultflexGrow: 1. Inside a fit-content parent such as a bot chat bubble (alignItems: "flex-start"), the scroller takes a runaway height. The block then shows as a tall, empty box, and the text after it renders normally.Evidence: measured with
onLayoutin a temporary fixture screen (not committed) on an iOS 26.0 simulator and an Android 16 emulator (Canopy_Fold):ScrollView horizontal, padding on style)flexGrow: 0maxWidth/ withflexShrink: 0So the font (
monospaceon iOS), the inverted list and fixed heights were not the cause. Before the fix, every sample with a horizontal scroller measured ~1729 pt in the realChatBubble(code, empty code, long line, both tables, diff). After the fix they measure 90–412 pt. Android was affected too, not only iOS. Sideways scrollers in markdown andDiffnow setflexGrow: 0(docs/mobile.md notes the pitfall).Changes
@canopy/domain/markdown(new): the lexer with$…$/$$…$$math,safeHref,isTokenand the inline-element sentinels, moved fromapps/web/src/lib/shared/ui/markdownunchanged in behaviour. The web now imports them from there; mobile uses the same token tree and link rules.apps/mobile/src/ui/markdown/replaces the single-file renderer with small components:Markdown,Blocks,Inline,CodeFence,MarkdownList,MarkdownTable,scope,text-style.fontStyle, so italics showed upright.Facedkeeps weight and slant through nested text (bold italic, italic in a heading).UserMessageView).MarkdownBody) instead of a monospace output block.No new dependency:
markedwas already in mobile and web, and@canopy/domainnow declares it.Elements: web vs mobile (before → after)
headerrole~~)<del>"monospace"(not an iOS family)expo-clipboard, a native dependency; text is selectable)difffenceDiff, tall empty box in bubblesDiff, fixedcheckboxrole, Done / Not done)safeHref(adds mailto), others as text[Image: …]text$$as text)Where markdown renders on mobile
Agent messages (
AgentMessageView), bot chat bubbles (ChatBubble), reasoning and compaction summaries, checklists, subagent prompts/results, agent-bus instructions and messages, turn inputs from other origins (TurnInput), Typography settings preview: all throughMarkdown. New: user messages and prose tool bodies. Goals and notices on mobile show plain text, also on the web.Verification
development-simulatorbuild. Android emulator Canopy_Fold (Android 16) with an EASdevelopmentAPK. Both ran against my own Metro. The realChatBubble,AgentMessageViewandUserMessageViewwere rendered in the same inverted list setup as the bot chat, through a temporary fixture route (not committed). The fixture had one message per element and these edge cases: 200+ char code line, 10-column table, 4-level nested list, empty code block, long table cell,javascript:link, mentions inside code spans.https://example.com; tapping thejavascript:link did nothing.bun install,bun run gen:check,bun run typecheck,bun run lint,bun run format:check,bunx expo lint,bun run check:tmp(1499 pass, 0 fail, temp dir clean), web build.Not verified: a seeded gateway end to end (the fixture used the production components, not a paired gateway). Physical iPhone. Android phone width (the Fold was unfolded; phone width was checked on iOS). Interface font set to system/serif.
Copy audit (docs/copy.md §8)
All are short and in sentence case, with no glossary terms and no fact repeated. The checkbox state is not conveyed by colour alone: the check mark and the label carry it.