react-native-wgpu 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,9 +1,8 @@
1
1
  # React Native WebGPU
2
2
 
3
- React Native implementation of WebGPU using [Dawn](https://dawn.googlesource.com/dawn).
4
- This is currently a technical preview for early adopters.
3
+ React Native implementation of WebGPU using [Dawn](https://dawn.googlesource.com/dawn).
5
4
 
6
- React Native WebGPU requires React Native 0.81 or newer and doesn't run on legacy architecture.
5
+ React Native WebGPU requires React Native 0.81 or newer. It doesn't support the legacy architecture.
7
6
 
8
7
  ## Installation
9
8
 
@@ -13,7 +12,16 @@ Please note that the package name is `react-native-wgpu`.
13
12
  npm install react-native-wgpu
14
13
  ```
15
14
 
16
- Note that if you use pnpm, you MUST use a `node-linker = hoisted` so that the external reference to the Dawn webgpu library can successfully link it.
15
+ ## With Expo
16
+
17
+ Expo provides a React Native WebGPU template that works with React Three Fiber.
18
+ The works on iOS, Android, and Web.
19
+
20
+ ```
21
+ npx create-expo-app@latest -e with-webgpu
22
+ ```
23
+
24
+ https://github.com/user-attachments/assets/efbd05f8-4ce0-46c2-919c-03e1095bc8ac
17
25
 
18
26
  Below are some examples from the [example app](/apps/example/).
19
27
 
@@ -38,13 +46,6 @@ We also provide prebuilt binaries for visionOS and macOS.
38
46
 
39
47
  https://github.com/user-attachments/assets/2d5c618e-5b15-4cef-8558-d4ddf8c70667
40
48
 
41
- ## Diagnostics
42
-
43
- Two diagnostic screens were added to the example app so you can reproduce the issues highlighted in the code review:
44
-
45
- - `Async Runner Starvation` (`apps/example/src/Diagnostics/AsyncStarvation.tsx`) shows that a zero-delay `setTimeout` never fires before `device.createRenderPipelineAsync()` resolves because the event loop is kept busy. Launch the example app and open the screen from the home list to observe the stalled timer.
46
- - `Device Lost Promise Hang` (`apps/example/src/Diagnostics/DeviceLostHang.tsx`) forces a synthetic device loss by calling the native `forceLossForTesting()` helper. On the current build the `device.lost` promise remains pending indefinitely, confirming that the loss callback is never delivered once pumping stops.
47
-
48
49
  ## Usage
49
50
 
50
51
  Usage is identical to Web.
@@ -158,8 +159,8 @@ From there you will be able to run the example app properly.
158
159
 
159
160
  ## Similarities and Differences with the Web
160
161
 
161
- The API has been designed to be completely symmetric with the Web.
162
- For instance, you can access the WebGPU context synchronously, as well as the canvas size.
162
+ The API has been designed to be completely symmetric with the Web.
163
+ For instance, you can access the WebGPU context synchronously, as well as the canvas size.
163
164
  Pixel density and canvas resizing are handled exactly like on the Web as well.
164
165
 
165
166
  ```tsx
@@ -173,7 +174,7 @@ ctx.canvas.height = ctx.canvas.clientHeight * PixelRatio.get();
173
174
 
174
175
  ### Frame Scheduling
175
176
 
176
- In React Native, we want to keep frame presentation as a manual operation as we plan to provide more advanced rendering options that are React Native specific.
177
+ In React Native, we want to keep frame presentation as a manual operation as we plan to provide more advanced rendering options that are React Native specific.
177
178
  This means that when you are ready to present a frame, you need to call `present` on the context.
178
179
 
179
180
  ```tsx
@@ -184,6 +185,19 @@ device.queue.submit([commandEncoder.finish()]);
184
185
  context.present();
185
186
  ```
186
187
 
188
+ ### Canvas Transparency
189
+
190
+ On Android, the `alphaMode` property is ignored when configuring the canvas.
191
+ To have a transparent canvas by default, use the `transparent` property.
192
+
193
+ ```tsx
194
+ return (
195
+ <View style={style.container}>
196
+ <Canvas ref={ref} style={style.webgpu} transparent />
197
+ </View>
198
+ );
199
+ ```
200
+
187
201
  ### External Textures
188
202
 
189
203
  This module provides a `createImageBitmap` function that you can use in `copyExternalImageToTexture`.
@@ -14,11 +14,11 @@ let CONTEXT_COUNTER = 1;
14
14
  function generateContextId() {
15
15
  return CONTEXT_COUNTER++;
16
16
  }
17
- const Canvas = exports.Canvas = /*#__PURE__*/(0, _react.forwardRef)(({
18
- onLayout: _onLayout,
17
+ const Canvas = ({
19
18
  transparent,
19
+ ref,
20
20
  ...props
21
- }, ref) => {
21
+ }) => {
22
22
  const viewRef = (0, _react.useRef)(null);
23
23
  const [contextId, _] = (0, _react.useState)(() => generateContextId());
24
24
  (0, _react.useImperativeHandle)(ref, () => ({
@@ -33,16 +33,10 @@ const Canvas = exports.Canvas = /*#__PURE__*/(0, _react.forwardRef)(({
33
33
  if (!viewRef.current) {
34
34
  throw new Error("[WebGPU] Cannot get context before mount");
35
35
  }
36
- let size;
37
- if (_reactNative.Platform.OS === "web") {
38
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
39
- // @ts-expect-error
40
- size = viewRef.current.getBoundingClientRect();
41
- } else {
42
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
43
- // @ts-expect-error
44
- size = viewRef.current.unstable_getBoundingClientRect();
45
- }
36
+ // getBoundingClientRect became stable in RN 0.83
37
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
+ const view = viewRef.current;
39
+ const size = "getBoundingClientRect" in view ? view.getBoundingClientRect() : view.unstable_getBoundingClientRect();
46
40
  return RNWebGPU.MakeWebGPUCanvasContext(contextId, size.width, size.height);
47
41
  }
48
42
  }));
@@ -56,5 +50,6 @@ const Canvas = exports.Canvas = /*#__PURE__*/(0, _react.forwardRef)(({
56
50
  contextId: contextId,
57
51
  transparent: !!transparent
58
52
  }));
59
- });
53
+ };
54
+ exports.Canvas = Canvas;
60
55
  //# sourceMappingURL=Canvas.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_WebGPUViewNativeComponent","_interopRequireDefault","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","CONTEXT_COUNTER","generateContextId","Canvas","exports","forwardRef","onLayout","_onLayout","transparent","props","ref","viewRef","useRef","contextId","_","useState","useImperativeHandle","getContextId","getNativeSurface","RNWebGPU","getContext","contextName","Error","current","size","Platform","OS","getBoundingClientRect","unstable_getBoundingClientRect","MakeWebGPUCanvasContext","width","height","createElement","View","collapsable","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,KAAK,CAAC,0CAA0C,CAAC;MAC7D;MACA,IAAIE,IAAI;MACR,IAAIC,qBAAQ,CAACC,EAAE,KAAK,KAAK,EAAE;QACzB;QACA;QACAF,IAAI,GAAGb,OAAO,CAACY,OAAO,CAACI,qBAAqB,CAAC,CAAC;MAChD,CAAC,MAAM;QACL;QACA;QACAH,IAAI,GAAGb,OAAO,CAACY,OAAO,CAACK,8BAA8B,CAAC,CAAC;MACzD;MACA,OAAOT,QAAQ,CAACU,uBAAuB,CACrChB,SAAS,EACTW,IAAI,CAACM,KAAK,EACVN,IAAI,CAACO,MACP,CAAC;IACH;EACF,CAAC,CAAC,CAAC;EAEH,oBACE7D,MAAA,CAAAQ,OAAA,CAAAsD,aAAA,CAAC3D,YAAA,CAAA4D,IAAI,EAAAtC,QAAA;IAACuC,WAAW,EAAE,KAAM;IAACxB,GAAG,EAAEC;EAAQ,GAAKF,KAAK,gBAC/CvC,MAAA,CAAAQ,OAAA,CAAAsD,aAAA,CAAC1D,0BAAA,CAAAI,OAAgB;IACfyD,KAAK,EAAE;MAAEC,IAAI,EAAE;IAAE,CAAE;IACnBvB,SAAS,EAAEA,SAAU;IACrBL,WAAW,EAAE,CAAC,CAACA;EAAY,CAC5B,CACG,CAAC;AAEX,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_WebGPUViewNativeComponent","_interopRequireDefault","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","CONTEXT_COUNTER","generateContextId","Canvas","transparent","ref","props","viewRef","useRef","contextId","_","useState","useImperativeHandle","getContextId","getNativeSurface","RNWebGPU","getContext","contextName","Error","current","view","size","getBoundingClientRect","unstable_getBoundingClientRect","MakeWebGPUCanvasContext","width","height","createElement","View","collapsable","style","flex","exports"],"sourceRoot":"../../src","sources":["Canvas.tsx"],"mappings":";;;;;;AAAA,IA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BA,IAAI,CAACE,qBAAqB,CAAC,CAAC,GAC5BF,IAAI,CAACG,8BAA8B,CAAC,CAAC;MAC3C,OAAOR,QAAQ,CAACS,uBAAuB,CACrCf,SAAS,EACTY,IAAI,CAACI,KAAK,EACVJ,IAAI,CAACK,MACP,CAAC;IACH;EACF,CAAC,CAAC,CAAC;EAEH,oBACExD,MAAA,CAAAQ,OAAA,CAAAiD,aAAA,CAACtD,YAAA,CAAAuD,IAAI,EAAAjC,QAAA;IAACkC,WAAW,EAAE,KAAM;IAACxB,GAAG,EAAEE;EAAQ,GAAKD,KAAK,gBAC/CpC,MAAA,CAAAQ,OAAA,CAAAiD,aAAA,CAACrD,0BAAA,CAAAI,OAAgB;IACfoD,KAAK,EAAE;MAAEC,IAAI,EAAE;IAAE,CAAE;IACnBtB,SAAS,EAAEA,SAAU;IACrBL,WAAW,EAAE,CAAC,CAACA;EAAY,CAC5B,CACG,CAAC;AAEX,CAAC;AAAC4B,OAAA,CAAA7B,MAAA,GAAAA,MAAA","ignoreList":[]}
@@ -1,16 +1,16 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- import React, { forwardRef, useImperativeHandle, useRef, useState } from "react";
3
- import { Platform, View } from "react-native";
2
+ import React, { useImperativeHandle, useRef, useState } from "react";
3
+ import { View } from "react-native";
4
4
  import WebGPUNativeView from "./WebGPUViewNativeComponent";
5
5
  let CONTEXT_COUNTER = 1;
6
6
  function generateContextId() {
7
7
  return CONTEXT_COUNTER++;
8
8
  }
9
- export const Canvas = /*#__PURE__*/forwardRef(({
10
- onLayout: _onLayout,
9
+ export const Canvas = ({
11
10
  transparent,
11
+ ref,
12
12
  ...props
13
- }, ref) => {
13
+ }) => {
14
14
  const viewRef = useRef(null);
15
15
  const [contextId, _] = useState(() => generateContextId());
16
16
  useImperativeHandle(ref, () => ({
@@ -25,16 +25,10 @@ export const Canvas = /*#__PURE__*/forwardRef(({
25
25
  if (!viewRef.current) {
26
26
  throw new Error("[WebGPU] Cannot get context before mount");
27
27
  }
28
- let size;
29
- if (Platform.OS === "web") {
30
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
31
- // @ts-expect-error
32
- size = viewRef.current.getBoundingClientRect();
33
- } else {
34
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
35
- // @ts-expect-error
36
- size = viewRef.current.unstable_getBoundingClientRect();
37
- }
28
+ // getBoundingClientRect became stable in RN 0.83
29
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
+ const view = viewRef.current;
31
+ const size = "getBoundingClientRect" in view ? view.getBoundingClientRect() : view.unstable_getBoundingClientRect();
38
32
  return RNWebGPU.MakeWebGPUCanvasContext(contextId, size.width, size.height);
39
33
  }
40
34
  }));
@@ -48,5 +42,5 @@ export const Canvas = /*#__PURE__*/forwardRef(({
48
42
  contextId: contextId,
49
43
  transparent: !!transparent
50
44
  }));
51
- });
45
+ };
52
46
  //# sourceMappingURL=Canvas.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","forwardRef","useImperativeHandle","useRef","useState","Platform","View","WebGPUNativeView","CONTEXT_COUNTER","generateContextId","Canvas","onLayout","_onLayout","transparent","props","ref","viewRef","contextId","_","getContextId","getNativeSurface","RNWebGPU","getContext","contextName","Error","current","size","OS","getBoundingClientRect","unstable_getBoundingClientRect","MakeWebGPUCanvasContext","width","height","createElement","_extends","collapsable","style","flex"],"sourceRoot":"../../src","sources":["Canvas.tsx"],"mappings":";AAAA,OAAOA,KAAK,IACVC,UAAU,EACVC,mBAAmB,EACnBC,MAAM,EACNC,QAAQ,QACH,OAAO;AAEd,SAASC,QAAQ,EAAEC,IAAI,QAAQ,cAAc;AAE7C,OAAOC,gBAAgB,MAAM,6BAA6B;AAE1D,IAAIC,eAAe,GAAG,CAAC;AACvB,SAASC,iBAAiBA,CAAA,EAA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AAK,gBAC/Cd,KAAA,CAAAiC,aAAA,CAAC1B,gBAAgB;IACf6B,KAAK,EAAE;MAAEC,IAAI,EAAE;IAAE,CAAE;IACnBpB,SAAS,EAAEA,SAAU;IACrBJ,WAAW,EAAE,CAAC,CAACA;EAAY,CAC5B,CACG,CAAC;AAEX,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["React","useImperativeHandle","useRef","useState","View","WebGPUNativeView","CONTEXT_COUNTER","generateContextId","Canvas","transparent","ref","props","viewRef","contextId","_","getContextId","getNativeSurface","RNWebGPU","getContext","contextName","Error","current","view","size","getBoundingClientRect","unstable_getBoundingClientRect","MakeWebGPUCanvasContext","width","height","createElement","_extends","collapsable","style","flex"],"sourceRoot":"../../src","sources":["Canvas.tsx"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,mBAAmB,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAEpE,SAASC,IAAI,QAAQ,cAAc;AAEnC,OAAOC,gBAAgB,MAAM,6BAA6B;AAE1D,IAAIC,eAAe,GAAG,CAAC;AACvB,SAASC,iBAAiBA,CAAA,EAAG;EAC3B,OAAOD,eAAe,EAAE;AAC1B;AA0CA,OAAO,MAAME,MAAM,GAAGA,CAAC;EAAEC,WAAW;EAAEC,GAAG;EAAE,GAAGC;AAAmB,CAAC,KAAK;EACrE,MAAMC,OAAO,GAAGV,MAAM,CAAC,IAAI,CAAC;EAC5B,MAAM,CAACW,SAAS,EAAEC,CAAC,CAAC,GAAGX,QAAQ,CAAC,MAAMI,iBAAiB,CAAC,CAAC,CAAC;EAC1DN,mBAAmB,CAACS,GAAG,EAAE,OAAO;IAC9BK,YAAY,EAAEA,CAAA,KAAMF,SAAS;IAC7BG,gBAAgB,EAAEA,CAAA,KAAM;MACtB,OAAOC,QAAQ,CAACD,gBAAgB,CAACH,SAAS,CAAC;IAC7C,CAAC;IACDK,UAAUA,CAACC,WAAqB,EAA0B;MACxD,IAAIA,WAAW,KAAK,QAAQ,EAAE;QAC5B,MAAM,IAAIC,KAAK,CAAC,iCAAiCD,WAAW,EAAE,CAAC;MACjE;MACA,IAAI,CAACP,OAAO,CAACS,OAAO,EAAE;QACpB,MAAM,IAAID,KAAK,CAAC,0CAA0C,CAAC;MAC7D;MACA;MACA;MACA,MAAME,IAAI,GAAGV,OAAO,CAACS,OAAc;MACnC,MAAME,IAAI,GACR,uBAAuB,IAAID,IAAI,GAC3BA,IAAI,CAACE,qBAAqB,CAAC,CAAC,GAC5BF,IAAI,CAACG,8BAA8B,CAAC,CAAC;MAC3C,OAAOR,QAAQ,CAACS,uBAAuB,CACrCb,SAAS,EACTU,IAAI,CAACI,KAAK,EACVJ,IAAI,CAACK,MACP,CAAC;IACH;EACF,CAAC,CAAC,CAAC;EAEH,oBACE5B,KAAA,CAAA6B,aAAA,CAACzB,IAAI,EAAA0B,QAAA;IAACC,WAAW,EAAE,KAAM;IAACrB,GAAG,EAAEE;EAAQ,GAAKD,KAAK,gBAC/CX,KAAA,CAAA6B,aAAA,CAACxB,gBAAgB;IACf2B,KAAK,EAAE;MAAEC,IAAI,EAAE;IAAE,CAAE;IACnBpB,SAAS,EAAEA,SAAU;IACrBJ,WAAW,EAAE,CAAC,CAACA;EAAY,CAC5B,CACG,CAAC;AAEX,CAAC","ignoreList":[]}
@@ -1,3 +1,7 @@
1
1
  export const __esModule: boolean;
2
- export const Canvas: any;
2
+ export function Canvas({ transparent, ref, ...props }: {
3
+ [x: string]: any;
4
+ transparent: any;
5
+ ref: any;
6
+ }): any;
3
7
  //# sourceMappingURL=Canvas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../commonjs/Canvas.js"],"names":[],"mappings":""}
1
+ {"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../commonjs/Canvas.js"],"names":[],"mappings":";AAgBA;;;;QAoCC"}
@@ -1,3 +1,8 @@
1
- export const Canvas: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
1
+ export function Canvas({ transparent, ref, ...props }: {
2
+ [x: string]: any;
3
+ transparent: any;
4
+ ref: any;
5
+ }): React.CElement<import("react-native").ViewProps, View>;
6
+ import { View } from "react-native";
2
7
  import React from "react";
3
8
  //# sourceMappingURL=Canvas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../module/Canvas.js"],"names":[],"mappings":"AAQA,+EA0CG;kBAjDsE,OAAO"}
1
+ {"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../module/Canvas.js"],"names":[],"mappings":"AAQO;;;;2DAoCN;qBA1CoB,cAAc;kBAD0B,OAAO"}
@@ -26,8 +26,10 @@ export interface CanvasRef {
26
26
  getContext(contextName: "webgpu"): RNCanvasContext | null;
27
27
  getNativeSurface: () => NativeCanvas;
28
28
  }
29
- export declare const Canvas: React.ForwardRefExoticComponent<ViewProps & {
29
+ interface CanvasProps extends ViewProps {
30
30
  transparent?: boolean;
31
- } & React.RefAttributes<CanvasRef>>;
31
+ ref?: React.Ref<CanvasRef>;
32
+ }
33
+ export declare const Canvas: ({ transparent, ref, ...props }: CanvasProps) => React.JSX.Element;
32
34
  export {};
33
35
  //# sourceMappingURL=Canvas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../src/Canvas.tsx"],"names":[],"mappings":"AAAA,OAAO,KAKN,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAU9C,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,QAAQ,EAAE;QACZ,GAAG,EAAE,GAAG,CAAC;QACT,MAAM,EAAE,OAAO,CAAC;QAChB,gBAAgB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,YAAY,CAAC;QACtD,uBAAuB,EAAE,CACvB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,KACX,eAAe,CAAC;Q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AE,OAAO,iBAAiB,CAAC;KAC7C,CAAC;CACH;AAED,KAAK,cAAc,GAAG,MAAM,CAAC;AAE7B,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG;IAC/C,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,UAAU,CAAC,WAAW,EAAE,QAAQ,GAAG,eAAe,GAAG,IAAI,CAAC;IAC1D,gBAAgB,EAAE,MAAM,YAAY,CAAC;CACtC;AAED,UAAU,WAAY,SAAQ,SAAS;IACrC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;CAC5B;AAED,eAAO,MAAM,MAAM,GAAI,gCAAgC,WAAW,sBAuCjE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-wgpu",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "React Native WebGPU",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -123,4 +123,4 @@
123
123
  }
124
124
  }
125
125
  }
126
- }
126
+ }
package/src/Canvas.tsx CHANGED
@@ -1,11 +1,6 @@
1
- import React, {
2
- forwardRef,
3
- useImperativeHandle,
4
- useRef,
5
- useState,
6
- } from "react";
1
+ import React, { useImperativeHandle, useRef, useState } from "react";
7
2
  import type { ViewProps } from "react-native";
