[0.77] `getBoundingClientRect` TypeScript type definition missing on View with New Architecture
Description
With the introduction of New Architecture and useLayoutEffect, we can now read layout synchronously with ref.current?.getBoundingClientRect.
However, the TypeScript definition for NativeMethods does not yet include the newly supported method.
Steps to reproduce
Check the definition of NativeMethods in react-native/types/public/ReactNativeTypes.d.ts, note that getBoundingClientRect is missing.
React Native Version
0.77.1
Affected Platforms
Build - MacOS
Areas
Other (please specify)
Output of npx @react-native-community/cli info
info Fetching system and libraries information...
System:
OS: macOS 14.5
CPU: (12) arm64 Apple M2 Pro
Memory: 121.22 MB / 32.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 18.19.0
path: ~/.nvm/versions/node/v18.19.0/bin/node
Yarn:
version: 1.22.19
path: ~/.nvm/versions/node/v18.19.0/bin/yarn
npm:
version: 10.2.3
path: ~/.nvm/versions/node/v18.19.0/bin/npm
Watchman:
version: 2024.12.02.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.16.2
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 23.2
- iOS 17.2
- macOS 14.2
- tvOS 17.2
- visionOS 1.0
- watchOS 10.2
Android SDK:
API Levels:
- "31"
- "35"
Build Tools:
- 34.0.0
- 35.0.0
System Images:
- android-35 | Google Play ARM 64 v8a
- android-Baklava | Google Play ARM 64 v8a
Android NDK: Not Found
IDEs:
Android Studio: 2024.2 AI-242.23339.11.2421.12700392
Xcode:
version: 15.2/15C500b
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.14
path: /usr/bin/javac
Ruby:
version: 3.3.6
path: /Users/bryan/.rvm/rubies/ruby-3.3.6/bin/ruby
npmPackages:
"@react-native-community/cli": Not Found
react:
installed: 18.3.1
wanted: 18.3.1
react-native:
installed: 0.77.1
wanted: ~0.77.1
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: Not found
newArchEnabled: Not found
iOS:
hermesEnabled: Not found
newArchEnabled: Not found
info React Native v0.79.0 is now available (your project is running on v0.77.1).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.79.0
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.77.1&to=0.79.0
info For more info, check out "https://reactnative.dev/docs/upgrading?os=macos".
Stacktrace or Logs
Not applicable.
Reproducer
https://github.com/bryanmylee/missing-types-new-arch-native-methods
Screenshots and Videos
I've searched for any mention of this all over but can't find anything, and the documentation barely makes a mention of getBoundingClientRect.
This appears to be the most valid channel to report this bug, however this does not produce a stacktrace or reproducer, so I'm happy to move this elsewhere if necessary.
[!TIP] Newer version available: You are on a supported minor version, but it looks like there's a newer patch available - 0.77.2. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.
[!TIP] Newer version available: You are on a supported minor version, but it looks like there's a newer patch available - undefined. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.
I've verified that this issue persists on 0.77 and the latest version of react-native.
I've also filed an issue for the missing documentation of this feature.
If i remember correctly, the getBoundingClientRect is not stable yet, and u can access it by calling ref.current.unstable_getBoundingClientRect
Just to confirm @bryanmylee, have you tried using this as you describe? If so, could you please add a code snippet to your reproducer that we can check? (I don't see it in the reproducer you linked.)
Maybe we need to add unstable_getBoundingClientRect instead to the type definitions if it works like @FightFarewellFearless pointed out.
Sorry work has been rough, but yes I've used it as I described and it works as expected, which is why I was surprised it wasn't in the type definition.
still an issue on 0.81
is the feature stable or not? as it's only mentioned at the blog post from new arch
I believe this is fixed as of 0.83.0.