Skip to content

Fix iOS text positioning for center and right alignment - #437

Open
ldalzottomp wants to merge 3 commits into
JimmyDaddy:masterfrom
ldalzottomp:ldz/ios-wrong-alignment
Open

ldalzottomp wants to merge 3 commits into
JimmyDaddy:masterfrom
ldalzottomp:ldz/ios-wrong-alignment

Conversation

@ldalzottomp

@ldalzottomp ldalzottomp commented Sep 14, 2026 •

Copy link
Copy Markdown

Summary

Multiline text on iOS can shift outside its background or get clipped when using center or right alignment.

In one of my example.
When switching from left to right text alignment, textBounds.origin.x changed from 0 to 683.95, while self.size remained (853, 117). Drawing the container at the requested origin (663, 1911) therefore shifted the text horizontally.

This PR subtract the text bounds origin before drawing glyphs and backgrounds. To counter the fact that layoutManager.drawBackground and layoutManager.drawGlyphs re-apply the textBounds.origin.

An additional UI manual test has been implemented (commit 6038e2a).
Showcasing the issue. You can checkout the commit and test the example app for the repro.

Before
Screenshot 2026-09-14 at 13 50 19

After
Screenshot 2026-09-14 at 13 49 26

Validation

  • yarn test
  • yarn typecheck
  • yarn lint
  • example/ios/ImageMarkerExampleUITests/ImageMarkerExampleUITests.swift tests ran via xcode

@ldalzottomp
ldalzottomp marked this pull request as draft September 14, 2026 11:58
@ldalzottomp
ldalzottomp force-pushed the ldz/ios-wrong-alignment branch from 7ead513 to c8d970c Compare September 14, 2026 12:16
@ldalzottomp
ldalzottomp marked this pull request as ready for review September 14, 2026 12:17
);
}

async function runMultilineTextAlignmentFeature() {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer, this function has been autogenerated. The issue is reproduced without the fix (see the images in the PR description)

@ldalzottomp
ldalzottomp marked this pull request as draft September 14, 2026 12:19
@ldalzottomp
ldalzottomp force-pushed the ldz/ios-wrong-alignment branch from c8d970c to a53414d Compare September 14, 2026 12:21
@ldalzottomp
ldalzottomp marked this pull request as ready for review September 14, 2026 12:22
@ldalzottomp
ldalzottomp force-pushed the ldz/ios-wrong-alignment branch from a53414d to dbc51a2 Compare September 14, 2026 12:28

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant