Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(transforms): simplify macOS transform logic on old and new architecture #2289

Merged
merged 2 commits into from
Nov 21, 2024

Conversation

Saadnajmi
Copy link
Collaborator

@Saadnajmi Saadnajmi commented Nov 21, 2024

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 new transformOrigin 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, and top-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

Saadnajmi and others added 2 commits November 20, 2024 16:24
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
@Saadnajmi Saadnajmi requested a review from a team as a code owner November 21, 2024 00:57
@Saadnajmi Saadnajmi merged commit bf133b9 into microsoft:main Nov 21, 2024
14 checks passed
@Saadnajmi Saadnajmi deleted the fabric/transforms branch November 21, 2024 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants