fix(ios): replace per-cell UITextView with single drawRect pass for tables#418
Draft
hryhoriiK97 wants to merge 1 commit into
Draft
fix(ios): replace per-cell UITextView with single drawRect pass for tables#418hryhoriiK97 wants to merge 1 commit into
hryhoriiK97 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR optimizes iOS table rendering by replacing per-cell UITextView creation with a single custom drawRect:-based grid view, aiming to eliminate main-thread hangs on large tables while keeping link interaction support.
Changes:
- Reworks iOS table rendering in
TableContainerViewto build row data and delegate drawing to a newENRMTableIOSGridView. - Adds
ENRMTableIOSGridView/ENRMTableIOSRowDatato render the whole table in onedrawRect:pass and perform on-demand link hit-testing on tap/long-press. - Updates iOS “new rows” animation to use a view-level cross-dissolve instead of per-cell alpha animations.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/react-native-enriched-markdown/ios/views/TableContainerView.m | Switches iOS tables to a single grid view renderer; builds per-row data for drawing and updates row animation hook. |
| packages/react-native-enriched-markdown/ios/views/ENRMTableIOSGridView.m | New iOS grid view implementation (drawing + gesture handling + link hit-testing). |
| packages/react-native-enriched-markdown/ios/views/ENRMTableIOSGridView.h | Public interface for the new iOS grid view + row data container. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+168
to
+173
| id linkValue = [text attribute:NSLinkAttributeName atIndex:charIndex effectiveRange:NULL]; | ||
| if ([linkValue isKindOfClass:[NSURL class]]) | ||
| return [(NSURL *)linkValue absoluteString]; | ||
| if ([linkValue isKindOfClass:[NSString class]]) | ||
| return linkValue; | ||
| return nil; |
Comment on lines
+161
to
+166
| NSUInteger glyphIndex = [layoutManager glyphIndexForPoint:local | ||
| inTextContainer:textContainer | ||
| fractionOfDistanceThroughGlyph:&fraction]; | ||
| NSUInteger charIndex = [layoutManager characterIndexForGlyphAtIndex:glyphIndex]; | ||
| if (charIndex >= text.length) | ||
| return nil; |
| CGFloat rowHeight = [_rowHeights[r] doubleValue]; | ||
| CGFloat xOffset = 0; | ||
|
|
||
| for (NSUInteger c = 0; c < rowData.cellTexts.count; c++) { |
Comment on lines
+48
to
+55
| _tableRows = rows; | ||
| _columnWidths = columnWidths; | ||
| _rowHeights = rowHeights; | ||
| _borderColor = borderColor; | ||
| _borderWidth = borderWidth; | ||
| _horizontalCellPadding = horizontalCellPadding; | ||
| _verticalCellPadding = verticalCellPadding; | ||
| [self setNeedsDisplay]; |
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.
What/Why?
Replace per-cell
UITextViewallocation in iOS table rendering with a singledrawRect:pass, eliminating multi-second AppHangs on large tables.Problem: Each table cell allocated a full
UITextViewwith its own TextKit stack (NSTextStorage,NSLayoutManager,NSTextContainer). Setting the frame triggered synchronous typesetting viaensureLayoutForBounds:per cell. A 200×7 table = 1,400 UITextViews blocking the main thread — 10–85s hangs in production, including fatal watchdog kills. Both the render path (addTextToCell:) and shadow-node measurement (renderMarkdownSynchronously:) were affected.Fix: New
ENRMTableIOSGridViewdraws all cells in onedrawRect:pass usingNSAttributedString.drawWithRect:— same approach macOS already uses viaENRMTableGridView. Link handling reimplemented with on-demand TextKit hit-testing (only on tap, not per-cell on render). Shadow-node measurement now creates one lightweight view instead of 1,400 UITextViews.Testing
PR Checklist