Commit eef5827
authored
fix: Respect RN view layout and transforms within ForeignObject (#2811)
# Summary
Fixes: #2733 (`Bug1`, `Bug3`)
Fixes: #1428
Fixes: #2519
### Problem
When a React Native view (e.g., `<View>`, `<Text>`) is nested inside an
SVG `<ForeignObject>`, its own style properties like transform (scale,
rotate, translate) and its layout position are ignored during rendering.
This causes the nested view to be rendered incorrectly at the (0, 0)
origin of the` <ForeignObject>` without any of its applied
transformations, making it impossible to style or position elements
within the foreign object container.
### Solution
This PR fixes the issue by manually applying the child view's own
position and transformation matrix to the drawing context (the `Canvas`
on Android and `CGContext` on iOS) before the view is drawn.
On iOS we also reset `hidden` property to `false` for nested RN
components inside `ForeignObject` within `prepareForRecycle`. This
prevents views from being pooled in an invisible state and then
disappearing when they are subsequently reused on different screens.
With changes:
<img width="797" height="291" alt="image"
src="https://github.com/user-attachments/assets/1faf0645-7ee0-432b-99e9-28129ba13c1c"
/>
Before changes:
<img width="793" height="304" alt="image"
src="https://github.com/user-attachments/assets/c2ffce3d-ca05-4e76-baa6-75765a754958"
/>
## Test Plan
Run test case from issue: #27331 parent 0e08a39 commit eef5827
File tree
2 files changed
+43
-2
lines changed- android/src/main/java/com/horcrux/svg
- apple/Elements
2 files changed
+43
-2
lines changedLines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
113 | 125 | | |
| 126 | + | |
114 | 127 | | |
115 | 128 | | |
116 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
143 | 160 | | |
144 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
145 | 164 | | |
146 | 165 | | |
147 | 166 | | |
| |||
173 | 192 | | |
174 | 193 | | |
175 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
176 | 204 | | |
177 | 205 | | |
178 | 206 | | |
| |||
0 commit comments