Commit 70cdc6a
fix(transforms): enable transforms on new arch and fix hit testing on both arches (#2866)
## Summary
CSS transforms (`rotate`, `scale`, `translateX`, etc.) were not
rendering on macOS with the New Architecture (Fabric). This PR fixes the
root cause and related issues.
### Root Cause
On macOS, `NSView` has no built-in `transform` property (unlike `UIView`
on iOS). AppKit's layer-backed view system resets `layer.transform` to
identity during its layout/display cycle. This means any transform set
on the layer is silently discarded.
### Changes
**1. Add `transform3D` property to `RCTUIView` with anchor point and hit
testing fixes**
- Stores the transform in an ivar so it survives AppKit's reset
- Re-applies the transform in `updateLayer` (called during AppKit's
display phase)
- `wantsUpdateLayer` is conditional on having a custom transform or
`displayLayer:` delegate, so `drawRect:` still works for text views
- Compensates for macOS `layer.anchorPoint` defaulting to `{0, 0}`
instead of `{0.5, 0.5}`, so transforms apply from the view's center
- `hitTest:` and `RCTUIViewHitTestWithEvent` use `CALayer` coordinate
conversion, which correctly accounts for `layer.transform` (`NSView`'s
`convertPoint:fromView:` does not)
**2. Use `transform3D` in Fabric component views**
- `RCTViewComponentView` uses `self.transform3D` instead of
`self.layer.transform` on macOS
- Removes duplicated anchor point compensation and `hitTest:` override
now handled by `RCTUIView`
**3. Update Paper hit testing callers for transform-aware coordinate
conversion**
- Updates `RCTUIViewHitTestWithEvent` callers in Paper architecture to
use the new `fromView` parameter, enabling transform-aware hit testing
in old architecture as well
## Test Plan
- [x] Verified transforms render correctly on macOS Fabric: rotate,
scale, translateX, opacity, combined rotate+scale
- [x] Verified text still renders (conditional `wantsUpdateLayer`
prevents skipping `drawRect:`)
- [x] Verified hit testing works on transformed views (Pressable with
click counters)
- [x] Verified no regression on non-transformed views
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 85ab8c2 commit 70cdc6a
File tree
7 files changed
+67
-29
lines changed- packages/react-native/React
- Fabric/Mounting/ComponentViews
- ScrollView
- View
- Modules
- RCTUIKit
- Views
7 files changed
+67
-29
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
536 | 536 | | |
537 | 537 | | |
538 | 538 | | |
539 | | - | |
| 539 | + | |
540 | 540 | | |
541 | 541 | | |
542 | 542 | | |
| |||
Lines changed: 9 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
373 | 369 | | |
374 | 370 | | |
375 | | - | |
376 | 371 | | |
377 | 372 | | |
378 | 373 | | |
| |||
713 | 708 | | |
714 | 709 | | |
715 | 710 | | |
| 711 | + | |
716 | 712 | | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
717 | 716 | | |
718 | 717 | | |
719 | 718 | | |
| |||
807 | 806 | | |
808 | 807 | | |
809 | 808 | | |
810 | | - | |
| 809 | + | |
811 | 810 | | |
812 | 811 | | |
813 | 812 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1186 | 1186 | | |
1187 | 1187 | | |
1188 | 1188 | | |
1189 | | - | |
| 1189 | + | |
1190 | 1190 | | |
1191 | 1191 | | |
1192 | 1192 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| |||
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | | - | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
111 | 116 | | |
112 | | - | |
113 | 117 | | |
114 | | - | |
| 118 | + | |
115 | 119 | | |
116 | 120 | | |
117 | 121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| 25 | + | |
| 26 | + | |
24 | 27 | | |
25 | 28 | | |
26 | 29 | | |
| |||
51 | 54 | | |
52 | 55 | | |
53 | 56 | | |
| 57 | + | |
| 58 | + | |
54 | 59 | | |
55 | 60 | | |
56 | 61 | | |
| |||
127 | 132 | | |
128 | 133 | | |
129 | 134 | | |
130 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
131 | 156 | | |
132 | 157 | | |
133 | 158 | | |
134 | 159 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
139 | 170 | | |
140 | 171 | | |
141 | 172 | | |
142 | 173 | | |
143 | | - | |
| 174 | + | |
144 | 175 | | |
145 | 176 | | |
146 | 177 | | |
| |||
153 | 184 | | |
154 | 185 | | |
155 | 186 | | |
156 | | - | |
157 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
158 | 194 | | |
159 | 195 | | |
160 | 196 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
260 | | - | |
261 | | - | |
| 260 | + | |
262 | 261 | | |
263 | 262 | | |
264 | 263 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| |||
0 commit comments