microsoft / react-native-macos

A framework for building native macOS apps with React.
https://microsoft.github.io/react-native-windows/
MIT License
3.57k stars 138 forks source link

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

Closed Saadnajmi closed 4 days ago

Saadnajmi commented 5 days ago

This is part of a series of PRs where we are cherry-picking fixes from https://github.com/microsoft/react-native-macos/pull/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 https://github.com/facebook/react-native/pull/38626/ and https://github.com/facebook/react-native/pull/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)

https://github.com/user-attachments/assets/3f1ad39d-2e74-4e03-bc37-44e705d1bfed