Skip to content

Commit 662b1e7

Browse files
authored
fix: BottomSheet example crash (#8416)
## Summary It seems that the `unstable_getBoundingClientRect` no longer exists in RN `0.82` and the if check used in the Gorhom's bottom-sheet library is invalid as it checks whether the value is not `null`: ```ts if (ref.current.unstable_getBoundingClientRect !== null) { ... } ``` Instead of checking if it is defined. More details can be found in this issue: gorhom/react-native-bottom-sheet#2513
1 parent aed8dc0 commit 662b1e7

File tree

3 files changed

+90
-2
lines changed

3 files changed

+90
-2
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
diff --git a/lib/commonjs/hooks/useBoundingClientRect.js b/lib/commonjs/hooks/useBoundingClientRect.js
2+
index b4a90b76ee55bf2cad9cf461017621b1ddab0fe1..ccd592713dbbdf47957d24a5bced0ea4742a82ad 100644
3+
--- a/lib/commonjs/hooks/useBoundingClientRect.js
4+
+++ b/lib/commonjs/hooks/useBoundingClientRect.js
5+
@@ -46,7 +46,7 @@ function useBoundingClientRect(ref, handler) {
6+
}
7+
8+
// @ts-ignore 👉 https://github.com/facebook/react/commit/53b1f69ba
9+
- if (ref.current.unstable_getBoundingClientRect !== null) {
10+
+ if (ref.current.unstable_getBoundingClientRect) {
11+
// @ts-ignore https://github.com/facebook/react/commit/53b1f69ba
12+
const layout = ref.current.unstable_getBoundingClientRect();
13+
handler(layout);
14+
@@ -54,7 +54,7 @@ function useBoundingClientRect(ref, handler) {
15+
}
16+
17+
// @ts-ignore once it `unstable_getBoundingClientRect` gets stable 🤞.
18+
- if (ref.current.getBoundingClientRect !== null) {
19+
+ if (ref.current.getBoundingClientRect) {
20+
// @ts-ignore once it `unstable_getBoundingClientRect` gets stable.
21+
const layout = ref.current.getBoundingClientRect();
22+
handler(layout);
23+
diff --git a/lib/module/hooks/useBoundingClientRect.js b/lib/module/hooks/useBoundingClientRect.js
24+
index a723aede9d4cfbb46f5985c531e0dae8f517aba8..c11b18b569d67fc9993ac9ab492ee1d967c24867 100644
25+
--- a/lib/module/hooks/useBoundingClientRect.js
26+
+++ b/lib/module/hooks/useBoundingClientRect.js
27+
@@ -42,7 +42,7 @@ export function useBoundingClientRect(ref, handler) {
28+
}
29+
30+
// @ts-ignore 👉 https://github.com/facebook/react/commit/53b1f69ba
31+
- if (ref.current.unstable_getBoundingClientRect !== null) {
32+
+ if (ref.current.unstable_getBoundingClientRect) {
33+
// @ts-ignore https://github.com/facebook/react/commit/53b1f69ba
34+
const layout = ref.current.unstable_getBoundingClientRect();
35+
handler(layout);
36+
@@ -50,7 +50,7 @@ export function useBoundingClientRect(ref, handler) {
37+
}
38+
39+
// @ts-ignore once it `unstable_getBoundingClientRect` gets stable 🤞.
40+
- if (ref.current.getBoundingClientRect !== null) {
41+
+ if (ref.current.getBoundingClientRect) {
42+
// @ts-ignore once it `unstable_getBoundingClientRect` gets stable.
43+
const layout = ref.current.getBoundingClientRect();
44+
handler(layout);
45+
diff --git a/src/hooks/useBoundingClientRect.ts b/src/hooks/useBoundingClientRect.ts
46+
index cc85c8ced2de8ec514360368ed20af733f8f9aec..c551df2694ef00023a2e4616f8969ffd5e21d695 100644
47+
--- a/src/hooks/useBoundingClientRect.ts
48+
+++ b/src/hooks/useBoundingClientRect.ts
49+
@@ -56,7 +56,7 @@ export function useBoundingClientRect(
50+
}
51+
52+
// @ts-ignore 👉 https://github.com/facebook/react/commit/53b1f69ba
53+
- if (ref.current.unstable_getBoundingClientRect !== null) {
54+
+ if (ref.current.unstable_getBoundingClientRect) {
55+
// @ts-ignore https://github.com/facebook/react/commit/53b1f69ba
56+
const layout = ref.current.unstable_getBoundingClientRect();
57+
handler(layout);
58+
@@ -64,7 +64,7 @@ export function useBoundingClientRect(
59+
}
60+
61+
// @ts-ignore once it `unstable_getBoundingClientRect` gets stable 🤞.
62+
- if (ref.current.getBoundingClientRect !== null) {
63+
+ if (ref.current.getBoundingClientRect) {
64+
// @ts-ignore once it `unstable_getBoundingClientRect` gets stable.
65+
const layout = ref.current.getBoundingClientRect();
66+
handler(layout);

apps/common-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@fortawesome/fontawesome-svg-core": "6.5.2",
1818
"@fortawesome/free-solid-svg-icons": "6.5.2",
1919
"@fortawesome/react-native-fontawesome": "0.3.2",
20-
"@gorhom/bottom-sheet": "5.2.6",
20+
"@gorhom/bottom-sheet": "patch:@gorhom/bottom-sheet@npm%3A5.2.6#~/.yarn/patches/@gorhom-bottom-sheet-npm-5.2.6-c24dba2629.patch",
2121
"@gorhom/portal": "1.0.14",
2222
"@react-native-async-storage/async-storage": "2.2.0",
2323
"@react-native-clipboard/clipboard": "1.16.3",

yarn.lock

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4307,6 +4307,28 @@ __metadata:
43074307
languageName: node
43084308
linkType: hard
43094309

4310+
"@gorhom/bottom-sheet@patch:@gorhom/bottom-sheet@npm%3A5.2.6#~/.yarn/patches/@gorhom-bottom-sheet-npm-5.2.6-c24dba2629.patch":
4311+
version: 5.2.6
4312+
resolution: "@gorhom/bottom-sheet@patch:@gorhom/bottom-sheet@npm%3A5.2.6#~/.yarn/patches/@gorhom-bottom-sheet-npm-5.2.6-c24dba2629.patch::version=5.2.6&hash=5dd64e"
4313+
dependencies:
4314+
"@gorhom/portal": "npm:1.0.14"
4315+
invariant: "npm:^2.2.4"
4316+
peerDependencies:
4317+
"@types/react": "*"
4318+
"@types/react-native": "*"
4319+
react: "*"
4320+
react-native: "*"
4321+
react-native-gesture-handler: ">=2.16.1"
4322+
react-native-reanimated: "*"
4323+
peerDependenciesMeta:
4324+
"@types/react":
4325+
optional: true
4326+
"@types/react-native":
4327+
optional: true
4328+
checksum: 10/6b08b8c621a629759316198a73eb48cb0cb0bcb9a36f12adb0afe204f8bec9d414a5a7ba9daf1cfaaf06c3027bb391c630bc1444d8a5597d4356ded668e1642f
4329+
languageName: node
4330+
linkType: hard
4331+
43104332
"@gorhom/portal@npm:1.0.14":
43114333
version: 1.0.14
43124334
resolution: "@gorhom/portal@npm:1.0.14"
@@ -12430,7 +12452,7 @@ __metadata:
1243012452
"@fortawesome/fontawesome-svg-core": "npm:6.5.2"
1243112453
"@fortawesome/free-solid-svg-icons": "npm:6.5.2"
1243212454
"@fortawesome/react-native-fontawesome": "npm:0.3.2"
12433-
"@gorhom/bottom-sheet": "npm:5.2.6"
12455+
"@gorhom/bottom-sheet": "patch:@gorhom/bottom-sheet@npm%3A5.2.6#~/.yarn/patches/@gorhom-bottom-sheet-npm-5.2.6-c24dba2629.patch"
1243412456
"@gorhom/portal": "npm:1.0.14"
1243512457
"@react-native-async-storage/async-storage": "npm:2.2.0"
1243612458
"@react-native-clipboard/clipboard": "npm:1.16.3"

0 commit comments

Comments
 (0)