fix ReactNativeART arc drawing on Android

fix ReactNativeART arc drawing on Android
This commit is contained in:
Horcrux
2016-04-23 23:23:15 +08:00
parent 5b630f1e4a
commit 81733043cf
2 changed files with 27 additions and 4 deletions
@@ -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;