Fixes CSS transform styles applied directly to <Text> components are silently ignored on iOS when using the new architecture#56002
Open
Adityakk9031 wants to merge 2 commits into
Open
Conversation
…silently ignored on iOS when using the new architecture
Author
|
@christophpurrer sir please have a look |
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.
Fixes #55306
Root Cause
On iOS, a node does not form a dedicated UIView by default. It is "flattened" into its parent component as an NSAttributedString fragment, controlled by the ShadowNodeTraits::Trait::FormsView flag. Since there is no backing UIView or CALayer, any transform prop applied to has nothing to act on and is silently ignored.
On Android, all nodes always set FormsView (unconditionally), which is why the transform works there — this asymmetry was the root cause.
cpp
// Before fix: FormsView only ever set on Android
static ShadowNodeTraits BaseTraits() {
auto traits = ConcreteShadowNode::BaseTraits();
#ifdef ANDROID
traits.set(ShadowNodeTraits::Trait::FormsView); // ← iOS never reaches here!
#endif
return traits;
}
Fix
Three files were changed:
TextProps.h
— Added Transform transform and TransformOrigin transformOrigin fields. Previously
TextProps
only inherited from
Props
+
BaseTextProps
(not
BaseViewProps
), so it had no transform field at all.
TextProps.cpp
— Parse transform and transformOrigin from raw JS props in the constructor and in
setProp
, mirroring
BaseViewProps
.
TextShadowNode.h
— On iOS, added a custom constructor that checks textProps->transform.operations.empty(). If the user supplied a transform, it sets ShadowNodeTraits::Trait::FormsView before delegating to BaseShadowNode, forcing Fabric to generate a real UIView for that text node so the transform can be applied.
This is zero-cost for non-transformed nodes — they continue to be flattened as before with no performance regression.
Changelog:
[IOS] [FIXED] - CSS transform styles applied to components are now correctly applied on iOS in the new architecture (Fabric), matching Android behavior.
Test Plan:
Repro steps (iOS Simulator, macOS + Xcode required)
Clone and build the RNTester app with this fix on an iOS Simulator.
Create a component with a directly-transformed :
jsx
<Text style={{ transform: [{ translateY: 50 }] }}>
Transformed text
Before fix: Text is not translated — it renders at its default position.
After fix: Text is translated 50pt downward, matching Android behavior.