Skip to content

Commit 3fb27ac

Browse files
committed
chore: add backgroundColor to setAttrs api
1 parent 6e772f5 commit 3fb27ac

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/components/layer.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ function Layer(
8282
const [attrs, setAttrs] = React.useState<Attrs>(() => {
8383
return {
8484
opacity,
85+
backgroundColor,
8586
};
8687
});
8788

@@ -91,6 +92,12 @@ function Layer(
9192
});
9293
}, [opacity]);
9394

95+
React.useEffect(() => {
96+
setAttrs((attrs) => {
97+
return { ...attrs, backgroundColor };
98+
});
99+
}, [backgroundColor]);
100+
94101
const xrUiContext = React.useContext(XrUiContext);
95102

96103
const res = React.useMemo(() => {
@@ -106,7 +113,10 @@ function Layer(
106113
}, [optimizedRendering, xrUiContext.optimizedRendering]);
107114

108115
const groupRef = React.useRef<THREE.Group>(null);
109-
const meshRef = React.useRef<THREE.Mesh<THREE.PlaneGeometry, THREE.MeshBasicMaterial>>(null);
116+
const meshRef =
117+
React.useRef<THREE.Mesh<THREE.PlaneGeometry, THREE.MeshBasicMaterial>>(
118+
null
119+
);
110120
const materialRef = React.useRef<THREE.MeshBasicMaterial>(null);
111121
const childrenGroupRef = React.useRef<THREE.Group>(null);
112122

@@ -206,13 +216,15 @@ function Layer(
206216

207217
const layoutOnly = React.useMemo<boolean>(() => {
208218
const props = [
209-
backgroundColor === "transparent" ? undefined : backgroundColor,
219+
attrs.backgroundColor === "transparent"
220+
? undefined
221+
: attrs.backgroundColor,
210222
backgroundImage,
211223
borderColor === "transparent" ? undefined : borderColor,
212224
textContent,
213225
];
214226
return props.filter((prop) => prop !== undefined).length === 0;
215-
}, [backgroundColor, backgroundImage, borderColor, textContent]);
227+
}, [attrs.backgroundColor, backgroundImage, borderColor, textContent]);
216228

217229
// Create 2d canvas context
218230
const ctx = React.useMemo<CanvasRenderingContext2D | null>(() => {
@@ -333,7 +345,6 @@ function Layer(
333345
borderColor,
334346
attrs,
335347
images,
336-
backgroundColor,
337348
backgroundPosition,
338349
backgroundSize,
339350
font,
@@ -388,7 +399,7 @@ function Layer(
388399
ctx.globalAlpha = attrs.opacity;
389400

390401
// Background color
391-
ctx.fillStyle = backgroundColor;
402+
ctx.fillStyle = attrs.backgroundColor;
392403
ctx.lineWidth = borderWidth * res * 2;
393404
ctx.fill();
394405

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export type LayerProps = GroupProps & {
8787

8888
export type Attrs = {
8989
opacity: number;
90+
backgroundColor: string;
9091
};
9192

9293
export type LayerRef = {

0 commit comments

Comments
 (0)