Skip to content

Commit a9cec62

Browse files
authored
fix(⚛️): support stable getBoundingClientRect in RN 0.83+ (#296)
1 parent 6bf4b4a commit a9cec62

3 files changed

Lines changed: 10 additions & 13 deletions

File tree

externals/dawn

Submodule dawn updated from ffb6058 to c84d448

packages/webgpu/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-wgpu",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"description": "React Native WebGPU",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

packages/webgpu/src/Canvas.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useImperativeHandle, useRef, useState } from "react";
22
import type { ViewProps } from "react-native";
3-
import { Platform, View } from "react-native";
3+
import { View } from "react-native";
44

55
import WebGPUNativeView from "./WebGPUViewNativeComponent";
66

@@ -64,16 +64,13 @@ export const Canvas = ({ transparent, ref, ...props }: CanvasProps) => {
6464
if (!viewRef.current) {
6565
throw new Error("[WebGPU] Cannot get context before mount");
6666
}
67-
let size;
68-
if (Platform.OS === "web") {
69-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
70-
// @ts-expect-error
71-
size = viewRef.current.getBoundingClientRect();
72-
} else {
73-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
74-
// @ts-expect-error
75-
size = viewRef.current.unstable_getBoundingClientRect();
76-
}
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();
7774
return RNWebGPU.MakeWebGPUCanvasContext(
7875
contextId,
7976
size.width,

0 commit comments

Comments
 (0)