Skip to content

Position iOS inline views from their line's actual baseline (#59921) - #59921

Open
jasozh wants to merge 1 commit into
react:mainfrom
jasozh:export-D127932169
Open

jasozh wants to merge 1 commit into
react:mainfrom
jasozh:export-D127932169

Conversation

@jasozh

@jasozh jasozh commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Fixes an issue where inline views in text on iOS are not properly positioned from their actual baseline, resulting in situations where the view/image appears lower than expected or with less padding from the previous line.

Root Cause

After TextKit lays out the text, RCTTextLayoutManager tries to position an inline view's frame on the baseline. It does so by using glyphRect.origin.y + glyphRect.size.height to calculate the line bottom, then adding font.descender to derive the baseline. However, this fails in two cases. First, when a line only contains an attachment, the baseline should be the line bottom, but the current formula still adds font.descender which positions the view too high and clips into the previous line. Second, when lineHeight is set, text is lifted by an NSBaselineOffset to center it. The current formula fails to account for this offset, so inline views appear placed below the actual text baseline.

This PR

Modify RCTTextLayoutManager so that instead of manually computing the baseline, we ask TextKit for the baseline used on that line.

Changelog: [iOS][Fixed] - Fix inline views on iOS being misaligned from the baseline

Reviewed By: vzaidman

Differential Revision: D127932169

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 10, 2026
@meta-codesync

meta-codesync Bot commented Nov 10, 2026

Copy link
Copy Markdown

@jasozh has exported this pull request. If you are a Meta employee, you can view the originating Diff in D127932169.

)

Summary:

Fixes an issue where inline views in text on iOS are not properly positioned from their actual baseline, resulting in situations where the view/image appears lower than expected or with less padding from the previous line.

### Root Cause

After TextKit lays out the text, RCTTextLayoutManager tries to position an inline view's frame on the baseline. It does so by using `glyphRect.origin.y + glyphRect.size.height` to calculate the line bottom, then adding `font.descender` to derive the baseline. However, this fails in two cases. First, when a line only contains an attachment, the baseline should be the line bottom, but the current formula still adds `font.descender` which positions the view too high and clips into the previous line. Second, when `lineHeight` is set, text is lifted by an `NSBaselineOffset` to center it. The current formula fails to account for this offset, so inline views appear placed below the actual text baseline.

### This PR

Modify RCTTextLayoutManager so that instead of manually computing the baseline, we ask TextKit for the baseline used on that line.

Changelog: [iOS][Fixed] - Fix inline views on iOS being misaligned from the baseline

Reviewed By: vzaidman

Differential Revision: D127932169
@meta-codesync meta-codesync Bot changed the title Position iOS inline views from their line's actual baseline Position iOS inline views from their line's actual baseline (#59921) Nov 19, 2026
@github-actions

Copy link
Copy Markdown

Visual regression

No visual differences at f0a51cbf1153.

android: no capture

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant