Skip to content

Commit

Permalink
Open image in new tab when saving on iOS Safari because of iOS bug
Browse files Browse the repository at this point in the history
  • Loading branch information
shannonlui committed May 24, 2019
1 parent 39a4afa commit f659d3d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions client/src/pages/ImageEditor/Canvas/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,16 @@ class Canvas extends Component {
}

saveCanvas = () => {
const canvas = this.canvas.current;
saveAs(canvas.toDataURL('image/png'), 'pixelartify.png');
var ua = window.navigator.userAgent;
var iOS = !!ua.match(/iPad/i) || !!ua.match(/iPhone/i);
var webkit = !!ua.match(/WebKit/i);
var iOSSafari = iOS && webkit && !ua.match(/CriOS/i);
const canvasURL = this.canvas.current.toDataURL('image/png');
if (iOSSafari) {
window.open(canvasURL, '_blank');
} else {
saveAs(canvasURL, 'pixelartify.png');
}
}

getClosestColor(colors, target) {
Expand Down

0 comments on commit f659d3d

Please sign in to comment.