Skip to content

Commit c3eae88

Browse files
authored
Add fallback for roundRect for older browsers (#9)
* Add fallback for roundRect for older browsers * Linting
1 parent be7d560 commit c3eae88

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-audio-visualize",
33
"private": false,
4-
"version": "1.1.2",
4+
"version": "1.1.3",
55
"license": "MIT",
66
"author": "",
77
"repository": {

src/AudioVisualizer/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,13 @@ export const draw = (
101101
const h = amp + dp.max - y;
102102

103103
ctx.beginPath();
104-
ctx.roundRect(x, y, w, h, 50);
105-
ctx.fill();
104+
if (ctx.roundRect) {
105+
// making sure roundRect is supported by the browser
106+
ctx.roundRect(x, y, w, h, 50);
107+
ctx.fill();
108+
} else {
109+
// fallback for browsers that do not support roundRect
110+
ctx.fillRect(x, y, w, h);
111+
}
106112
});
107113
};

src/LiveAudioVisualizer/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ export const draw = (
6464
const h = dp || 1;
6565

6666
ctx.beginPath();
67-
ctx.roundRect(x, y, w, h, 50);
68-
ctx.fill();
67+
if (ctx.roundRect) {
68+
// making sure roundRect is supported by the browser
69+
ctx.roundRect(x, y, w, h, 50);
70+
ctx.fill();
71+
} else {
72+
// fallback for browsers that do not support roundRect
73+
ctx.fillRect(x, y, w, h);
74+
}
6975
});
7076
};

0 commit comments

Comments
 (0)