refactor(transforms): simplify macOS transform logic on old and new architecture #2289
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.
This is part of a series of PRs where we are cherry-picking fixes from #2117 to update our Fabric implementation on macOS.
Summary:
For whatever reason, the default transform origin on iOS is the center of a view, while on macOS it is the top left corner. I think this is because
layer.anchorPoint
is getting nilled out into{0,0}
at some point. Regardless, because of this difference, we've maintained a diff to make the React Native macOS behavior matches iOS (See #1035 ). The diff involved storing the transform in an instance variable and manually applying a new transform on top to adjust the transform origin.As of React Native 0.73+, there is a new style prop
transformOrigin
(see facebook#38626 and facebook#38559 ) that involved adding a lot of the same logic to save and adjust the transform based on the newtransformOrigin
prop.Now that React Native upstream has that logic for adjusting transforms, let's remove the macOS specific diffs to do the same thing and reuse the iOS code. The only macOS diff left is simply adjusting the transform origin from top left to center.
Test Plan:
I lightly modified the TransformOrigin example in RN-Tester with a fixed border to better show the original view bounds, and then tried out different origins.
top-left
,center
, andtop-right
work as expected. Note on the new architecture, animations don't work so I haven't been able to test it there.macOS (Old architecture)
Screen.Recording.2024-11-20.at.4.06.20.PM.mov