From 13acd7ed7e641f80c8cfecf949a96c336300d403 Mon Sep 17 00:00:00 2001 From: Michael Ortiz Date: Thu, 28 Apr 2016 15:47:50 -0700 Subject: [PATCH] Reverted commit D3234404 Summary: **Motivation**: Arc drawing has been broken on Android for some time. dgladkov submitted a PR, which ended up having a bug and was never merged. This PR should fix that bug as well as provide screenshots to prove it works. **Reproducing the Bug:** dgladkov made a simple test app which helps to illustrate the bug. The repo can be found [here](https://github.com/dgladkov/RNArtArcDrawingBug). The demo app illustrates that on iOS, wedges are drawn correctly, but Android only draws full circles. [Direct Link to iOS Before](https://github.com/dgladkov/RNArtArcDrawingBug/blob/master/images/ios.png). [Direct Link to Android Before](https://github.com/dgladkov/RNArtArcDrawingBug/blob/master/images/android.png). **Proof The Bug is Fixed:** [Here is a direct link to Android After pic.](http://i.imgur.com/9dTU2Xn.png) You can see the wedges match the iOS Before screenshot. **What went wrong:** dgladkov's solution relied on Java's modulus, which in fact, implements modulus in a non-standard way. Modulus should a Closes https://github.com/facebook/react-native/pull/7049 Differential Revision: D3234404 Pulled By: spicyj fb-gh-sync-id: 6b85eb42389da6c344ec9723c7f81f61473246b0 fbshipit-source-id: 6b85eb42389da6c344ec9723c7f81f61473246b0 --- .../react/views/art/ARTShapeShadowNode.java | 29 +++---------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTShapeShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTShapeShadowNode.java index 21d8849ad..ce8b5e136 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTShapeShadowNode.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/art/ARTShapeShadowNode.java @@ -191,20 +191,6 @@ public class ARTShapeShadowNode extends ARTVirtualNode { return false; } - /** - * 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 modulus = remainder; - if (remainder < 0) { - modulus += y; - } - return modulus; - } - /** * Creates a {@link Path} from an array of instructions constructed by JS * (see ARTSerializablePath.js). Each instruction starts with a type (see PATH_TYPE_*) followed @@ -246,18 +232,11 @@ public class ARTShapeShadowNode extends ARTVirtualNode { float r = data[i++] * mScale; float start = (float) Math.toDegrees(data[i++]); float end = (float) Math.toDegrees(data[i++]); - boolean clockwise = data[i++] == 1f; - float sweep = end - start; - if (Math.abs(sweep) > 360) { - sweep = 360; - } else { - sweep = modulus(sweep, 360); + boolean clockwise = data[i++] == 0f; + if (!clockwise) { + end = 360 - end; } - if (!clockwise && sweep < 360) { - start = end; - sweep = 360 - sweep; - } - + float sweep = start - end; RectF oval = new RectF(x - r, y - r, x + r, y + r); path.addArc(oval, start, sweep); break;