You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: paint highlight ranges behind the rendered text (upstream #1218) - #17
This brings software-mansion#1218 to fork/t3-mobile, so that T3 Code can tint the paragraph and the word that read aloud speaks on mobile.
It adds three props to EnrichedMarkdownText:
highlights: UTF-16 ranges painted behind the rendered text.
onRenderedTextChange: sends the rendered text and its blocks.
onHighlightLayout: sends the rect of each range, so that the app can scroll to follow it.
A change to highlights does not parse or lay out the markdown again, and it does not change copied text. The details and limits are in software-mansion#1218.
The port to the fork needed no conflict fixes. The upstream branch needed some, because upstream's Android onDraw now draws text backgrounds.
Verification
Typecheck, eslint, jest, ktlint and the Android unit tests pass.
iOS XCTest runs 69 tests, and 3 of them are new.
I ran the Highlight example screen on an iPhone 17 Pro Max simulator (iOS 26.5) and a Pixel 8 emulator (Android 15), in light and dark mode. I also ran it in the T3 Code mobile app, with read aloud.
T3 Code uses a tarball of this branch (1.2.0-t3.18-3431ed09) in its read-aloud highlight PR, until this lands.
Model and harness: Claude Opus 5.5 in Claude Code.
Add a highlights prop to EnrichedMarkdownText: ranges of the rendered text
with a color, border radius and padding, drawn behind the glyphs on iOS
(TextKit 1 layout manager background pass) and Android (TextView onDraw,
before the text). The text, selection, copy and measuring do not change, and
moving a highlight does not render the Markdown again. In GitHub flavor, code
blocks and tables are tinted as a whole.
onRenderedTextChange reports the text the offsets index into and its blocks.
onHighlightLayout reports each highlight's box when it moves, so a screen can
scroll a highlighted word into view.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The change adds native text highlighting based on UTF-16 ranges in rendered Markdown text. iOS and Android report rendered text with block offsets and emit highlight layout rectangles. The TypeScript API exposes the highlight props and callbacks. Tests and documentation cover the API and native coordination. The example app adds a screen that highlights words as playback advances.
Highlights in Android CommonMark code blocks can cover the text itself instead of sitting behind it, which breaks the main feature in that case. Highlight indices can also shift when an entry is ignored, and Android can report stale rendered text after a render failure. These are worth fixing before merge; most other findings are minor edge cases.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: adding paintable highlight ranges behind rendered text in the react-native-enriched-markdown package, which the changeset implements across JS props, Android, and iOS.…
Description check
The description states the purpose: porting upstream #1218 to the fork so T3 Code can tint paragraphs and spoken words. It lists the three new props (highlights, onRenderedTextChange, onHighlightLayou…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: adding paintable highlight ranges behind rendered text in the react-native-enriched-markdown package, which the changeset implements across JS props, Android, and iOS. It also notes the upstream PR reference. The title is specific and accurate, though it does not mention the new rendered-text and highlight-layout callbacks.
Full details: Description check
Explanation
The description states the purpose: porting upstream #1218 to the fork so T3 Code can tint paragraphs and spoken words. It lists the three new props (highlights, onRenderedTextChange, onHighlightLayout), which match the changeset. It also covers verification steps. It is related to the changeset in detail.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 7
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
⚠️ Outside diff range comments (1)
Minor · Update highlight metadata when a render failure clears the text. · EnrichedMarkdownText.kt:328
packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/EnrichedMarkdownText.kt:328 Minor · Data Integrity & Integration · Quick win
Update highlight metadata when a render failure clears the text.
After a successful render, these failure paths clear text without updating highlightCoordinator. If a listener is then enabled, setEnableRenderedTextChange emits the previous text and blocks although the view is empty. The event contract requires the text that the view shows. (raw.githubusercontent.com)
Route both clears through a helper that also refreshes coordinator state, emits the empty rendered-text snapshot when enabled, and schedules geometry reporting. Keep the existing render-ID and attachment guards.
Also applies to: 346-346
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: a3b7ded1-9253-420e-9e4a-a66e58457283
Commits
Reviewing files that changed from the base of the PR and between 497fbe6 and 3431ed0.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
Callback fired after each render with the text as the view shows it, which [`highlights`](#highlights) offsets index into. It differs from the Markdown source (list markers, quotes and code fences are not in it) and can differ between iOS and Android, so read it on each platform rather than computing it. Blocks are joined with `\n`; a table's cells are joined with tabs and its rows with newlines.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Describe change-based callback delivery.
On iOS, changing Markdown from **Hello** to Hello renders again but does not emit this callback. The coordinator detects identical rendered text and block metadata, so the view suppresses the event. “After each render” therefore promises a notification that callers do not receive. (raw.githubusercontent.com)
Document change-based delivery here and in the matching API reference and prop comments. If delivery after every native render is required, change the emission guard instead.
The reason will be displayed to describe this comment to others. Learn more.
Major · Functional Correctness · Heavy lift
Draw highlight fills before the glyphs, not after them.
For a CommonMark fenced code block, CodeBlockSpan implements LineBackgroundSpan, so drawOverBackgrounds fills the highlighted glyph area after super.onDraw has drawn the text. An opaque highlight hides the glyphs. A translucent highlight changes the glyph color instead of only the background. (raw.githubusercontent.com)
Integrate this fill between syntax-background drawing and glyph/selection drawing. Moving it before all backgrounds would make opaque syntax backgrounds hide the highlight again.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Keep separate bidi selection rectangles when painting.
On one LTR line containing abc אבג def, range [0,5) selects abc א. Android creates separate rectangles for the directional runs. This bounding rectangle also covers the unselected בג between them, so those characters receive the highlight. Preserve the separate rectangles for drawing. Use their union only for bounds(). (raw.githubusercontent.com)
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Use separate enclosing rectangles for bidirectional ranges.
In LTR text abc אבג def, UTF-16 range [2,5) selects c א. The selected glyphs occupy separate visual pieces. This single bounding rectangle also covers the unselected ב and ג between them. Apple specifies that this API returns one rectangle enclosing all requested glyphs. (developer.apple.com)
Use enumerateEnclosingRectsForGlyphRange:withinSelectedGlyphRange:inTextContainer:usingBlock: to retain separate visual pieces. Apply padding and rounding to each rectangle. The existing bounds consumer can still union them. Single-direction ranges continue to produce one background. Apple documents enclosing rectangles for drawing range highlights. (developer.apple.com)
The reason will be displayed to describe this comment to others. Learn more.
Minor · Data Integrity & Integration · Quick win
Preserve highlight indices when ignoring empty ranges.
For text hello, pass [0,0) followed by [0,5), both with plain colors. JS retains both entries. This conversion removes the first entry, so the coordinator reports the second highlight as index: 0. The public contract defines this index as the entry's position in highlights; it must remain 1. (raw.githubusercontent.com)
Preserve the original index through conversion, or retain a non-drawing placeholder. Apply the same correction to Android's parseTextHighlights, which also compacts these entries. (raw.githubusercontent.com)
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Invalidate the full padded area when a highlight changes.
The setter invalidates only the line fragments that span each highlight and its adjacent glyphs. The background pass draws each highlight box expanded by padding. When the padding extends a box past those adjacent lines, the outer part of the old tint lies outside the invalidated region. Removing or moving that highlight can then leave tint on lines that are not redrawn.
Invalidate the line fragments that the padded rectangle covers, not only the adjacent ones.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Data Integrity & Integration · Quick win
Preserve highlight indices when an entry is ignored.
If the first entry has an unprocessable color and the second entry is valid, this continue moves the valid entry to native index 0. Both native coordinators report that compacted index, and handleHighlightLayout forwards it unchanged. The public contract requires index 1, so a scroll-following handler can select the wrong highlight or miss it. (raw.githubusercontent.com)
Retain an original-index mapping through normalization and translate layout indices before calling the public callback. Account for native range filtering too. Keep the identity mapping when every entry is valid.
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
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.
This brings software-mansion#1218 to
fork/t3-mobile, so that T3 Code can tint the paragraph and the word that read aloud speaks on mobile.It adds three props to
EnrichedMarkdownText:highlights: UTF-16 ranges painted behind the rendered text.onRenderedTextChange: sends the rendered text and its blocks.onHighlightLayout: sends the rect of each range, so that the app can scroll to follow it.A change to
highlightsdoes not parse or lay out the markdown again, and it does not change copied text. The details and limits are in software-mansion#1218.The port to the fork needed no conflict fixes. The upstream branch needed some, because upstream's Android
onDrawnow draws text backgrounds.Verification
T3 Code uses a tarball of this branch (
1.2.0-t3.18-3431ed09) in its read-aloud highlight PR, until this lands.Model and harness: Claude Opus 5.5 in Claude Code.