-
Notifications
You must be signed in to change notification settings - Fork 25k
Fix ReactNativeART arc drawing on Android #7049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks! |
|
To be fair, lots of languages implement |
| if (!clockwise) { | ||
| end = 360 - end; | ||
| start = end; | ||
| sweep = 360 - sweep; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If start === end already and sweep is 0, is this correct?
|
@spicyj Good catch. That edge case would create a full circle in counter-clockwise mode. I have a fix in place, but first a question: what is the expected result of an arc with startAngle = -360 and endAngle = 20? In my implementation, the result is a full circle, but I guess the argument could be made for a 20 degree arc. The ART docs, unfortunately, do not describe Path.arc(). |
|
@MikeOrtiz updated the pull request. |
|
I decided it was best to mimic the behavior of iOS. If the sweep > 360, then a full circle is always drawn. If sweep = 0, no wedge is drawn. Comparison screenshots: iOS and Android. The start/end angles are as follows: Blue: start: 120, end: 220 |
|
@MikeOrtiz updated the pull request. |
|
@MikeOrtiz updated the pull request. |
|
@spicyj, I realized I didn't mention you in my last post. Not sure if that makes a difference. |
|
The post isn't yet tagged as such, but I have signed the CLA. |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
|
Assigning to @spicyj who started reviewing this PR. |
|
Hooray :) This is a blocker for my project. |
|
Can you say whether this matches the SVG behavior now? I am fairly sure that is what ART intends to do for this path component. |
|
The fixed behavior seems to conform to intentions. The repo provided uses the Wedge component from react-art, in any case. |
|
Yeah, that seems fair. @facebook-github-bot shipit |
|
@facebook-github-bot shipit |
|
Thanks for importing. If you are an FB employee go to Phabricator to review. |
|
It looks like this breaks circle rendering: (where Circle.art comes from https://github.com/reactjs/react-art/blob/d1eda4fd8e3ee9462c32d2f611923697195fee14/src/Circle.art.js). There should not be a line in the middle. I have to revert this commit (13acd7e), but would you want to send a follow-up that fixes this? |
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 #7049 Differential Revision: D3234404 Pulled By: spicyj fb-gh-sync-id: 6b85eb42389da6c344ec9723c7f81f61473246b0 fbshipit-source-id: 6b85eb42389da6c344ec9723c7f81f61473246b0
|
Aww, yeah I'll look into it. When should I submit the fix to get it in for the upcoming release? |
|
I think we cut a release every other Sunday, including this weekend. |
|
I just ran this on my machine and it looks fine. This is what it looks like for me. The call to close() in Circle.art is what will create the line segment to close off the final arc. If the path ends at the same point that it starts, there will be no line segment. This functionality is described in the Android Path docs here. The arcs are centered around the same coordinate and the second ends at the same angle the first begins, so the starting points should be identical. I printed some logs of Circle.art to confirm that fact: I don't understand how you got this rendering, but I can't reproduce it. One simple fix would be to remove the call to close() in Circle.art as it doesn't achieve anything, anyway. |
|
Hm, I'm not sure. I was testing on a Nexus 4 simulator on 4.4.4 (API 19). |
|
Sounds good. |
|
I couldn't successfully bisect the commits. After commit #47a470a, I get the red screen of death with the message "Couldn't get the native call queue...". Restarting package manager, reinstalling, etc didn't fix the issue. The message shows for this commit and all subsequent commits. Any hint would could be going wrong? Circle rendered fine in the commit before that though. |
|
I'm not sure, sorry. Does master work for you? (I don't really work on Android, or on React Native for that matter.) |
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 facebook#7049 Differential Revision: D3234404 Pulled By: spicyj fb-gh-sync-id: 4974b818dc49d9d16f2483c49b462c459a8bb479 fbshipit-source-id: 4974b818dc49d9d16f2483c49b462c459a8bb479
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 facebook#7049 Differential Revision: D3234404 Pulled By: spicyj fb-gh-sync-id: 6b85eb42389da6c344ec9723c7f81f61473246b0 fbshipit-source-id: 6b85eb42389da6c344ec9723c7f81f61473246b0
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 facebook#7049 Differential Revision: D3234404 Pulled By: spicyj fb-gh-sync-id: 4974b818dc49d9d16f2483c49b462c459a8bb479 fbshipit-source-id: 4974b818dc49d9d16f2483c49b462c459a8bb479
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 facebook#7049 Differential Revision: D3234404 Pulled By: spicyj fb-gh-sync-id: 6b85eb42389da6c344ec9723c7f81f61473246b0 fbshipit-source-id: 6b85eb42389da6c344ec9723c7f81f61473246b0
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 facebook#7049 Differential Revision: D3234404 Pulled By: spicyj fb-gh-sync-id: 4974b818dc49d9d16f2483c49b462c459a8bb479 fbshipit-source-id: 4974b818dc49d9d16f2483c49b462c459a8bb479
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 facebook#7049 Differential Revision: D3234404 Pulled By: spicyj fb-gh-sync-id: 6b85eb42389da6c344ec9723c7f81f61473246b0 fbshipit-source-id: 6b85eb42389da6c344ec9723c7f81f61473246b0

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. The demo app illustrates that on iOS, wedges are drawn correctly, but Android only draws full circles. Direct Link to iOS Before. Direct Link to Android Before.
Proof The Bug is Fixed: Here is a direct link to Android After pic. 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 always be positive. Java returns the remainder, which can be negative.
-120 % 360will return 240 in Python, but -120 in Java. I created a modulus method which mimics Python's behavior. Math.floorMod(), introduced in Java 8, also gets the job done. See this StackOverflow answer for more information regarding modulus.