Skip to content

Commit 05e7ba9

Browse files
committed
Better zero height/width behavior and warning
1 parent 0ee0559 commit 05e7ba9

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

apps/example/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<title>Example</title>
1111
<!-- The `react-native-web` recommended style reset: https://necolas.github.io/react-native-web/docs/setup/#root-element -->
12-
<style id="expo-reset">
12+
<style id="react-native-web-reset">
1313
/* These styles make the body full-height */
1414
html,
1515
body {

packages/webgpu/src/Canvas.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,19 @@ export const Canvas = forwardRef<
6969
const cb = useRef<() => void>();
7070
const { size, onLayout } = useSize(viewRef);
7171
useEffect(() => {
72-
if (size && cb.current) {
72+
const hasNonZeroDims = !!size?.height && !!size?.width;
73+
if (size && hasNonZeroDims && cb.current) {
7374
cb.current();
7475
}
76+
77+
if (size && !hasNonZeroDims) {
78+
console.warn(
79+
[
80+
`react-native-wgpu canvas has zero dimensions (width:${size.width}px; height:${size.height}px)!`,
81+
"Unable to initialize underlying canvas.",
82+
].join(" "),
83+
);
84+
}
7585
}, [size]);
7686

7787
useImperativeHandle(ref, () => ({

packages/webgpu/src/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1+
import "@webgpu/types";
2+
13
export * from "./main";
4+
5+
declare global {
6+
interface Navigator {
7+
gpu: GPU;
8+
}
9+
}

packages/webgpu/src/main.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ if (!navigator) {
201201
// @ts-expect-error
202202
navigator = {};
203203
}
204-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
205-
// @ts-expect-error
204+
206205
navigator.gpu = RNWebGPU.gpu;
207206

208207
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

0 commit comments

Comments
 (0)