Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Commit 5327edb

Browse files
committed
Fixed screenshots for web
1 parent fe970ca commit 5327edb

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

engine/capture.web.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,23 @@ export async function captureNShare(ref: React.RefObject<any>) {
55
if (!node) {
66
return;
77
}
8-
const dataUrl = await domtoimage.toPng(node);
8+
const dataUrl = await domtoimage.toJpeg(node);
99
const shareData = {
1010
title: "Loop Game",
1111
text: "Check out this level",
1212
url: dataUrl,
1313
dialogTitle: "Share this level",
1414
};
15-
await navigator.share(shareData);
15+
if (!navigator.canShare(shareData)) {
16+
const link = document.createElement("a");
17+
link.href = dataUrl;
18+
link.download = `rn-loop-game-${new Date().getTime()}.jpg`;
19+
20+
// Append to document, trigger click, and remove
21+
document.body.appendChild(link);
22+
link.click();
23+
document.body.removeChild(link);
24+
} else {
25+
navigator.share(shareData);
26+
}
1627
}

0 commit comments

Comments
 (0)