Closed mnem77 closed 5 years ago
Hey @mnem77, sorry to hear that you've been having trouble!
It looks like this might be an issue with Safari in general, and not with your particular setup. Even the official iro.js codepen demo renders as black on Safari for macOS.
Just to rule out possible causes -- is there a <base>
element in the <head>
of your HTML? What does the URL path for your test page look like? Is it using an <iframe>
?
I'm sick with flu right now so it'll be a while before I can investigate fully, but my guess is that it was either unintentionally broken in v3.5.2, or the recent Safari update has somehow managed to break its SVG gradient implementation even more.
BTW, the reason it also doesn't work on iOS Chrome is because all third-party browsers on iOS are basically just Safari webviews. :>
Hello James, thank you for your fast response, I wish you a speedy recovery!
Indeed, the codepen demo renders as black on the iPhone and iPad.There is no
Thanks! You can find v3.5.1 on unpkg here: https://unpkg.com/@jaames/iro@3.5.1/dist/iro.js
Let me know if it's any different :>
Thanks a lot, will test as soon as I get the time and will come back with an answer.
Thanks a lot, will test as soon as I get the time and will come back with an answer.
Did you find a solution. I got same black output for ios devices.
@ramzanucar Not yet, I had other stuff to work on but right now I am going to try the 3.5.1 version and see if it works.
@jaames So the 3.5.1 version seems to work great on iOS, tested on Chrome and Safari but anyways as you have already said, all the browsers on iOS act similar to Safari.So my guess is something "broke" between 3.5.1 and 3.5.3.I did not test 3.5.2 but I am happy with 3.5.1 for now.Hopefully this information will help you fix 3.5.2 also :)
Thank you for the quick answers and for the 3.5.1 link.
@mnem77 Glad that works, thanks for checking!
Looks like this line is the issue again? While it did fix #40, I guess there's something that I missed. I'll check it out tomorrow. :)
Hey! Sorry for the dead air, I've been kinda busy recently...
I just checked the official Codepen demo on MacOS Safari 12.0 (14606.1.36.1.9) again and it seems to work fine now? I also can't see any issued with generating the gradient URL under various conditions.
I'm going to assume maybe it was just a temporary bug introduced in one version of Safari that's since been fixed, but please do reopen the issue thread if you're still having problems.
Thanks!
On an iPhone7 Safari browser, if I add url parameters to the codepen, then I can reproduce the black palette: https://codepen.io/rakujira/pen/WZOeNq?hi=3
It doesn't seem to be a problem for Safari desktop browser.
I am using iro.min.js v3.5.3
Edit: Actually, I can produce this on Desktop Safari, just follow that link above in a Safari browser (I was using Chrome at the time :-/ ). I am able to get it to work on both iOS and Desktop by leaving the params in the URL. Alternatively, it seems to work without the full path, just URL(#Gradient), so maybe that issue of needing the full path has been fixed in Safari.
@jtb Nice catch! I just pushed a hotfix (v3.5.4) which should add URL parameters to the SVG URLS. It seems to fix the issue on my end (testing on desktop Safari).
It looks as though Safari fixed some SVG rendering stuff in release 71, but I'll need to investigate further to see if that's actually the case. Originally the issue was related to certain client-side routing libraries inserting a <base>
element into the document head, and Safari was treating the SVG gradient URLs as being relative to that.
Looks like the base tag issue is still present in MacOS Safari Version 12.0 (14606.1.36.1.9), so I guess we still can't just use url(#gradient)
yet...
Safari really is the new IE. :P
Thanks James for the quick fix. Looks like that fixed things. Thanks for making such a nice color picker!
I believe this issue is still present when page is launched with home screen shortcut.
@625alex Please could you provide some more information? It would be helpful to know if you're using a client-side routing library, the URL of the page (in Safari, iro.js has to use the full page URL to link SVG gradients), as well as what the rendered HTML structure looks like in this case. I don't have a working iPhone at the moment so I can't test myself.
I'm using AngularJS with client-side routing. The base
element is present by design.
The rendered HTML structure looks fine to me. I will try to play with the SVG gradient URL to see if I can isolate the issue.
I think the problem is with the following:
var IS_SAFARI = /^((?!chrome|android).)*safari/i.test(ua);
This evaluates to false
when web page is launched via desktop shortcut. The user agent is different. So, the Safari detection method should be updated.
@625alex Ahh, thanks for the heads-up. I'll try to work on a fix now. :)
I just pushed a hotfix which adds a check to see if the userAgent matches /iPhone|iPod|iPad/i
.
I tested with Xcode's iOS Simulator and the bug doesn't seem to be present in the iOS 12.0 webview, so please let me know if that solves the issue @625alex
Cheers!
@jaames Is there any way to fix this?
Angular / ionic3 / iOS 13.1.2 / "@jaames/iro": "^4.5.1"
@jaames I am running on the iOS 13.1 emulator, but this issue still occurs. #18
@13546777510 Yeah, it seems to be an issue with using iro.js in an Ionic app.
Angular's router adds a <base>
element in the page's <head>
, which changes the base path for any relative URLs on the page. Safari also resolves SVG gradient URLs (like fill="url(#gradient)"
) using this base path, which is why the color wheel shows as black. It can't find the gradient properly.
This stackoverflow thread explains it in more detail: https://stackoverflow.com/questions/7759371/svg-gradient-turns-black-when-there-is-a-base-tag-in-html-page
Here's the function that resolves full gradient URLs for iro.js in Safari: https://github.com/jaames/iro.js/blob/master/src/util/svg.js#L13
That was fixed though.
I wonder if this is a separate issue with Ionic? It looks like the SVG gradients are being resolved to ionic://app/
, is that correct?
I don't know a lot about Angular or Ionic, so I would appreciate more information or a demo I can run myself, if that's possible.
Thanks!
@jaames
After compiling with Xcode 11.1
, it works as expected in iOS 12.1.2
, but in iOS 13.1.2
, it happened.
It may also be that iOS 13.x
changed the way it worked before.
@13546777510 strange -- could you give me the value of window.navigator.userAgent
in iOS 13.1.2?
@jaames Thank you very much for your prompt reply.
Damn time difference, Here is the night now.
I will continue to track this issue after about 12 hours.
@13546777510 no problem!
I couldn't reproduce the issue in iOS 13.x Safari in the Xcode iOS simulator.
Does Ionic run in an iOS webview? iOS webview might have a different useragent to iOS Safari, so maybe it isn't being detected by iro.js?
@jaames I have created an ionic3 project with only iro.js. After running to iOS 13, I recreated this issues.
I am creating a github repository and writing README.md to guide you to run the ionic project to the simulator.
wait a moment...
@jaames Everything is ready, you can start testing.
@jaames I reproduce this issue.
@ 13546777510奇怪-您能给我
window.navigator.userAgent
iOS 13.1.2中的值吗?
After running on the emulator, I got this value through the Safari debugger.
"Mozilla/5.0 (iPhone; CPU iPhone OS 13_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"
@jaames Any progress on this issue?
@13546777510 Yes, thank you for creating a test repository, it was very helpful!
It looks like the problem is that Ionic Webview sets the value of window.location.protocol
to ionic:
, and that's breaking absolute SVG gradient URLs. For some reason doesn't do this when using ionic cordova emulate ios
.
I think I have a fix, I'll create a new branch in a moment :)
@13546777510 Please try replacing iro.js with this script: https://github.com/jaames/iro.js/blob/ionic-svg-url-fix/dist/iro.js
Expected result:
If it works, I'll push it as iro.js version 4.5.2
@jaames Great, it works as expected!
@13546777510 Excellent, I'm glad that worked! :)
I published the fix on NPM, so please update to iro.js v 4.5.2
$ npm install @jaames/iro@4.5.2
@jaames Good, thank you very much
I am still facing this issue, Ionic 4 with iPhone XS - iOS 13.1.2 @jaames
@jaames @leonardosalles I have reproduced this issue in ionic4 and created a repository to reproduce this problem.
https://github.com/13546777510/iro-ionic4
iro.js: 4.5.2
It seems Ionic 4 doesn't support relative SVG gradient URLs, but Ionic 3 does? I think that's a bug on their end.
Anyway, I found a workaround using protocol-relative URLs that fixes the test repository and also works in the latest versions of macOS and iOS Safari.
@13546777510 @leonardosalles Please try replacing iro.js with this script: https://github.com/jaames/iro.js/blob/ionic4-svg-url-fix/dist/iro.js
I would also appreciate it if you could test it in ionic 3 and ionic 4 to confirm that it works in both :)
Thanks!
@jaames I will start working after 12 hours :)
@jaames In ionic4, this problem is fixed. But the issues with ionic3 has appeared again, The same is true for real devices.
@jaames Did you reproduce this issues in ionic3?
@13546777510 I wasn't able to test in Ionic 3
Is there any way to check which version of Ionic is running from Javascript? I think iro.js will have to detect which version of Ionic is being used to know how to resolve gradient URLs
I'd also appreciate it if someone could report this as a bug to Ionic, because I don't want to have to keep adding checks for every future version of their library. It's a bit ridiculous that they've broken SVG gradients to begin with.
@jaames @leonardosalles
I am worried that I have not described it very clearly, so if there is any need to add a description, I hope you can go to that question to help continue to add.
tks.
@jaames The question was replied. He said that it was not an ionic issues, It's cordova.
I might also need to apply for help from cordova.
@13546777510 Thank you for following that up :)
Would it be reasonable to ask people to use Capacitor instead of Cordova if they want to use iro.js in an ionic app? I don't know how different they are to eachother.
Looking at the issues in cordova-plugin-ionic-webview repository, there haven't been any replies from the Ionic team in a long time...
@jaames Apache Cordova is also called PhoneGap. As for why Capacitor is also present, I suspect that for historical reasons, they are now suitable for large mixed app projects.
I have always used cordova in my project because it's open source cordova-plugin is enough to meet my project needs.
For the time I started learning to program, I have never known the plugin for Capacitor.
I don't really know what they are doing behind the scenes: Ionic, Angular, Capacitor, Cordova, Typescript... I just focus on coding and looking for full-featured plugins, forgive me for not doing any in-depth research.
@jaames Is there a better solution for compatibility with ionic?
Perhaps this issue is worthy of discussion with developers who use ionic to develop smart home apps. RBG strip controllers require iro.js support.
@13546777510 to be honest, I don't know
If the issue is cordova-plugin-ionic-webview then it's strange that iro.js works in one version of Ionic but not the other, unless there are different versions of cordova-plugin-ionic-webview?
I've never used Ionic or Cordova before, and I don't understand them very well, so I'm not certain.
I think I will open a new issue to ask for help from developers who have experience with Ionic and Cordova. Until someone else can help, iro.js won't be able to support Cordova. I'm sorry.
@jaames I agree to wait for the help of developers with Ionic and Cordova experience, and I will always be concerned about this issue.
Hi!
I've been testing iro.js library and it's working quite nicely besides this problem I seem to be having only on iOS devices with any browser I test ( Chrome, Safari etc ).I can see that someone else had the exact same problem but only on Safari apparently.
I can confirm that your demo page ( https://iro.js.org/ ) works just fine on the testing devices yet while I access my testing page the output is black.Even with the output being black the functionality "is there", I can drag around the circle and the color is generated correctly.
Link to the similar Issue thread on GitHub: https://github.com/jaames/iro.js/issues/18
Example of how I create the color picker (even though is really basic, should not and does not seem to be a parameters problem or anything similar)
`
var demo = new window.iro.ColorPicker("#demoWheel_101", { width: 360, height: 360, color: "#f00", borderWidth: 2, padding: 4, anticlockwise: true, }); demo.on("input:end", function onInputStart(color) { console.log("0"); console.log(color.rgb); $(".input_101").css("background-color", "rgb(" + color.rgb.r + "," + color.rgb.g + "," + color.rgb.b + ")"); }); `