8
- import { Platform, View } from "react-native";
3
+ import { View } from "react-native";
9
4
 
10
5
  import WebGPUNativeView from "./WebGPUViewNativeComponent";
11
6
 
@@ -49,10 +44,12 @@ export interface CanvasRef {
49
44
  getNativeSurface: () => NativeCanvas;
50
45
  }
51
46
 
52
- export const Canvas = forwardRef<
53
- CanvasRef,
54
- ViewProps & { transparent?: boolean }
55
- >(({ onLayout: _onLayout, transparent, ...props }, ref) => {
47
+ interface CanvasProps extends ViewProps {
48
+ transparent?: boolean;
49
+ ref?: React.Ref<CanvasRef>;
50
+ }
51
+
52
+ export const Canvas = ({ transparent, ref, ...props }: CanvasProps) => {
56
53
  const viewRef = useRef(null);
57
54
  const [contextId, _] = useState(() => generateContextId());
58
55
  useImperativeHandle(ref, () => ({
@@ -67,16 +64,13 @@ export const Canvas = forwardRef<
67
64
  if (!viewRef.current) {
68
65
  throw new Error("[WebGPU] Cannot get context before mount");
69
66
  }
70
- let size;
71
- if (Platform.OS === "web") {
72
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
73
- // @ts-expect-error
74
- size = viewRef.current.getBoundingClientRect();
75
- } else {
76
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
77
- // @ts-expect-error
78
- size = viewRef.current.unstable_getBoundingClientRect();
79
- }
67
+ // getBoundingClientRect became stable in RN 0.83
68
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
+ const view = viewRef.current as any;
70
+ const size =
71
+ "getBoundingClientRect" in view
72
+ ? view.getBoundingClientRect()
73
+ : view.unstable_getBoundingClientRect();
80
74
  return RNWebGPU.MakeWebGPUCanvasContext(
81
75
  contextId,
82
76
  size.width,
@@ -94,4 +88,4 @@ export const Canvas = forwardRef<
94
88
  />
95
89
  </View>
96
90
  );
97
- });
91
+ };