Skip to content

Commit 47fe786

Browse files
fix(mobile): SVG markers with orient="auto-start-reverse" no longer crash Android
react-native-svg's Android MarkerView parsed any orient other than "auto" with Double.parseDouble, so a chat SVG whose <marker> used orient="auto-start-reverse" (or "45deg") threw NumberFormatException on the main thread. Upstream 15.16.1 still has the same code. Patch [email protected]: "auto-start-reverse" turns the start marker by 180 degrees and orients the others like "auto", and an orient that is not a number falls back to 0 instead of throwing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 71c2d3a commit 47fe786

3 files changed

Lines changed: 55 additions & 10 deletions

File tree

‎patches/[email protected]‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
diff --git a/android/src/main/java/com/horcrux/svg/MarkerView.java b/android/src/main/java/com/horcrux/svg/MarkerView.java
2+
index 8c796236f9f4b58717ac3fbab65e33d11ba032f2..d886e13d2cd1390a396716ecf4a379205e6a8aeb 100644
3+
--- a/android/src/main/java/com/horcrux/svg/MarkerView.java
4+
+++ b/android/src/main/java/com/horcrux/svg/MarkerView.java
5+
@@ -114,6 +114,17 @@ class MarkerView extends GroupView {
6+
}
7+
}
8+
9+
+ private static double parseOrientAngle(String orient) {
10+
+ if (orient == null) {
11+
+ return 0;
12+
+ }
13+
+ try {
14+
+ return Double.parseDouble(orient);
15+
+ } catch (NumberFormatException e) {
16+
+ return 0;
17+
+ }
18+
+ }
19+
+
20+
void renderMarker(
21+
Canvas canvas, Paint paint, float opacity, RNSVGMarkerPosition position, float strokeWidth) {
22+
int count = saveAndSetupCanvas(canvas, mCTM);
23+
@@ -122,8 +133,15 @@ class MarkerView extends GroupView {
24+
Point origin = position.origin;
25+
markerTransform.setTranslate((float) origin.x, (float) origin.y);
26+
27+
- double markerAngle = "auto".equals(mOrient) ? -1 : Double.parseDouble(mOrient);
28+
- float degrees = 180 + (float) (markerAngle == -1 ? position.angle : markerAngle);
29+
+ double markerAngle = position.angle;
30+
+ if ("auto-start-reverse".equals(mOrient)) {
31+
+ if (position.type == RNSVGMarkerType.kStartMarker) {
32+
+ markerAngle += 180;
33+
+ }
34+
+ } else if (!"auto".equals(mOrient)) {
35+
+ markerAngle = parseOrientAngle(mOrient);
36+
+ }
37+
+ float degrees = 180 + (float) markerAngle;
38+
markerTransform.preRotate(degrees);
39+
40+
boolean useStrokeWidth = "strokeWidth".equals(mMarkerUnits);

‎pnpm-lock.yaml‎

Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pnpm-workspace.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ overrides:
124124
react-native-keyboard-controller: 1.22.8
125125
react-native-pdf-jsi: 5.0.0
126126
react-native-webview: 14.0.1
127+
react-native-svg: 15.16.0
127128
"@expo/ui": 58.0.20
128129
"@expo/fingerprint": 0.21.5
129130
app-builder-lib: 26.16.1
@@ -266,6 +267,8 @@ patchedDependencies:
266267
267268
# A failed Artifacts.cached effect hangs every later caller: https://github.com/alchemy-run/alchemy/issues/2981
268269
270+
# Android: a marker orient other than "auto" or a number (auto-start-reverse) no longer throws.
271+
269272

270273
# Unmet peers fail resolution, so a pin outside a dependency's peer range is
271274
# caught when the lockfile changes instead of scrolling past as a warning.

0 commit comments

Comments
 (0)