react-navigation / react-navigation

Routing and navigation for your React Native apps
https://reactnavigation.org
23.64k stars 5.05k forks source link

[V7] While using `measureInWindow`, the `y` value is off #12294

Open mrzachnugent opened 4 days ago

mrzachnugent commented 4 days ago

Current behavior

Given a useLayoutEffect that calls the measureInWindow of a ref , the y value is off. It seems to be off by the header height on iOS and web. For Android, I'm not sure what is off by exactly.

When the header is transparent or not shown, the y value from measureInWindow is correct for iOS and web but it is still off on Android.

// In a screen with default options

  React.useLayoutEffect(() => {
    triggerRef.current?.measureInWindow((x, y, width, height) => {
      setTargetRect({ x, y, width, height });
    });
  }, [setTargetRect]);

 // ...

  <Pressable ref={triggerRef}
  // ...

  // This should place it right below the trigger
  <View 
    style={{
    // ...
      position: "absolute",
      top: targetRect.y + targetRect.height, 
    }}
  // ...

See minimal reproduction repo for more details

Expected behavior

Given a useLayoutEffect that calls the measureInWindow of a ref , the y value should not be off.

It was expected that the tooltip example from the react-native docs should work.

Reproduction

https://github.com/mrzachnugent/react-navigation-measure-in-window-repro

Platform

Packages

Environment

package version
@react-navigation/native ^7.0.0
expo-router ~4.0.5
react-native-safe-area-context 4.12.0
react-native-screens ~4.1.0
react-native-reanimated ~3.16.1
react-native 0.76.3
expo ^52.0.7
node 20.13.1
npm 10.5.2
github-actions[bot] commented 4 days ago

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

github-actions[bot] commented 4 days ago

Hey! Thanks for opening the issue. Seems that this issue is related to react-native-screens library which is a dependency of React Navigation. Can you also post your issue in this repo so that it's notified to the maintainers of that library? This will help us fix the issue faster since it's upto the maintainers of that library to investigate it.

mrzachnugent commented 4 days ago

I can confirm that the version used in the package-lock.json is using 7.0.4 for @react-navigation/native