-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCheesyCanvas.jsx
50 lines (38 loc) · 1.17 KB
/
CheesyCanvas.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React, { useEffect } from "react";
import { Canvas, useThree } from "@react-three/fiber";
function SayCheese({ pauseAt = 0 }) {
const { advance, setFrameloop, clock } = useThree();
useEffect(() => {
console.log(`😬 Say cheeese (shooting photo in ${pauseAt}ms)`);
function shoot() {
// const secs = clock.elapsedTime;
const secs = 0;
console.log("📸 Shooting", secs);
setFrameloop("never");
advance(secs);
advance(secs); // not exactly sure why a 2nd-time, but needed 🤷♂️
document.dispatchEvent(new Event("playwright:snapshot-ready")); // will tell Playright to take a screenshot
}
setTimeout(shoot, pauseAt);
return () => {
clearTimeout(shoot);
};
}, []);
return null;
}
export default function CheesyCanvas({ children, ...props }) {
useEffect(() => {
console.log(
"CheesyCanvas: use ?saycheese in the URL to stop the animation"
);
}, []);
const sayCheeseParam = new URLSearchParams(window.location.search).has(
"saycheese"
);
return (
<Canvas {...props}>
{sayCheeseParam && <SayCheese pauseAt={3000} />}
{children}
</Canvas>
);
}