Skip to content

Commit

Permalink
feat(android): implement getTotalLength and getPointAtLength
Browse files Browse the repository at this point in the history
  • Loading branch information
msand committed Oct 3, 2019
1 parent 78c4f20 commit cd667d0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions android/src/main/java/com/horcrux/svg/RNSVGRenderableManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

package com.horcrux.svg;

import android.graphics.PathMeasure;

import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
Expand Down Expand Up @@ -72,4 +74,25 @@ public void isPointInFill(int tag, ReadableMap options, Callback successCallback
float[] src = new float[] { x, y };
isPointInFill(tag, src, successCallback, 0);
}

@SuppressWarnings("unused")
@ReactMethod
public void getTotalLength(int tag, Callback successCallback) {
RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag);
PathMeasure pm = new PathMeasure(svg.getPath(null, null), false);
successCallback.invoke(pm.getLength());
}

@SuppressWarnings("unused")
@ReactMethod
public void getPointAtLength(int tag, ReadableMap options, Callback successCallback) {
float length = (float)options.getDouble("length");
RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag);
PathMeasure pm = new PathMeasure(svg.getPath(null, null), false);
float pathLength = pm.getLength();
float[] pos = new float[2];
float[] tan = new float[2];
pm.getPosTan(Math.max(0, Math.min(length, pathLength)), pos, tan);
successCallback.invoke(pos[0], pos[1]);
}
}

0 comments on commit cd667d0

Please sign in to comment.