Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ const Menu = ({
return;
}

if (!display && prevRendered.current) {
if (!display) {
hide();
}

Expand Down Expand Up @@ -432,15 +432,23 @@ const Menu = ({
if (prevVisible.current !== visible) {
prevVisible.current = visible;

if (visible !== rendered) {
setRendered(visible);
if (visible) {
if (!rendered) {
// Mount the Portal before attempting to show.
setRendered(true);
}
} else {
// Keep the Portal mounted so the hide animation can finish.
updateVisibility(false);
}
}
}, [visible, rendered]);
}, [visible, rendered, updateVisibility]);

React.useEffect(() => {
updateVisibility(rendered);
}, [rendered, updateVisibility]);
if (rendered && visible) {
updateVisibility(true);
}
}, [rendered, visible, updateVisibility]);

// I don't know why but on Android measure function is wrong by 24
const additionalVerticalValue = Platform.select({
Expand Down Expand Up @@ -641,6 +649,7 @@ const Menu = ({
accessibilityLabel={overlayAccessibilityLabel}
accessibilityRole="button"
onPress={onDismiss}
pointerEvents={visible ? 'auto' : 'none'}
style={styles.pressableOverlay}
/>
<View
Expand Down
12 changes: 10 additions & 2 deletions src/components/__tests__/Menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ it('uses the default anchorPosition of top', async () => {
// componentDidUpdate isn't called by default in jest. Forcing the update
// than triggers measureInWindow, which is how Menu decides where to show
// itself.
screen.update(makeMenu(true));
await act(async () => {
screen.update(makeMenu(true));
// Menu waits a tick for Portal refs to be up-to-date.
await Promise.resolve();
});

await waitFor(() => {
const menu = screen.getByTestId('menu-view');
Expand Down Expand Up @@ -163,7 +167,11 @@ it('respects anchorPosition bottom', async () => {
.spyOn(View.prototype, 'measureInWindow')
.mockImplementation((fn) => fn(100, 100, 80, 32));

screen.update(makeMenu(true));
await act(async () => {
screen.update(makeMenu(true));
// Menu waits a tick for Portal refs to be up-to-date.
await Promise.resolve();
});

await waitFor(() => {
const menu = screen.getByTestId('menu-view');
Expand Down
2 changes: 2 additions & 0 deletions src/components/__tests__/__snapshots__/Menu.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ exports[`renders menu with content styles 1`] = `
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
pointerEvents="auto"
style={
{
"bottom": 0,
Expand Down Expand Up @@ -933,6 +934,7 @@ exports[`renders visible menu 1`] = `
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
pointerEvents="auto"
style={
{
"bottom": 0,
Expand Down