Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ const Menu = ({
return;
}

scaleX.value = 0;
scaleY.value = 0;
setMenuLayout({ width: 0, height: 0 });
setRendered(false);
isShownRef.current = false;
Expand Down
54 changes: 54 additions & 0 deletions src/components/__tests__/Menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
jest,
} from '@jest/globals';
import { act, screen, waitFor } from '@testing-library/react-native';
import { getAnimatedStyle } from 'react-native-reanimated';

import { render } from '../../test-utils';
import { LightTheme } from '../../theme/schemes';
Expand Down Expand Up @@ -457,3 +458,56 @@ it('does not crash when Keyboard.metrics is unavailable (react-native-web)', asy
dimensionsSpy.mockRestore();
}
});

it('scales in again when reopened at the same anchor', async () => {
const testID = 'reopened-menu';
const measureSpy = jest
.spyOn(ViewPrototype, 'measureInWindow')
.mockImplementation((fn) => fn(100, 100, 80, 32));

function makeMenu(visible: boolean) {
return (
<Portal.Host>
<Menu
visible={visible}
onDismiss={jest.fn()}
anchor={<Button mode="outlined">Open menu</Button>}
testID={testID}
>
<Menu.Item onPress={jest.fn()} title="Undo" />
</Menu>
</Portal.Host>
);
}

const openAndSample = async () => {
await act(async () => {
await screen.rerender(makeMenu(true));
});
await act(() => jest.advanceTimersByTimeAsync(100));
const style = getAnimatedStyle(screen.getByTestId(testID));
await act(() => jest.advanceTimersByTimeAsync(500));
return style;
};

try {
await render(makeMenu(false));

const firstOpen = await openAndSample();
// Partway through the first open, the menu is still growing.
expect(firstOpen).not.toMatchObject({
transform: [{ scaleX: 1 }, { scaleY: 1 }],
});

await act(async () => {
await screen.rerender(makeMenu(false));
});
await act(() => jest.advanceTimersByTimeAsync(500));
expect(screen.queryByTestId(testID)).toBeNull();

const secondOpen = await openAndSample();
expect(secondOpen).toEqual(firstOpen);
} finally {
measureSpy.mockRestore();
}
});
Loading