Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Wrong menu position in Menu component #4493

Open
alex-fournier opened this issue Sep 10, 2024 · 7 comments
Open

[Android] Wrong menu position in Menu component #4493

alex-fournier opened this issue Sep 10, 2024 · 7 comments
Labels
Milestone

Comments

@alex-fournier
Copy link
Contributor

Current behaviour

In Menu component, the menu is not positioned as expected when visible. For example with anchorPosition="bottom", the menu comes over the anchor.

Expected behaviour

The menu should appear under anchor.

How to reproduce?

https://snack.expo.dev/@alexfournier/ludicrous-green-churros

Tested with two physical devices: Google Pixel 7 and Samsung Galaxy S24.

actual expected
actual expected

What have you tried so far?

When passing the correct status bar height using statusBarHeight, it works fine. I think this piece of code is not working as expected as it returns 0 on my two devices:

// src/constants.tsx
const estimatedStatusBarHeight =
  NativeModules.NativeUnimoduleProxy?.modulesConstants?.ExponentConstants
    ?.statusBarHeight ?? 0;

Your Environment

software version
android 14
react-native 0.74.5
react-native-paper 5.12.5
node 20.10.0
npm or yarn 1.22.19
expo sdk 51.0.32
@gedu
Copy link
Contributor

gedu commented Sep 12, 2024

Hey, yes, there seems to be something on Android that requires a deeper investigation. Would you like to contribute?

@alex-fournier
Copy link
Contributor Author

alex-fournier commented Sep 12, 2024

I think the regression comes from this commit in Expo: https://github.com/expo/expo/pull/28014/files

Constants from expo-constants are not exported anymore so NativeModules.NativeUnimoduleProxy.modulesConstants is now empty.

We could use StatusBar.currentHeight and apply this value only when status bar is set as translucent but I didn't find a way to know this without native code yet.

Or maybe using insets from react-native-safe-area-context could do the job.

@gedu
Copy link
Contributor

gedu commented Sep 12, 2024

Yes, there is a comment that we should replace it with react-native-safe-area-context probably with

import { useSafeAreaInsets } from 'react-native-safe-area-context';

@alex-fournier
Copy link
Contributor Author

I am working on a PR to fix that.

@Ge0ffreyS
Copy link

Ge0ffreyS commented Nov 12, 2024

Hello,
I've also noticed this bug on Android when the menu is displayed from an Appbar. I've tried to compensate by adding some padding, but it doesn't work.
Have you managed to fix it?

@alex-fournier
Copy link
Contributor Author

Hello, I have this fix in my code:

import Constants from 'expo-constants'

<Menu
  statusBarHeight={Constants.statusBarHeight}
  ...
/>

The PR with the fix is still open...

@Vadko
Copy link

Vadko commented Dec 20, 2024

+1, @alex-fournier solution worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants