Skip to content

Commit 37be401

Browse files
committed
fix: correct menu position with translucent status bar
1 parent 7e938cf commit 37be401

File tree

7 files changed

+17
-399
lines changed

7 files changed

+17
-399
lines changed

example/src/Examples/MenuExample.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ const MenuExample = ({ navigation }: Props) => {
153153
anchorPosition="bottom"
154154
anchor={
155155
<Button mode="outlined" onPress={_toggleMenu('menu5')}>
156-
Menu with anchor position
156+
Menu with anchor position bottom
157157
</Button>
158158
}
159159
>

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
"eslint": "8.31.0",
8585
"eslint-plugin-flowtype": "^8.0.3",
8686
"eslint-plugin-local-rules": "^1.3.2",
87-
"expo-constants": "~15.4.6",
8887
"glob": "^7.1.3",
8988
"husky": "^1.3.1",
9089
"jest": "^29.6.3",

src/components/Menu/Menu.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import {
2020
Pressable,
2121
} from 'react-native';
2222

23+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
24+
2325
import MenuItem from './MenuItem';
24-
import { APPROX_STATUSBAR_HEIGHT } from '../../constants';
2526
import { useInternalTheme } from '../../core/theming';
2627
import type { MD3Elevation, ThemeProp } from '../../types';
2728
import { ElevationLevels } from '../../types';
@@ -182,7 +183,7 @@ const isBrowser = () => Platform.OS === 'web' && 'document' in global;
182183

183184
const Menu = ({
184185
visible,
185-
statusBarHeight = APPROX_STATUSBAR_HEIGHT,
186+
statusBarHeight,
186187
overlayAccessibilityLabel = 'Close menu',
187188
testID = 'menu',
188189
anchor,
@@ -197,6 +198,7 @@ const Menu = ({
197198
keyboardShouldPersistTaps,
198199
}: Props) => {
199200
const theme = useInternalTheme(themeOverrides);
201+
const insets = useSafeAreaInsets();
200202
const [rendered, setRendered] = React.useState(visible);
201203
const [left, setLeft] = React.useState(0);
202204
const [top, setTop] = React.useState(0);
@@ -444,7 +446,7 @@ const Menu = ({
444446

445447
// I don't know why but on Android measure function is wrong by 24
446448
const additionalVerticalValue = Platform.select({
447-
android: statusBarHeight,
449+
android: statusBarHeight ?? insets.top,
448450
default: 0,
449451
});
450452

src/components/__tests__/DataTable.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import * as React from 'react';
22

33
import { render } from '@testing-library/react-native';
4+
import mockSafeAreaContext from 'react-native-safe-area-context/jest/mock';
45

56
import Checkbox from '../Checkbox';
67
import DataTable from '../DataTable/DataTable';
78

9+
jest.mock('react-native-safe-area-context', () => mockSafeAreaContext);
10+
811
describe('DataTable.Header', () => {
912
it('renders data table header', () => {
1013
const tree = render(

src/components/__tests__/Menu.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import * as React from 'react';
22
import { Animated, StyleSheet, View } from 'react-native';
33

44
import { act, render, screen, waitFor } from '@testing-library/react-native';
5+
import mockSafeAreaContext from 'react-native-safe-area-context/jest/mock';
56

67
import { getTheme } from '../../core/theming';
78
import { MD3Elevation } from '../../types';
89
import Button from '../Button/Button';
910
import Menu, { ELEVATION_LEVELS_MAP } from '../Menu/Menu';
1011
import Portal from '../Portal/Portal';
1112

13+
jest.mock('react-native-safe-area-context', () => mockSafeAreaContext);
14+
1215
const styles = StyleSheet.create({
1316
contentStyle: {
1417
borderTopLeftRadius: 0,

src/constants.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)