Skip to content

Commit c6788bc

Browse files
fix: setting invMatrix during setTransforms for iOS (#2810)
# Summary Fixes: #2809 1. Fix `setTransform` to correctly update `_invmatrix` for hit testing. Previously, the `setTransforms` setter in `RNSVGNode` updated the `_matrix` property but did not recompute the `_invmatrix`. As a result, hit testing on iOS could become inaccurate when transforms were applied via Reanimated’s `animatedProps`, because the visual transform `_matrix` and the cached inverse `_invmatrix` were out of sync. This PR modifies `setTransforms` to update `_matrix` through its setter ensuring that `_invmatrix` is recomputed properly whenever the transforms changes. 2. Remove unused `invTransform` from `VirtualView.java`. ## Test Plan Run example from issue #2809
1 parent f0dd1a0 commit c6788bc

6 files changed

Lines changed: 1 addition & 11 deletions

File tree

android/src/main/java/com/horcrux/svg/GroupView.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ int hitTest(final float[] src) {
274274

275275
float[] dst = new float[2];
276276
mInvMatrix.mapPoints(dst, src);
277-
mInvTransform.mapPoints(dst);
278277

279278
int x = Math.round(dst[0]);
280279
int y = Math.round(dst[1]);

android/src/main/java/com/horcrux/svg/RenderableView.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,6 @@ int hitTest(final float[] src) {
701701

702702
float[] dst = new float[2];
703703
mInvMatrix.mapPoints(dst, src);
704-
mInvTransform.mapPoints(dst);
705704
int x = Math.round(dst[0]);
706705
int y = Math.round(dst[1]);
707706

android/src/main/java/com/horcrux/svg/TSpanView.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,6 @@ int hitTest(final float[] src) {
12181218

12191219
float[] dst = new float[2];
12201220
mInvMatrix.mapPoints(dst, src);
1221-
mInvTransform.mapPoints(dst);
12221221
int x = Math.round(dst[0]);
12231222
int y = Math.round(dst[1]);
12241223

android/src/main/java/com/horcrux/svg/UseView.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ int hitTest(float[] src) {
107107

108108
float[] dst = new float[2];
109109
mInvMatrix.mapPoints(dst, src);
110-
mInvTransform.mapPoints(dst);
111110

112111
VirtualView template = getSvgView().getDefinedTemplate(mHref);
113112
if (template == null) {

android/src/main/java/com/horcrux/svg/VirtualView.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public abstract class VirtualView extends ReactViewGroup {
5757
Matrix mMatrix = new Matrix();
5858
Matrix mInvCTM = new Matrix();
5959
Matrix mInvMatrix = new Matrix();
60-
final Matrix mInvTransform = new Matrix();
6160
boolean mInvertible = true;
6261
boolean mCTMInvertible = true;
6362
private RectF mClientRect;

apple/RNSVGNode.mm

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,7 @@ - (void)setMatrix:(CGAffineTransform)matrix
266266

267267
- (void)setTransforms:(CGAffineTransform)transforms
268268
{
269-
if (CGAffineTransformEqualToTransform(transforms, _matrix)) {
270-
return;
271-
}
272-
273-
_matrix = transforms;
274-
[self invalidate];
269+
self.matrix = transforms;
275270
}
276271

277272
- (void)setClientRect:(CGRect)clientRect

0 commit comments

Comments
 (0)