Skip to content

fix transforms #280 - #460

Closed
Spencer Ahrens (sahrens) wants to merge 1 commit into
microsoft:mainfrom
sahrens:fixTransforms
Closed

fix transforms #280#460
Spencer Ahrens (sahrens) wants to merge 1 commit into
microsoft:mainfrom
sahrens:fixTransforms

Conversation

@sahrens

@sahrensSpencer Ahrens (sahrens) commented Jun 18, 2020

Copy link
Copy Markdown

Please select one of the following

  • I am removing an existing difference between facebook/react-native and microsoft/react-native-macos 👍
  • I am cherry-picking a change from Facebook's react-native into microsoft/react-native-macos 👍
  • I am making a fix / change for the macOS implementation of react-native
  • I am making a change required for Microsoft usage of react-native

Summary

This fixes#280 by making the effective origin of transforms {0.5, 0.5} with some additional matrix magic. I haven't been able to figure out why the anchorPoint default on macOS/NSView is {0, 0} rather than the iOS default {0.5, 0.5} (which matches the CALayer docs: https://developer.apple.com/documentation/quartzcore/calayer/1410817-anchorpoint)).

This also fixes application of the transform so it works on initial render. The underlying issue was that we were setting view.layer.transform directly (which is identified as undefined behavior in the NSView docs) and in practice doesn't work because the initial layer gets replaced after setting the initial values without copying the transform over to the new one, so it gets wiped out. The fix here is to save transform3D on the RCTView and apply it to the layer every time displayLayer: is called, along with all our existing custom layer rendering logic for border etc.

Changelog

[macOS] [Fixed] - fix transforms #280

Test Plan

BeforeAfter
imageimage
Microsoft Reviewers: Open in CodeFlow

@ghost

Deleted user (ghost) commented Jun 18, 2020

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@tom-un

Copy link
Copy Markdown
Collaborator

Thank you!

It looks like the change broke the FlatListExample in RNTester:

 FlatListExample, failed: caught "NSInternalInconsistencyException", "RedBox errors: Error setting property 'transform' of RCTSwitch with tag #25: Exception thrown while executing UI block: -[RCTSwitch setTransform3D:]: unrecognized selector sent to instance 0x60000309ad00"

I'll checkout your change locally to debug too.

Comment threadReact/Views/RCTView.h
*/
@property (nonatomic, assign) UIEdgeInsets hitTestEdgeInsets;

@property (nonatomic, assign) CATransform3D transform3D;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be inside the #if TARGET_OS_OSX block

@tom-un

Tom Underhill (tom-un) commented Jun 19, 2020

Copy link
Copy Markdown
Collaborator

I checked out your branch and debugged the test failure. It's crashing in RCTSwitch with an "undefined selector setTransform3d". RCTSwitch is a subclass of UISwitch/NSSwitch and uses the UIView+React category. So, the transform3d will have to be implemented in the category as well as RCTView otherwise any UIView+React based components could crash.

@kurdin

Copy link
Copy Markdown

Tom Underhill (@tom-un) any idea when this fix will be merged and available ? animations with transform rotation are broken right now

