Repository navigation
Conversation
`TextAttributes::operator==` compares every field except `lineBreakMode`, so text attributes that differ only in `lineBreakModeIOS` compare equal. react#46130 added the field to the struct and to `std::hash<TextAttributes>`, and left the operator as it was. An iOS `TextInput` decides with this operator whether its text attributes changed. `RCTTextInputComponentView updateProps:` sets the default text attributes of the field, which style the placeholder and typed text, only when the props' text attributes differ from the props the view already has. `BaseTextInputShadowNode::updateStateIfNeeded` gives the view new attributed text only when the attributed string differs from the one in the state. A change of `lineBreakModeIOS` alone therefore reaches neither the default text attributes nor the text. A recycled view keeps the props of the input it showed before, so an input that differs from that one only in `lineBreakModeIOS` keeps the default text attributes of the input before it. A newly created view is not affected: `<TextInput>` sends `allowFontScaling` (`true` unless the app passes another value), which differs from the view's initial props. The operator now compares `lineBreakMode`, so attributes that differ only in it no longer compare equal while hashing differently. `lineBreakModeIOS` is only in the iOS view config of `TextInput`, and only `RCTAttributedTextUtils.mm` turns `lineBreakMode` into a text style, so `<Text>` and Android never set it and are unaffected.
ide
force-pushed
the
@ide/text-attributes-line-break-mode
branch
from
December 2, 2026 03:51
6ba1733 to
ca0c41c
Compare
ide
marked this pull request as ready for review
December 2, 2026 05:17
This branch has not been deployed
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:
TextAttributes::operator==compares every field exceptlineBreakMode, so text attributes that differ only inlineBreakModeIOScompare equal. #46130 added the field to the struct and tostd::hash<TextAttributes>, and left the operator as it was.An iOS
TextInputdecides with this operator whether its text attributes changed:RCTTextInputComponentView updateProps:sets the default text attributes of the field, which style the placeholder and typed text, only when the props' text attributes differ from the props the view already has.BaseTextInputShadowNode::updateStateIfNeededgives the view new attributed text only when the attributed string differs from the one in the state.So on
main:lineBreakModeIOSalone reaches neither the default text attributes nor the text.prepareForRecycledoes not reset them), so an input that differs from that one only inlineBreakModeIOSkeeps the default text attributes of the input before it.Two inputs whose
lineBreakModeIOSchanges from"head"to"middle", one with a value and one with a placeholder. Left to right: before the change, after it onmain, and after it with this change.A newly created view is not affected:
<TextInput>sendsallowFontScaling(trueunless the app passes another value), which differs from the view's initial props.The operator now compares
lineBreakMode, so attributes that differ only in it no longer compare equal while hashing differently.lineBreakModeIOSis only in the iOS view config ofTextInput, and onlyRCTAttributedTextUtils.mmturnslineBreakModeinto a text style, so<Text>and Android never set it and are unaffected.Not changed: the measure cache's own comparison of text attributes (
areTextAttributesEquivalentLayoutWiseinTextMeasureCache.h) does not look atlineBreakModeorlineBreakStrategy. Whether a cached size can be wrong for them is not measured here.Changelog:
[IOS] [FIXED] - Apply a change of
lineBreakModeIOSto aTextInputwhen no other text style changes with itTest Plan:
C++
TextAttributesEqualityTest.everyFieldAffectsEquality, inTextAttributesTest.cpp, sets each field ofTextAttributesin turn and expects the result to differ from default attributes. Onmainit fails forlineBreakMode.The tests in
ReactCommonbuild against the Fantom tester's libraries and run with CTest, as in thetest_react_common_cxxjob:100% tests passed, 0 tests failed out of 1615on macOS (Apple clang 21).To run only this directory's tests after that:
All 21 pass. Each of these changes to
operator==failseveryFieldAffectsEquality, naming the field, and no other test:lineBreakModeis not compared (main's behavior)lineBreakModetextTransformis not comparedtextTransformletterSpacingis not comparedletterSpacingiOS
testChangeOfLineBreakModeAloneSetsDefaultTextAttributesin the newRCTTextInputComponentViewTestsgives anRCTTextInputComponentViewprops withallowFontScaling, as<TextInput>sends, and a line break mode, and reads the paragraph style of the field's default text attributes:"head"on a new view givesNSLineBreakByTruncatingHead."middle"givesNSLineBreakByTruncatingMiddle.prepareForRecycle, props with no line break mode give no paragraph style.With
lineBreakModetaken out ofoperator==again, step 2 still readsNSLineBreakByTruncatingHeadand step 3 still has the paragraph style of step 1.No CI job runs the tests in
React/Tests. I ran this one with Xcode 27.1 on an iOS 27.0 simulator (iPhone 18 Pro) after these local changes, which are not part of this PR::testspecs => ['Tests']on theReact-RCTFabricpod inscripts/cocoapods/fabric.rb; and inReact-RCTFabric.podspec, aswift_versionand a test spec that lists this file and an empty Swift file, which makes Xcode link the Swift runtime thatRCTSwiftUIneeds into the test bundle.Simulator
RNTester (Debug) on the same simulator, built from this branch and again with
TextAttributes.cppas onmain. The page isRNTesterPlayground.jsedited locally: two single-line inputs 280 pt wide with a 16 pt font, one with a value wider than the field and one with a placeholder that wide, and a timer that changeslineBreakModeIOSon both from"head"to"middle"and nothing else.Left to right: before the change; after it on
main, where the value and the placeholder still end at the head; after it with this change, where both have the ellipsis in the middle. The value shows the attributed text from the state and the placeholder shows the default text attributes.Not checked: the attributed text path through
updateStateIfNeededhas no unit test of its own; the simulator check above covers it. No device was used.