|
9 | 9 |
|
10 | 10 | package com.horcrux.svg;
|
11 | 11 |
|
| 12 | +import android.graphics.PathMeasure; |
| 13 | + |
12 | 14 | import com.facebook.react.bridge.Callback;
|
13 | 15 | import com.facebook.react.bridge.ReactApplicationContext;
|
14 | 16 | import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
@@ -72,4 +74,25 @@ public void isPointInFill(int tag, ReadableMap options, Callback successCallback
|
72 | 74 | float[] src = new float[] { x, y };
|
73 | 75 | isPointInFill(tag, src, successCallback, 0);
|
74 | 76 | }
|
| 77 | + |
| 78 | + @SuppressWarnings("unused") |
| 79 | + @ReactMethod |
| 80 | + public void getTotalLength(int tag, Callback successCallback) { |
| 81 | + RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag); |
| 82 | + PathMeasure pm = new PathMeasure(svg.getPath(null, null), false); |
| 83 | + successCallback.invoke(pm.getLength()); |
| 84 | + } |
| 85 | + |
| 86 | + @SuppressWarnings("unused") |
| 87 | + @ReactMethod |
| 88 | + public void getPointAtLength(int tag, ReadableMap options, Callback successCallback) { |
| 89 | + float length = (float)options.getDouble("length"); |
| 90 | + RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag); |
| 91 | + PathMeasure pm = new PathMeasure(svg.getPath(null, null), false); |
| 92 | + float pathLength = pm.getLength(); |
| 93 | + float[] pos = new float[2]; |
| 94 | + float[] tan = new float[2]; |
| 95 | + pm.getPosTan(Math.max(0, Math.min(length, pathLength)), pos, tan); |
| 96 | + successCallback.invoke(pos[0], pos[1]); |
| 97 | + } |
75 | 98 | }
|
0 commit comments