Skip to content

Commit 1922504

Browse files
committed
Canvas[width][height]
1 parent ee4c8d8 commit 1922504

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

packages/fiber/src/web/Canvas.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export interface CanvasProps
2222
ref?: React.Ref<HTMLCanvasElement>
2323
/** Canvas fallback content, similar to img's alt prop */
2424
fallback?: React.ReactNode
25+
/** */
26+
width?: number
27+
/** */
28+
height?: number
2529
/**
2630
* Options to pass to useMeasure.
2731
* @see https://github.com/pmndrs/react-use-measure#api
@@ -37,6 +41,8 @@ function CanvasImpl({
3741
ref,
3842
children,
3943
fallback,
44+
width,
45+
height,
4046
resize,
4147
style,
4248
gl,
@@ -83,7 +89,11 @@ function CanvasImpl({
8389

8490
useIsomorphicLayoutEffect(() => {
8591
const canvas = canvasRef.current
86-
if (containerRect.width > 0 && containerRect.height > 0 && canvas) {
92+
93+
const manualSize = width && height ? { width, height, left: 0, top: 0 } : undefined
94+
const size = manualSize ?? containerRect
95+
96+
if (size.width > 0 && size.height > 0 && canvas) {
8797
if (!root.current) root.current = createRoot<HTMLCanvasElement>(canvas)
8898

8999
async function run() {
@@ -101,7 +111,7 @@ function CanvasImpl({
101111
performance,
102112
raycaster,
103113
camera,
104-
size: containerRect,
114+
size,
105115
// Pass mutable reference to onPointerMissed so it's free to update
106116
onPointerMissed: (...args) => handlePointerMissed.current?.(...args),
107117
onCreated: (state) => {

0 commit comments

Comments
 (0)