Skip to content

Commit 271a404

Browse files
author
takuma-hmng8
committed
add useDomView to domSyncerObj
1 parent 3ba72fe commit 271a404

File tree

12 files changed

+497
-444
lines changed

12 files changed

+497
-444
lines changed

app/ShaderFx.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const ShaderFx = ({ children }: { children: React.ReactNode }) => {
1616
setDpr(Math.round((0.5 + 1.0 * factor) * 10) / 10);
1717
}}>
1818
<Suspense fallback={null}>{children}</Suspense>
19-
{/* <Perf position={"bottom-left"} minimal={false} /> */}
19+
<Perf position={"bottom-left"} minimal={false} />
2020
</PerformanceMonitor>
2121
</Canvas>
2222
);

app/domSyncer/DomSyncer.tsx

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,32 +51,16 @@ export const DomSyncer = ({ state }: { state: number }) => {
5151
);
5252

5353
const { setFrameloop } = useThree();
54-
const isPlaying = useRef<boolean>(true);
55-
56-
useEffect(() => {
57-
let id: number;
58-
const filterIntersection = () => {
59-
if (domSyncerObj.intersections.some((item) => item)) {
60-
// どっかには交差してる
61-
if (!isPlaying.current) {
62-
setFrameloop("always");
63-
isPlaying.current = true;
64-
}
65-
} else {
66-
// どこにも交差してない
67-
if (isPlaying.current) {
68-
setFrameloop("never");
69-
isPlaying.current = false;
70-
}
71-
}
72-
73-
id = requestAnimationFrame(filterIntersection);
74-
};
75-
id = requestAnimationFrame(filterIntersection);
76-
return () => {
77-
cancelAnimationFrame(id);
78-
};
79-
}, [domSyncerObj.intersections, setFrameloop]);
54+
domSyncerObj.useDomView({
55+
onView: () => {
56+
console.log("play");
57+
setFrameloop("always");
58+
},
59+
onHidden: () => {
60+
console.log("stop");
61+
setFrameloop("never");
62+
},
63+
});
8064

8165
const domArr = useRef<(HTMLElement | Element)[]>([]);
8266
const contentArr = useRef<HTMLElement[]>([]);

0 commit comments

Comments
 (0)