refactor(transforms): simplify macOS transform logic on old and new architecture#2289
Merged
Saadnajmi merged 2 commits intomicrosoft:mainfrom Nov 21, 2024
Merged
Conversation
Summary: On macOS, Core Animation layers have their anchor point set to (0,0) which is the top-left. On iOS the anchor point is set to (0.5, 0.5) which matches the center. Transforms assigned to views are built based on having the anchor point at the center. This diff updates the transform matrix to apply to transform from the center. Test Plan: Check zoom/rotation animations in Zeratul. | Before | After | |--| | https://pxl.cl/3G8HG | https://pxl.cl/3G8HQ | Reviewers: shawndempsey, #rn-desktop Reviewed By: shawndempsey Differential Revision: https://phabricator.intern.facebook.com/D50628807 Tasks: T161413049
JunielKatarn
approved these changes
Nov 21, 2024
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.
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.anchorPointis 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 newtransformOriginprop.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-rightwork 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