b42b1a193d
* fix: Excessive battery usage * chore: Refactor Eraser, Lasso and Laser pointer to use AnimationController * fix: Last laser trail element is not removed from SVG --------- Signed-off-by: Mark Tolmacs <mark@lazycat.hu> Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
35 lines
665 B
TypeScript
35 lines
665 B
TypeScript
import { useEffect, useRef } from "react";
|
|
|
|
import "./SVGLayer.scss";
|
|
|
|
import type { Trail } from "../animatedTrail";
|
|
|
|
type SVGLayerProps = {
|
|
trails: Trail[];
|
|
};
|
|
|
|
export const SVGLayer = ({ trails }: SVGLayerProps) => {
|
|
const svgRef = useRef<SVGSVGElement | null>(null);
|
|
|
|
useEffect(() => {
|
|
if (svgRef.current) {
|
|
for (const trail of trails) {
|
|
trail.start(svgRef.current);
|
|
}
|
|
}
|
|
|
|
return () => {
|
|
for (const trail of trails) {
|
|
trail.stop();
|
|
}
|
|
};
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, trails);
|
|
|
|
return (
|
|
<div className="SVGLayer">
|
|
<svg ref={svgRef} />
|
|
</div>
|
|
);
|
|
};
|