Satyajit Sahoo (satya164) added a commit to satya164/react-native-tab-view that referenced this pull request Jul 30, 2021
Using `react-native-pager-view` on macOS and Windows causes errors. Solution is to use `PanResponder` for these platforms (same with web).
Those platforms favors `.native.tsx` file over `.tsx` file which caused the errors. Solution is to use platform specific components for each.
macOS fixes:
Transform property is currently broken on `react-native-macos`. Temporary solution is to use `left` for indicator position. See: microsoft/react-native-macos#280
Windows fixes:
`PlatformPressable` is not pressable on Windows (only the label), I'm not sure why, but adding `backgroundColor: 'transparent'` to it makes the whole tab pressable.
### Motivation
`react-native-pager-view` does not support macOS and Windows.
### Test plan
Run on `react-native-macos` and `react-native-windows` projects.
Windows (initial):
![windows](https://user-images.githubusercontent.com/36528176/120261298-35feb780-c2ca-11eb-8755-845d539992ce.png)
Windows (swiping):
![windows2](https://user-images.githubusercontent.com/36528176/120261302-372fe480-c2ca-11eb-958e-b710f092e1ba.png)
macOS (initial):
<img width="489" alt="Screen Shot 2021-06-01 at 11 18 18 AM" src="https://user-images.githubusercontent.com/36528176/120262026-b671e800-c2cb-11eb-8337-c3bf792442ac.png">
macOS (swiping):
<img width="397" alt="Screen Shot 2021-06-01 at 11 19 32 AM" src="https://user-images.githubusercontent.com/36528176/120262036-ba056f00-c2cb-11eb-82d5-5fa8135e454c.png">
macOS (swiping): if microsoft/react-native-macos#460 is merged
<img width="391" alt="Screen Shot 2021-06-01 at 12 56 17 PM" src="https://user-images.githubusercontent.com/36528176/120268666-cfcd6100-c2d8-11eb-8ca7-97c260d07bee.png">
macOS (after swipe/swipe release):
<img width="494" alt="Screen Shot 2021-06-01 at 11 20 11 AM" src="https://user-images.githubusercontent.com/36528176/120262033-b8d44200-c2cb-11eb-8c4b-8207ddac74b2.png">
Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
@row248-hola

Copy link
Copy Markdown

Tom Underhill (@tom-un) Hi! Any updates on this PR? It will be great when transforms would work properly

@Saadnajmi

Copy link
Copy Markdown
Collaborator

Tom Underhill (@tom-un) Hi! Any updates on this PR? It will be great when transforms would work properly

Hello, Tom Underhill (@tom-un) no longer works in this repo actively. However, if I understand the description correctly, would this PR potentially also fix #767 ?

@row248-hola

Copy link
Copy Markdown

Hello, Tom Underhill (@tom-un) no longer works in this repo actively. However, if I understand the description correctly, would this PR potentially also fix #767 ?

Saad Najmi (@Saadnajmi)
Yeah, the same issue

@jdk

Jason Kotzin (jdk) commented Feb 21, 2022

Copy link
Copy Markdown

Tom Underhill (@tom-un) Are we waiting on the following:

'transform3d will have to be implemented in the category as well as RCTView'?

@Saadnajmi

Copy link
Copy Markdown
Collaborator

An FYI, I took over this PR in #1035 so if that lands, I'll close this one.

@jdk

Copy link
Copy Markdown

Saad Najmi (@Saadnajmi) Team tested #1035 and #1035 looks good.

Marc Robotham (forxnives) pushed a commit to forxnives/react-native-tab-view that referenced this pull request Apr 26, 2023
Using `react-native-pager-view` on macOS and Windows causes errors. Solution is to use `PanResponder` for these platforms (same with web).
Those platforms favors `.native.tsx` file over `.tsx` file which caused the errors. Solution is to use platform specific components for each.
macOS fixes:
Transform property is currently broken on `react-native-macos`. Temporary solution is to use `left` for indicator position. See: microsoft/react-native-macos#280
Windows fixes:
`PlatformPressable` is not pressable on Windows (only the label), I'm not sure why, but adding `backgroundColor: 'transparent'` to it makes the whole tab pressable.
### Motivation
`react-native-pager-view` does not support macOS and Windows.
### Test plan
Run on `react-native-macos` and `react-native-windows` projects.
Windows (initial):
![windows](https://user-images.githubusercontent.com/36528176/120261298-35feb780-c2ca-11eb-8755-845d539992ce.png)
Windows (swiping):
![windows2](https://user-images.githubusercontent.com/36528176/120261302-372fe480-c2ca-11eb-958e-b710f092e1ba.png)
macOS (initial):
<img width="489" alt="Screen Shot 2021-06-01 at 11 18 18 AM" src="https://user-images.githubusercontent.com/36528176/120262026-b671e800-c2cb-11eb-8337-c3bf792442ac.png">
macOS (swiping):
<img width="397" alt="Screen Shot 2021-06-01 at 11 19 32 AM" src="https://user-images.githubusercontent.com/36528176/120262036-ba056f00-c2cb-11eb-82d5-5fa8135e454c.png">
macOS (swiping): if microsoft/react-native-macos#460 is merged
<img width="391" alt="Screen Shot 2021-06-01 at 12 56 17 PM" src="https://user-images.githubusercontent.com/36528176/120268666-cfcd6100-c2d8-11eb-8ca7-97c260d07bee.png">
macOS (after swipe/swipe release):
<img width="494" alt="Screen Shot 2021-06-01 at 11 20 11 AM" src="https://user-images.githubusercontent.com/36528176/120262033-b8d44200-c2cb-11eb-8c4b-8207ddac74b2.png">
Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
Scott Judy (scottjudy) added a commit to scottjudy/react-native-tab-view that referenced this pull request Jun 20, 2023
Using `react-native-pager-view` on macOS and Windows causes errors. Solution is to use `PanResponder` for these platforms (same with web).
Those platforms favors `.native.tsx` file over `.tsx` file which caused the errors. Solution is to use platform specific components for each.
macOS fixes:
Transform property is currently broken on `react-native-macos`. Temporary solution is to use `left` for indicator position. See: microsoft/react-native-macos#280
Windows fixes:
`PlatformPressable` is not pressable on Windows (only the label), I'm not sure why, but adding `backgroundColor: 'transparent'` to it makes the whole tab pressable.
### Motivation
`react-native-pager-view` does not support macOS and Windows.
### Test plan
Run on `react-native-macos` and `react-native-windows` projects.
Windows (initial):
![windows](https://user-images.githubusercontent.com/36528176/120261298-35feb780-c2ca-11eb-8755-845d539992ce.png)
Windows (swiping):
![windows2](https://user-images.githubusercontent.com/36528176/120261302-372fe480-c2ca-11eb-958e-b710f092e1ba.png)
macOS (initial):
<img width="489" alt="Screen Shot 2021-06-01 at 11 18 18 AM" src="https://user-images.githubusercontent.com/36528176/120262026-b671e800-c2cb-11eb-8337-c3bf792442ac.png">
macOS (swiping):
<img width="397" alt="Screen Shot 2021-06-01 at 11 19 32 AM" src="https://user-images.githubusercontent.com/36528176/120262036-ba056f00-c2cb-11eb-82d5-5fa8135e454c.png">
macOS (swiping): if microsoft/react-native-macos#460 is merged
<img width="391" alt="Screen Shot 2021-06-01 at 12 56 17 PM" src="https://user-images.githubusercontent.com/36528176/120268666-cfcd6100-c2d8-11eb-8ca7-97c260d07bee.png">
macOS (after swipe/swipe release):
<img width="494" alt="Screen Shot 2021-06-01 at 11 20 11 AM" src="https://user-images.githubusercontent.com/36528176/120262033-b8d44200-c2cb-11eb-8c4b-8207ddac74b2.png">
Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
Rajendran Nadar (raajnadar) pushed a commit to raajnadar/react-navigation that referenced this pull request Jul 24, 2026
Using `react-native-pager-view` on macOS and Windows causes errors. Solution is to use `PanResponder` for these platforms (same with web).
Those platforms favors `.native.tsx` file over `.tsx` file which caused the errors. Solution is to use platform specific components for each.
macOS fixes:
Transform property is currently broken on `react-native-macos`. Temporary solution is to use `left` for indicator position. See: microsoft/react-native-macos#280
Windows fixes:
`PlatformPressable` is not pressable on Windows (only the label), I'm not sure why, but adding `backgroundColor: 'transparent'` to it makes the whole tab pressable.
### Motivation
`react-native-pager-view` does not support macOS and Windows.
### Test plan
Run on `react-native-macos` and `react-native-windows` projects.
Windows (initial):
![windows](https://user-images.githubusercontent.com/36528176/120261298-35feb780-c2ca-11eb-8755-845d539992ce.png)
Windows (swiping):
![windows2](https://user-images.githubusercontent.com/36528176/120261302-372fe480-c2ca-11eb-958e-b710f092e1ba.png)
macOS (initial):
<img width="489" alt="Screen Shot 2021-06-01 at 11 18 18 AM" src="https://user-images.githubusercontent.com/36528176/120262026-b671e800-c2cb-11eb-8337-c3bf792442ac.png">
macOS (swiping):
<img width="397" alt="Screen Shot 2021-06-01 at 11 19 32 AM" src="https://user-images.githubusercontent.com/36528176/120262036-ba056f00-c2cb-11eb-82d5-5fa8135e454c.png">
macOS (swiping): if microsoft/react-native-macos#460 is merged
<img width="391" alt="Screen Shot 2021-06-01 at 12 56 17 PM" src="https://user-images.githubusercontent.com/36528176/120268666-cfcd6100-c2d8-11eb-8ca7-97c260d07bee.png">
macOS (after swipe/swipe release):
<img width="494" alt="Screen Shot 2021-06-01 at 11 20 11 AM" src="https://user-images.githubusercontent.com/36528176/120262033-b8d44200-c2cb-11eb-8c4b-8207ddac74b2.png">
Co-authored-by: Satyajit Sahoo <satyajit.happy@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transforms

7 participants

@sahrens@tom-un@kurdin@row248-hola@Saadnajmi@jdk@kelset