diff --git a/README.md b/README.md index fa78069e..4f2a07f0 100644 --- a/README.md +++ b/README.md @@ -562,6 +562,7 @@ npm install 4. [morph animations](https://github.com/gorangajic/react-svg-morph) 5. fix propTypes 6. more Text features support +7. support percent props #### Thanks: diff --git a/android/src/main/java/com/horcrux/svg/RNSVGVirtualNode.java b/android/src/main/java/com/horcrux/svg/RNSVGVirtualNode.java index 5f1029fe..056b6057 100644 --- a/android/src/main/java/com/horcrux/svg/RNSVGVirtualNode.java +++ b/android/src/main/java/com/horcrux/svg/RNSVGVirtualNode.java @@ -164,6 +164,20 @@ public abstract class RNSVGVirtualNode extends ReactShadowNode { mMatrix.setValues(sRawMatrix); } + /** + * Returns the floor modulus of the float arguments. Java modulus will return a negative remainder + * when the divisor is negative. Modulus should always be positive. This mimics the behavior of + * Math.floorMod, introduced in Java 8. + */ + private float modulus(float x, float y) { + float remainder = x % y; + float ret = remainder; + if (remainder < 0) { + ret += y; + } + return ret; + } + /** * Creates a {@link Path} from an array of instructions constructed by JS * (see RNSVGSerializablePath.js). Each instruction starts with a type (see PATH_TYPE_*) followed @@ -206,11 +220,19 @@ public abstract class RNSVGVirtualNode extends ReactShadowNode { float r = data[i++] * mScale; float start = (float) Math.toDegrees(data[i++]); float end = (float) Math.toDegrees(data[i++]); - boolean clockwise = data[i++] == 0f; - if (!clockwise) { - end = 360 - end; + + boolean clockwise = data[i++] == 1f; + float sweep = end - start; + if (Math.abs(sweep) > 360) { + sweep = 360; + } else { + sweep = modulus(sweep, 360); } - float sweep = start - end; + if (!clockwise && sweep < 360) { + start = end; + sweep = 360 - sweep; + } + RectF oval = new RectF(x - r, y - r, x + r, y + r); path.addArc(oval, start, sweep); break;