Repository navigation
Add unit tests for natural text alignment on iOS - #59004
Closed
YevheniiKotyrlo wants to merge 1 commit into
Closed
YevheniiKotyrlo wants to merge 1 commit into
YevheniiKotyrlo wants to merge 1 commit into
Conversation
Contributor
Author
YevheniiKotyrlo
marked this pull request as ready for review
October 12, 2026 05:05
zoontek
suggested changes
Oct 26, 2026
| BOOL isParagraphStyleUsed = NO; | ||
| const bool isRTL = textAttributes.layoutDirection == LayoutDirection::RightToLeft; | ||
| if (textAttributes.alignment.has_value() || isRTL) { | ||
| if (textAttributes.alignment.has_value() || textAttributes.layoutDirection.has_value()) { |
Contributor
There was a problem hiding this comment.
The line above (const bool isRTL = textAttributes.layoutDirection == LayoutDirection::RightToLeft;) could be moved inside the condition.
Contributor
Author
Contributor
There was a problem hiding this comment.
You can close this PR then.
YevheniiKotyrlo
marked this pull request as draft
October 26, 2026 20:21
RCTNSTextAttributesFromTextAttributes resolves a paragraph that declares no textAlign to the start edge of its layout direction, left to right as well as right to left (react#57634, react#59249), and leaves it to UIKit when the text attributes carry no layout direction, as a text input's do. Cover the three cases. The left-to-right one fails without react#59249, where the paragraph gets no paragraph style at all: a test that read only the alignment would pass there, since a nil paragraph style reads as NSTextAlignmentLeft.
YevheniiKotyrlo
force-pushed
the
fix/ios-natural-alignment-ltr
branch
from
October 26, 2026 21:42
00fef63 to
24bc565
Compare
Contributor
Author
|
Closing in favor of #59249, which landed this change. |
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.


Summary:
Adds tests for the alignment
RCTNSTextAttributesFromTextAttributesgives a paragraph that declares notextAlign. #57634 and #59249 resolve it to the start edge of the paragraph's layout direction, rather than leavingNSTextAlignmentNatural, which UIKit resolves against the app's localization, and neither added a test:testUndeclaredTextAlignmentResolvesWithLayoutDirection: a left-to-right paragraph is aligned left and a right-to-left one right. It asserts that the paragraph style exists, because a missing one reads asNSTextAlignmentLeft, so a check of the alignment alone would pass without [iOS] Resolve natural text alignment from the layout direction for LTR as well as RTL #59249.testUndeclaredTextAlignmentWithoutLayoutDirectionStaysNatural: text attributes with no layout direction, as a text input's, get no paragraph style, so aUITextFieldkeeps aligning to its own view.Changelog:
[Internal]
Test Plan:
RCTAttributedTextUtilsTestonmainat 19d6d17 with this change: 26 tests, 0 failures, on an iPhone 12 Pro Max (iOS 27.0.1, Xcode 27.1). The file belongs toReact-RCTFabric'sTeststest spec, which no Podfile enables, so for the run I added it toRNTesterUnitTests, hosted in RNTester.testUndeclaredTextAlignmentResolvesWithLayoutDirectionfails onmainbefore [iOS] Resolve natural text alignment from the layout direction for LTR as well as RTL #59249 (1c6e0c7) atXCTAssertNotNil(leftToRight):React-RCTFabric-Unit-Testson an iOS 18.0 simulator, 56 tests with 1 failure.yarn format-cppleaves the file unchanged.