diff --git a/.github/workflows/ReleaseUtils.yml b/.github/workflows/ReleaseUtils.yml new file mode 100644 index 000000000..91eccfcfd --- /dev/null +++ b/.github/workflows/ReleaseUtils.yml @@ -0,0 +1,119 @@ +name: Release internal utilities + +# Packs @mendix/piw-native-utils-internal and attaches the tarball to a GitHub release, the way mendix-native is +# released, so the Mendix client can depend on it through the release's download URL, for example +# "@mendix/piw-native-utils-internal": "https://github.com/mendix/native-widgets/releases/download/piw-native-utils-internal-v1.1.0/piw-native-utils-internal-v1.1.0.tgz" +# Only run it by hand: it publishes a release. + +on: + workflow_dispatch: + inputs: + version: + description: "Version bump type" + required: true + type: choice + options: + - patch + - minor + - major + +permissions: {} + +env: + PACKAGE_DIR: packages/tools/piw-native-utils-internal + PACKAGE_NAME: "@mendix/piw-native-utils-internal" + +jobs: + release: + name: "Pack and release" + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: "Checking-out code" + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + fetch-depth: 0 + - name: "Defining node version" + uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 + with: + node-version-file: ".nvmrc" + package-manager-cache: false + - name: "Setup pnpm" + uses: pnpm/action-setup@a8198c4bff370c8506180b035930dea56dbd5288 # v5 + + - name: "Calculating the next version" + id: version + env: + BUMP: ${{ inputs.version }} + run: | + cd "$PACKAGE_DIR" + CURRENT=$(node -p "require('./package.json').version") + # Bumps package.json only: no git tag, no lifecycle scripts + NEXT=$(npm version "$BUMP" --no-git-tag-version --ignore-scripts | sed 's/^v//') + echo "current=$CURRENT" >> "$GITHUB_OUTPUT" + echo "next=$NEXT" >> "$GITHUB_OUTPUT" + echo "tag=piw-native-utils-internal-v$NEXT" >> "$GITHUB_OUTPUT" + echo "Version $CURRENT -> $NEXT ($BUMP)" + + - name: "Checking the release does not exist yet" + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ steps.version.outputs.tag }} + run: | + if git ls-remote --tags origin | grep -q "refs/tags/$TAG$"; then + echo "::error::The tag $TAG already exists" + exit 1 + fi + if gh release view "$TAG" &>/dev/null; then + echo "::error::The release $TAG already exists" + exit 1 + fi + + - name: "Installing dependencies" + # The internal utilities are built once below instead of by the workspace lifecycle scripts + run: pnpm install --frozen-lockfile --ignore-scripts + - name: "Building internal utilities" + run: pnpm run build:internal-utils + - name: "Linting and testing" + run: | + pnpm --filter "$PACKAGE_NAME" run lint + pnpm --filter "$PACKAGE_NAME" run test + + - name: "Packing" + id: pack + env: + TAG: ${{ steps.version.outputs.tag }} + run: | + mkdir -p "$RUNNER_TEMP/pack" + # Ships a package.json without scripts: the build scripts of this workspace package would fail on install + TARBALL=$(node "$PACKAGE_DIR/scripts/pack.mjs" "$RUNNER_TEMP/pack" "$TAG.tgz") + echo "tarball=$TARBALL" >> "$GITHUB_OUTPUT" + echo "Tarball contents:" + tar -tzf "$TARBALL" + + - name: "Creating the release" + uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0 + with: + tag_name: ${{ steps.version.outputs.tag }} + name: ${{ steps.version.outputs.tag }} + body: "Internal utilities of the native widgets (@mendix/piw-native-utils-internal ${{ steps.version.outputs.next }}), packed for use as a dependency of the Mendix client. Not a widget release." + files: ${{ steps.pack.outputs.tarball }} + target_commitish: ${{ github.sha }} + fail_on_unmatched_files: true + draft: false + prerelease: false + # This repository's widget releases decide what "latest" is + make_latest: "false" + + - name: "Opening a pull request with the version bump" + uses: peter-evans/create-pull-request@84ae59a2cdc2258d6fa0732dd66352dddae2a412 # v7.0.9 + with: + commit-message: "chore: release piw-native-utils-internal ${{ steps.version.outputs.next }}" + branch: release/piw-native-utils-internal-${{ steps.version.outputs.next }} + title: "Release piw-native-utils-internal ${{ steps.version.outputs.next }}" + body: "Updates the version of @mendix/piw-native-utils-internal for the release ${{ steps.version.outputs.tag }}." + base: ${{ github.ref_name }} + add-paths: ${{ env.PACKAGE_DIR }}/package.json diff --git a/configs/e2e/native_dependencies.json b/configs/e2e/native_dependencies.json index d2ec18a7e..3bf375907 100644 --- a/configs/e2e/native_dependencies.json +++ b/configs/e2e/native_dependencies.json @@ -3,7 +3,6 @@ "react-native-geocoder": "0.5.0", "react-native-device-info": "15.0.2", "react-native-action-button": "2.8.5", - "react-native-material-menu": "1.2.0", "react-native-linear-gradient": "2.8.3", "@react-native-community/netinfo": "11.5.2", "react-native-svg": "15.15.4", diff --git a/packages/pluggableWidgets/popup-menu-native/CHANGELOG.md b/packages/pluggableWidgets/popup-menu-native/CHANGELOG.md index 4fd0d0473..ae9e5399e 100644 --- a/packages/pluggableWidgets/popup-menu-native/CHANGELOG.md +++ b/packages/pluggableWidgets/popup-menu-native/CHANGELOG.md @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Changed + +- The menu is now presented through the shared MxMenu component instead of react-native-material-menu, which has been removed as a dependency. The style keys, the four item style classes and the ripple colour keep working as before. +- Screen readers now treat the popup as a menu with menu items, report whether the menu is open on the trigger, and return focus to the trigger when the menu closes. +- Items no longer crash the app when a style sets a font size of 0. +- On iOS an item now dims and shows the ripple colour as its background while it is pressed, the same as on the drop-down. Before it used the default highlight of a touchable. + ## [4.1.1] - 2026-9-2 ### Changed diff --git a/packages/pluggableWidgets/popup-menu-native/package.json b/packages/pluggableWidgets/popup-menu-native/package.json index 8efa113a1..e1309e68b 100644 --- a/packages/pluggableWidgets/popup-menu-native/package.json +++ b/packages/pluggableWidgets/popup-menu-native/package.json @@ -1,7 +1,7 @@ { "name": "popup-menu-native", "widgetName": "PopupMenu", - "version": "4.1.1", + "version": "4.2.0", "license": "Apache-2.0", "repository": { "type": "git", @@ -20,11 +20,9 @@ }, "dependencies": { "@mendix/piw-native-utils-internal": "*", - "@mendix/piw-utils-internal": "*", - "react-native-material-menu": "1.2.0" + "@mendix/piw-utils-internal": "*" }, "devDependencies": { - "@mendix/pluggable-widgets-tools": "*", - "@types/react-native-material-menu": "^1.0.6" + "@mendix/pluggable-widgets-tools": "*" } } diff --git a/packages/pluggableWidgets/popup-menu-native/src/PopupMenu.tsx b/packages/pluggableWidgets/popup-menu-native/src/PopupMenu.tsx index 2819768e0..2a7e7c38b 100644 --- a/packages/pluggableWidgets/popup-menu-native/src/PopupMenu.tsx +++ b/packages/pluggableWidgets/popup-menu-native/src/PopupMenu.tsx @@ -1,42 +1,38 @@ -import { ComponentType, ReactElement, useCallback, useRef, Fragment } from "react"; +import { ComponentType, ReactElement, useCallback } from "react"; import { PopupMenuProps } from "../typings/PopupMenuProps"; import { PopupMenuStyle } from "./ui/Styles"; import { executeAction } from "@mendix/piw-utils-internal"; +import { MxMenu, MxMenuDivider, MxMenuItem, useMxMenu } from "@mendix/piw-native-utils-internal"; import { Platform, StyleSheet, - TouchableHighlight, - TouchableHighlightProps, TouchableNativeFeedback, TouchableNativeFeedbackProps, TouchableOpacity, View } from "react-native"; import { ActionValue } from "mendix"; -import Menu, { MenuDivider, MenuItem } from "react-native-material-menu"; - -const TouchableItem: ComponentType = - Platform.OS === "android" ? TouchableNativeFeedback : TouchableHighlight; const TouchableButton: ComponentType = Platform.OS === "android" ? TouchableNativeFeedback : TouchableOpacity; +// Custom items hold whatever the app puts in them, so they do not get the minimum size of a text item +const customItemDefaults = { minHeight: 0, minWidth: 0, justifyContent: "flex-start" } as const; +const basicItemDefaults = { height: 48, maxWidth: 248 } as const; + export function PopupMenu(props: PopupMenuProps): ReactElement { const styles = StyleSheet.flatten(props.style); - const menuRef = useRef(null); - const showMenu = useCallback(() => { - menuRef.current?.show(); - }, [menuRef.current]); + const { anchorRef, anchor, visible, expanded, open, close } = useMxMenu(); const handlePress = useCallback( (action?: ActionValue) => { - menuRef.current?.hide(); + close(); // Set timeout needed since modal closes the alerts which might be shown in action setTimeout(() => { executeAction(action); }, 500); }, - [menuRef.current] + [close] ); let menuOptions: ReactElement[]; @@ -44,67 +40,68 @@ export function PopupMenu(props: PopupMenuProps): ReactElement { menuOptions = props.basicItems.map((item, index) => { const itemStyle = styles.basic?.itemStyle && styles.basic?.itemStyle[item.styleClass]; return item.itemType === "divider" ? ( - + ) : ( - handlePress(item.action)} textStyle={itemStyle} - ellipsizeMode={styles.basic?.itemStyle?.ellipsizeMode as any} - style={styles.basic?.container as any} + ellipsizeMode={styles.basic?.itemStyle?.ellipsizeMode} + style={[basicItemDefaults, styles.basic?.container]} {...getRippleColor(styles.basic?.itemStyle?.rippleColor)} testID={`${props.name}_basic-item`} > {item.caption} - + ); }); } else { menuOptions = props.customItems.map((item, index) => ( - handlePress(item.action)} {...getRippleColor(styles.custom?.itemStyle?.rippleColor)} testID={`${props.name}_custom-item`} > - {Platform.OS === "android" ? ( - {item.content} - ) : ( - {item.content} - )} - + {item.content} + )); } return ( - + <> + + {props.menuTriggerer} - } - > - + {menuOptions} - - + + ); } -function getRippleColor(color: string | undefined) { - if (color) { - return Platform.OS === "android" - ? color && { background: TouchableNativeFeedback.Ripple(color, false) } - : { underlayColor: color }; - } - return undefined; +/** + * One style key, two platform behaviours: rippleColor is the colour of the ripple on Android and the + * background shown while an item is pressed on iOS. The menu item picks the one for its platform. + */ +function getRippleColor(color: string | undefined): { rippleColor: string; underlayColor: string } | undefined { + return color ? { rippleColor: color, underlayColor: color } : undefined; } diff --git a/packages/pluggableWidgets/popup-menu-native/src/__tests__/PopupMenu.spec.tsx b/packages/pluggableWidgets/popup-menu-native/src/__tests__/PopupMenu.spec.tsx index 70a230428..2c370a651 100644 --- a/packages/pluggableWidgets/popup-menu-native/src/__tests__/PopupMenu.spec.tsx +++ b/packages/pluggableWidgets/popup-menu-native/src/__tests__/PopupMenu.spec.tsx @@ -1,11 +1,9 @@ import { PopupMenuProps } from "../../typings/PopupMenuProps"; import { defaultPopupMenuStyle, PopupMenuStyle } from "../ui/Styles"; -import { Text, View } from "react-native"; +import { Modal, Platform, StyleSheet, Text, View } from "react-native"; import { actionValue } from "@mendix/piw-utils-internal"; -import { act, fireEvent, render, within } from "@testing-library/react-native"; +import { act, fireEvent, render, RenderAPI, within } from "@testing-library/react-native"; import { PopupMenu } from "../PopupMenu"; -import { MenuDivider, MenuItem } from "react-native-material-menu"; -import { ReactTestInstance } from "react-test-renderer"; let dummyActionValue: any; let defaultProps: PopupMenuProps; @@ -14,17 +12,32 @@ jest.useFakeTimers(); let basicItemTestId: string; let customItemTestId: string; -jest.mock("react-native/Libraries/Modal/Modal", () => { - const MockedModal = jest.requireActual("react-native").View; +const flat = (style: unknown): Record => + (StyleSheet.flatten(style as never) as Record | undefined) ?? {}; - return { - __esModule: true, - default: (props: any) => - }; -}); +/** The props the menu item gave to React Native's Pressable (it is a wrapped component, so it cannot be found by type) */ +const pressableProps = (component: RenderAPI, testID: string): Record => + component.UNSAFE_root.findAll( + node => typeof node.type !== "string" && node.props.testID === testID && "disabled" in node.props + )[0].props; + +const openMenu = (component: RenderAPI): void => { + fireEvent.press(component.getByTestId("popup-menu_trigger")); + // The menu is shown a frame after the trigger has been measured + act(() => { + jest.advanceTimersByTime(20); + }); +}; describe("Popup menu", () => { + const originalOS = Platform.OS; + beforeEach(() => { + // The trigger is measured when the menu opens + jest.spyOn(View.prototype as unknown as { measureInWindow: () => void }, "measureInWindow").mockImplementation( + ((callback: (x: number, y: number, width: number, height: number) => void) => + callback(100, 300, 40, 30)) as never + ); dummyActionValue = actionValue(); defaultProps = { popupRenderMode: "basic", @@ -42,6 +55,11 @@ describe("Popup menu", () => { customItemTestId = `${defaultProps.name}_custom-item`; }); + afterEach(() => { + (Platform as { OS: string }).OS = originalOS; + jest.restoreAllMocks(); + }); + it("renders", () => { const component = render(); @@ -54,12 +72,36 @@ describe("Popup menu", () => { expect(component.toJSON()).toMatchSnapshot(); }); + describe("the trigger", () => { + it("opens the menu", () => { + const component = render(); + expect(component.queryByTestId("popup-menu_menu")).toBeNull(); + + openMenu(component); + + expect(component.getByTestId("popup-menu_menu")).toBeTruthy(); + }); + + it("is a button that says whether the menu is open", () => { + const component = render(); + const trigger = (): Record => component.getByTestId("popup-menu_trigger").props; + + expect(trigger().accessibilityRole).toBe("button"); + expect(trigger().accessibilityState).toMatchObject({ expanded: false }); + + openMenu(component); + + expect(trigger().accessibilityState).toMatchObject({ expanded: true }); + }); + }); + describe("in basic mode", () => { - it("renders only basic items", async () => { + it("renders only basic items", () => { const component = render(); + openMenu(component); const basicItems = component.queryAllByTestId(basicItemTestId); - const dividers = component.UNSAFE_queryAllByType(MenuDivider); + const dividers = component.queryAllByTestId("popup-menu_divider", { includeHiddenElements: true }); const customItems = component.queryAllByTestId(customItemTestId); expect(basicItems).toHaveLength(1); expect(within(basicItems[0]).getByText("yolo")).not.toBeNull(); @@ -67,19 +109,98 @@ describe("Popup menu", () => { expect(customItems).toHaveLength(0); }); - it("triggers action", () => { + it("renders the items in a menu", () => { const component = render(); - const basicItem = component.UNSAFE_root.findByType(MenuItem); - expect(basicItem).toBeDefined(); - expect(basicItem.props.testID).toBe(basicItemTestId); + openMenu(component); - fireEvent.press(basicItem); + expect(component.getByTestId("popup-menu_menu").props.accessibilityRole).toBe("menu"); + expect(component.getByTestId(basicItemTestId).props.accessibilityRole).toBe("menuitem"); + }); + + it("triggers action and closes the menu", () => { + const component = render(); + openMenu(component); + fireEvent.press(component.getByTestId(basicItemTestId)); + + // The action waits until the menu is gone, because the modal would close alerts the action shows + expect(dummyActionValue.execute).not.toHaveBeenCalled(); act(() => { jest.advanceTimersByTime(501); }); expect(dummyActionValue.execute).toHaveBeenCalled(); + expect(component.queryByTestId("popup-menu_menu")).toBeNull(); + }); + + it("closes with the Android back button without running an action", () => { + const component = render(); + openMenu(component); + + act(() => component.UNSAFE_getByType(Modal).props.onRequestClose()); + act(() => { + jest.advanceTimersByTime(501); + }); + + expect(component.queryByTestId("popup-menu_menu")).toBeNull(); + expect(dummyActionValue.execute).not.toHaveBeenCalled(); + }); + + it("applies the divider colour and the item container style", () => { + const component = render( + + ); + openMenu(component); + + expect( + flat(component.getByTestId("popup-menu_divider", { includeHiddenElements: true }).props.style) + .borderBottomColor + ).toBe("#123456"); + const row = component + .getByTestId(basicItemTestId) + .findAll(node => typeof node.type === "string" && flat(node.props.style).backgroundColor === "pink")[0]; + expect(flat(row.props.style)).toMatchObject({ height: 64, maxWidth: 248 }); + }); + + describe("styleClass", () => { + const styleClasses = ["defaultStyle", "primaryStyle", "dangerStyle", "customStyle"] as const; + const colors = { + defaultStyle: "#111111", + primaryStyle: "#222222", + dangerStyle: "#333333", + customStyle: "#444444" + }; + const customStyle = [ + { + basic: { + itemStyle: Object.fromEntries(styleClasses.map(name => [name, { color: colors[name] }])) + } + } + ] as unknown as PopupMenuProps["style"]; + + it.each(["android", "ios"] as const)("styles each of the four classes with its own style on %s", os => { + (Platform as { OS: string }).OS = os; + const component = render( + ({ + itemType: "item" as const, + styleClass, + caption: styleClass, + action: dummyActionValue + }))} + /> + ); + openMenu(component); + + for (const styleClass of styleClasses) { + expect(flat(component.getByText(styleClass).props.style).color).toBe(colors[styleClass]); + } + }); }); it("renders with custom styles", () => { @@ -95,9 +216,44 @@ describe("Popup menu", () => { } ]; const component = render(); - expect(component.getByTestId(basicItemTestId).findByType(Text).props.style).toEqual( - expect.arrayContaining([{ color: "green" }]) - ); + openMenu(component); + + expect(flat(component.getByText("yolo").props.style).color).toBe("green"); + }); + + describe("rippleColor", () => { + const rippleStyle = [{ basic: { itemStyle: { rippleColor: "#00aa00" } } }]; + + it("is the ripple of the item on Android", () => { + (Platform as { OS: string }).OS = "android"; + const component = render(); + openMenu(component); + + const props = pressableProps(component, basicItemTestId); + + expect(props.android_ripple).toMatchObject({ color: "#00aa00", borderless: false }); + expect(typeof props.style).not.toBe("function"); + }); + + it("is the colour shown while the item is pressed on iOS", () => { + (Platform as { OS: string }).OS = "ios"; + const component = render(); + openMenu(component); + + const props = pressableProps(component, basicItemTestId); + + expect(props.android_ripple).toBeUndefined(); + expect(flat(props.style({ pressed: true }))).toMatchObject({ backgroundColor: "#00aa00" }); + expect(flat(props.style({ pressed: false }))).not.toHaveProperty("backgroundColor"); + }); + + it("falls back to the default feedback when it is not set", () => { + (Platform as { OS: string }).OS = "android"; + const component = render(); + openMenu(component); + + expect(pressableProps(component, basicItemTestId).android_ripple.color).toBe("rgba(0, 0, 0, 0.2)"); + }); }); }); @@ -108,9 +264,10 @@ describe("Popup menu", () => { it("renders only custom items", () => { const component = render(); + openMenu(component); const basicItems = component.queryAllByTestId(basicItemTestId); - const dividers = component.UNSAFE_queryAllByType(MenuDivider); + const dividers = component.queryAllByTestId("popup-menu_divider", { includeHiddenElements: true }); const customItems = component.queryAllByTestId(customItemTestId); expect(basicItems).toHaveLength(0); expect(dividers).toHaveLength(0); @@ -120,6 +277,8 @@ describe("Popup menu", () => { it("triggers action", () => { const component = render(); + openMenu(component); + fireEvent.press(component.getByTestId(customItemTestId)); act(() => { @@ -138,11 +297,43 @@ describe("Popup menu", () => { } ]; const component = render(); - const modal = component.getByTestId("modal"); - const firstView = within(modal).UNSAFE_getByType(View); - const secondView = within(firstView.children[0] as ReactTestInstance).UNSAFE_getByType(View); - expect(secondView.props.style.backgroundColor).toEqual("yellow"); - expect(within(secondView).getByText("Yolo")).not.toBeNull(); + openMenu(component); + + const [surface] = component.UNSAFE_root.findAll( + node => typeof node.type === "string" && flat(node.props.style).backgroundColor === "yellow" + ); + expect(surface).toBeDefined(); + expect(within(surface).getByText("Yolo")).not.toBeNull(); + }); + + it("does not force a minimum size on custom items, and applies the custom container style", () => { + const component = render( + + ); + openMenu(component); + + const row = component + .getByTestId(customItemTestId) + .findAll(node => typeof node.type === "string" && flat(node.props.style).backgroundColor === "pink")[0]; + + expect(flat(row.props.style)).toMatchObject({ minHeight: 0, minWidth: 0 }); + }); + + it("uses the custom rippleColor on both platforms", () => { + const rippleStyle = [{ custom: { itemStyle: { rippleColor: "#aa0000" } } }]; + + (Platform as { OS: string }).OS = "android"; + const android = render(); + openMenu(android); + expect(pressableProps(android, customItemTestId).android_ripple.color).toBe("#aa0000"); + android.unmount(); + + (Platform as { OS: string }).OS = "ios"; + const ios = render(); + openMenu(ios); + expect(flat(pressableProps(ios, customItemTestId).style({ pressed: true })).backgroundColor).toBe( + "#aa0000" + ); }); }); diff --git a/packages/pluggableWidgets/popup-menu-native/src/__tests__/__snapshots__/PopupMenu.spec.tsx.snap b/packages/pluggableWidgets/popup-menu-native/src/__tests__/__snapshots__/PopupMenu.spec.tsx.snap index 86a2ee8a5..17c1f5e4f 100644 --- a/packages/pluggableWidgets/popup-menu-native/src/__tests__/__snapshots__/PopupMenu.spec.tsx.snap +++ b/packages/pluggableWidgets/popup-menu-native/src/__tests__/__snapshots__/PopupMenu.spec.tsx.snap @@ -4,198 +4,50 @@ exports[`Popup menu renders 1`] = ` - - - - - Menu Triggerer - - - - - - - - - - - - yolo - - - - - - - + + Menu Triggerer + @@ -205,173 +57,50 @@ exports[`Popup menu renders custom items 1`] = ` - - - - - Menu Triggerer - - - - - - - - - - - Yolo - - - - - + + Menu Triggerer + diff --git a/packages/pluggableWidgets/popup-menu-native/src/package.xml b/packages/pluggableWidgets/popup-menu-native/src/package.xml index 0e0cb079b..7f6a8af9c 100644 --- a/packages/pluggableWidgets/popup-menu-native/src/package.xml +++ b/packages/pluggableWidgets/popup-menu-native/src/package.xml @@ -1,6 +1,6 @@ - + diff --git a/packages/tools/piw-native-utils-internal/menu.d.ts b/packages/tools/piw-native-utils-internal/menu.d.ts new file mode 100644 index 000000000..680d0a705 --- /dev/null +++ b/packages/tools/piw-native-utils-internal/menu.d.ts @@ -0,0 +1 @@ +export * from "./dist/components/menu"; diff --git a/packages/tools/piw-native-utils-internal/menu.js b/packages/tools/piw-native-utils-internal/menu.js new file mode 100644 index 000000000..6d2d5a414 --- /dev/null +++ b/packages/tools/piw-native-utils-internal/menu.js @@ -0,0 +1,3 @@ +// Lets other packages import the menu without loading the rest of the utilities: +// import { MxMenu } from "@mendix/piw-native-utils-internal/menu"; +module.exports = require("./dist/components/menu"); diff --git a/packages/tools/piw-native-utils-internal/package.json b/packages/tools/piw-native-utils-internal/package.json index a8b4636aa..91a00c255 100644 --- a/packages/tools/piw-native-utils-internal/package.json +++ b/packages/tools/piw-native-utils-internal/package.json @@ -14,6 +14,11 @@ "packagePath": "com.mendix.utils", "main": "dist/index.js", "types": "dist/index.d.ts", + "files": [ + "dist", + "menu.js", + "menu.d.ts" + ], "sideEffects": false, "scripts": { "start": "tsc --watch", diff --git a/packages/tools/piw-native-utils-internal/scripts/pack.mjs b/packages/tools/piw-native-utils-internal/scripts/pack.mjs new file mode 100644 index 000000000..952294de9 --- /dev/null +++ b/packages/tools/piw-native-utils-internal/scripts/pack.mjs @@ -0,0 +1,53 @@ +// Packs the utilities into a tarball that other projects can install, for example the Mendix client: +// node scripts/pack.mjs [file name] +// +// The package.json that ships in the tarball has no scripts and no dev dependencies. The scripts of this +// workspace package (postinstall and prepare build the sources) would otherwise run when the tarball is installed +// and fail, because the sources are not part of it. +import { execFileSync } from "node:child_process"; +import { copyFileSync, cpSync, existsSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { dirname, join, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; + +const packageDir = resolve(dirname(fileURLToPath(import.meta.url)), ".."); +const destination = resolve(process.argv[2] ?? "."); +const fileName = process.argv[3]; + +if (!existsSync(join(packageDir, "dist"))) { + throw new Error("There is no dist folder. Build the package first."); +} + +const stage = mkdtempSync(join(tmpdir(), "piw-native-utils-pack-")); +try { + cpSync(join(packageDir, "dist"), join(stage, "dist"), { recursive: true }); + for (const file of ["menu.js", "menu.d.ts"]) { + copyFileSync(join(packageDir, file), join(stage, file)); + } + // The licence lives in the root of the repository + const license = resolve(packageDir, "../../../LICENSE"); + if (existsSync(license)) { + copyFileSync(license, join(stage, "LICENSE")); + } + + const manifest = JSON.parse(readFileSync(join(packageDir, "package.json"), "utf8")); + delete manifest.scripts; + delete manifest.devDependencies; + writeFileSync(join(stage, "package.json"), `${JSON.stringify(manifest, null, 2)}\n`); + + const packed = execFileSync("npm", ["pack", "--pack-destination", destination, "--silent"], { + cwd: stage, + encoding: "utf8" + }) + .trim() + .split("\n") + .pop(); + + const result = fileName ? join(destination, fileName) : join(destination, packed); + if (fileName) { + renameSync(join(destination, packed), result); + } + console.log(result); +} finally { + rmSync(stage, { recursive: true, force: true }); +} diff --git a/packages/tools/piw-native-utils-internal/src/components/MxOverlay.tsx b/packages/tools/piw-native-utils-internal/src/components/MxOverlay.tsx index e1f3abafc..2c6166640 100644 --- a/packages/tools/piw-native-utils-internal/src/components/MxOverlay.tsx +++ b/packages/tools/piw-native-utils-internal/src/components/MxOverlay.tsx @@ -42,6 +42,8 @@ export interface MxOverlayProps { initialFocusRef?: RefObject; /** Element that receives accessibility focus once the overlay has closed, typically the trigger. */ returnFocusRef?: RefObject; + /** Called once the overlay has completely closed: the exit animation is done and the modal is gone. */ + onClosed?: () => void; /** Enter/exit duration in ms. 0 disables the animation. Defaults to 200. */ animationDuration?: number; /** Render a transparent modal so what is behind shows through. When false the platform provides an opaque background. Defaults to true. */ @@ -83,6 +85,7 @@ export function MxOverlay(props: MxOverlayProps): ReactElement | null { const { visible, onRequestClose, + onClosed, dismissOnBackPress = true, dismissOnBackdropPress = true, placement = "center", @@ -111,9 +114,10 @@ export function MxOverlay(props: MxOverlayProps): ReactElement | null { useEffect(() => { if (wasMounted.current && !mounted) { moveFocusTo(returnFocusRef); + onClosed?.(); } wasMounted.current = mounted; - }, [mounted, returnFocusRef]); + }, [mounted, returnFocusRef, onClosed]); useEffect(() => { if (visible) { diff --git a/packages/tools/piw-native-utils-internal/src/components/__tests__/MxOverlay.spec.tsx b/packages/tools/piw-native-utils-internal/src/components/__tests__/MxOverlay.spec.tsx index 6545adf14..8802b0ba7 100644 --- a/packages/tools/piw-native-utils-internal/src/components/__tests__/MxOverlay.spec.tsx +++ b/packages/tools/piw-native-utils-internal/src/components/__tests__/MxOverlay.spec.tsx @@ -247,6 +247,59 @@ describe.each(["ios", "android"] as const)("MxOverlay on %s", os => { }); }); + it("tells when it has closed, once the exit animation is done", () => { + jest.useFakeTimers(); + try { + const onClosed = jest.fn(); + const element = (visible: boolean): ReactElement => ( + + content + + ); + const { rerender } = render(element(true)); + act(() => { + jest.advanceTimersByTime(250); + }); + expect(onClosed).not.toHaveBeenCalled(); + + rerender(element(false)); + expect(onClosed).not.toHaveBeenCalled(); + + act(() => { + jest.advanceTimersByTime(250); + }); + expect(onClosed).toHaveBeenCalledTimes(1); + } finally { + jest.useRealTimers(); + } + }); + + it("tells when it has closed without an animation", () => { + const onClosed = jest.fn(); + const element = (visible: boolean): ReactElement => ( + + content + + ); + const { rerender } = render(element(true)); + + rerender(element(false)); + + expect(onClosed).toHaveBeenCalledTimes(1); + }); + + it("does not tell it has closed when it was never shown", () => { + const onClosed = jest.fn(); + + render( + + content + + ); + + expect(onClosed).not.toHaveBeenCalled(); + }); + it("renders nothing while hidden", () => { const { queryByTestId } = renderOverlay({ visible: false }); diff --git a/packages/tools/piw-native-utils-internal/src/components/menu/MxMenu.tsx b/packages/tools/piw-native-utils-internal/src/components/menu/MxMenu.tsx new file mode 100644 index 000000000..2f0ab5e7c --- /dev/null +++ b/packages/tools/piw-native-utils-internal/src/components/menu/MxMenu.tsx @@ -0,0 +1,159 @@ +import { ReactElement, ReactNode, RefObject, useCallback, useState } from "react"; +import { + I18nManager, + LayoutChangeEvent, + Platform, + StatusBar, + StyleProp, + StyleSheet, + useWindowDimensions, + View, + ViewStyle +} from "react-native"; +import { MxOverlay } from "../MxOverlay"; +import { computeMenuPosition, MenuPlacement, MenuRect, MenuSize, toStyleLeft } from "./position"; + +const DEFAULT_ANIMATION_DURATION = 150; +const DEFAULT_RADIUS = 4; +const transparentBackdrop: ViewStyle = { backgroundColor: "transparent" }; + +export interface MxMenuProps { + visible: boolean; + /** Where the trigger is, see useMxMenu */ + anchor: MenuRect | null; + /** Called for a press outside the menu and for the Android back button */ + onRequestClose: () => void; + /** "overlap" puts the menu on the trigger like a Material menu, "below" puts it under it like a drop-down */ + placement?: MenuPlacement; + /** Make the menu as wide as the trigger */ + matchAnchorWidth?: boolean; + maxHeight?: number; + /** Styles the menu surface. It has a white background, rounded corners and a shadow unless this changes them */ + style?: StyleProp; + animationDuration?: number; + /** Receives accessibility focus when the menu has closed, the trigger */ + returnFocusRef?: RefObject; + accessibilityLabel?: string; + /** On the element that holds the items. The overlay's own elements get "-overlay" as a suffix. */ + testID?: string; + children?: ReactNode; +} + +/** + * A menu that opens next to its trigger. It is presented through MxOverlay, so it gets the back button, + * focus handling and modal behaviour of every overlay, and adds the menu role. + * + * About the double modal on iOS: the drop-down in the client re-created the library's menu with a new `key` + * every time it had hidden, because the modal could otherwise show twice on iOS. That is kept: once the overlay + * has completely closed (its modal is gone) it is remounted, so every opening starts from a fresh overlay and + * there is never more than one modal. + */ +export function MxMenu(props: MxMenuProps): ReactElement { + const { + visible, + anchor, + onRequestClose, + placement = "overlap", + matchAnchorWidth = false, + maxHeight, + style, + animationDuration = DEFAULT_ANIMATION_DURATION, + returnFocusRef, + accessibilityLabel, + testID, + children + } = props; + + const { width, height } = useWindowDimensions(); + // The modal starts below the status bar (see statusBarTranslucent below), so that part of the window is not + // available to the menu. react-native-material-menu took it off the window height in the same way. + const window = { width, height: height - (StatusBar.currentHeight ?? 0) }; + const [size, setSize] = useState(null); + const [instance, setInstance] = useState(0); + + const handleLayout = useCallback(({ nativeEvent: { layout } }: LayoutChangeEvent) => { + setSize(previous => + previous && previous.width === layout.width && previous.height === layout.height + ? previous + : { width: layout.width, height: layout.height } + ); + }, []); + + const handleClosed = useCallback(() => { + setSize(null); + setInstance(count => count + 1); + }, []); + + const rtl = I18nManager.isRTL; + const position = anchor && size ? computeMenuPosition({ anchor, menu: size, window, rtl, placement }) : null; + const swapsInRtl = rtl && I18nManager.doLeftAndRightSwapInRTL; + + const surfaceStyle = StyleSheet.flatten([styles.surface, style]); + + return ( + + + + {children} + + + + ); +} + +const styles = StyleSheet.create({ + surface: { + backgroundColor: "white", + borderRadius: DEFAULT_RADIUS, + ...Platform.select({ + ios: { + shadowColor: "black", + shadowOffset: { width: 0, height: 2 }, + shadowOpacity: 0.14, + shadowRadius: 2 + }, + default: { elevation: 8 } + }) + }, + // Lets the items shrink to the menu's maximum height, so a list inside can scroll + clip: { + overflow: "hidden", + flexShrink: 1 + }, + measuring: { + opacity: 0 + } +}); diff --git a/packages/tools/piw-native-utils-internal/src/components/menu/MxMenuDivider.tsx b/packages/tools/piw-native-utils-internal/src/components/menu/MxMenuDivider.tsx new file mode 100644 index 000000000..29c3187f0 --- /dev/null +++ b/packages/tools/piw-native-utils-internal/src/components/menu/MxMenuDivider.tsx @@ -0,0 +1,25 @@ +import { ReactElement } from "react"; +import { StyleSheet, View } from "react-native"; + +export interface MxMenuDividerProps { + color?: string; + testID?: string; +} + +export function MxMenuDivider({ color = "rgba(0, 0, 0, 0.12)", testID }: MxMenuDividerProps): ReactElement { + return ( + + ); +} + +const styles = StyleSheet.create({ + divider: { + flex: 1, + borderBottomWidth: StyleSheet.hairlineWidth + } +}); diff --git a/packages/tools/piw-native-utils-internal/src/components/menu/MxMenuItem.tsx b/packages/tools/piw-native-utils-internal/src/components/menu/MxMenuItem.tsx new file mode 100644 index 000000000..2981e74de --- /dev/null +++ b/packages/tools/piw-native-utils-internal/src/components/menu/MxMenuItem.tsx @@ -0,0 +1,144 @@ +import { ReactElement, ReactNode } from "react"; +import { + Platform, + Pressable, + StyleProp, + StyleSheet, + Text, + TextProps, + TextStyle, + TouchableNativeFeedback, + View, + ViewStyle +} from "react-native"; + +const DEFAULT_RIPPLE_COLOR = "rgba(0, 0, 0, 0.2)"; +const DEFAULT_ACTIVE_OPACITY = 0.2; +const DEFAULT_DISABLED_TEXT_COLOR = "#bdbdbd"; + +export interface MxMenuItemProps { + /** Text is wrapped in a single line label; any other content is rendered as is */ + children?: ReactNode; + onPress?: () => void; + disabled?: boolean; + /** Marks the item as the chosen one for screen readers, as in a drop-down */ + selected?: boolean; + /** Android: the colour of the press ripple */ + rippleColor?: string; + /** iOS: the background shown while the item is pressed */ + underlayColor?: string; + /** iOS: how transparent the item gets while pressed */ + activeOpacity?: number; + ellipsizeMode?: TextProps["ellipsizeMode"]; + textStyle?: StyleProp; + disabledTextColor?: string; + style?: StyleProp; + accessibilityLabel?: string; + testID?: string; +} + +/** + * fontSize: 0 crashes React Native's new architecture, so it is turned into a hidden text instead. + * https://github.com/facebook/react-native/blob/0d3a7ca52faea4dbe0dac5b9894b4f8bb5f380b3/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/TextAttributeProps.java#L400 + */ +function withoutZeroFontSize(style: StyleProp): StyleProp { + const flat = StyleSheet.flatten(style); + if (flat && flat.fontSize === 0) { + const rest = { ...flat }; + delete rest.fontSize; + return { ...rest, display: "none" }; + } + return style; +} + +export function MxMenuItem(props: MxMenuItemProps): ReactElement { + const { + children, + onPress, + disabled = false, + selected, + rippleColor, + underlayColor, + activeOpacity, + ellipsizeMode, + textStyle, + disabledTextColor = DEFAULT_DISABLED_TEXT_COLOR, + style, + accessibilityLabel, + testID + } = props; + + const content = + typeof children === "string" || typeof children === "number" ? ( + + {children} + + ) : ( + children + ); + + const accessibility = { + accessibilityRole: "menuitem" as const, + accessibilityLabel, + accessibilityState: { disabled, selected }, + testID + }; + + if (Platform.OS === "android") { + return ( + + {content} + + ); + } + + // iOS has no ripple: show the underlay colour and dim the item while it is pressed + return ( + + pressed + ? { + ...(underlayColor !== undefined && { backgroundColor: underlayColor }), + opacity: activeOpacity ?? DEFAULT_ACTIVE_OPACITY + } + : undefined + } + > + {content} + + ); +} + +const styles = StyleSheet.create({ + container: { + minHeight: 48, + minWidth: 124, + justifyContent: "center" + }, + text: { + fontSize: 14, + fontWeight: "400", + paddingHorizontal: 16, + textAlign: "left" + } +}); diff --git a/packages/tools/piw-native-utils-internal/src/components/menu/__tests__/MxMenu.spec.tsx b/packages/tools/piw-native-utils-internal/src/components/menu/__tests__/MxMenu.spec.tsx new file mode 100644 index 000000000..7c82eb6bc --- /dev/null +++ b/packages/tools/piw-native-utils-internal/src/components/menu/__tests__/MxMenu.spec.tsx @@ -0,0 +1,294 @@ +import { act, fireEvent, render, RenderAPI } from "@testing-library/react-native"; +import { ReactElement } from "react"; +import { I18nManager, Modal, StatusBar, StyleSheet, Text } from "react-native"; +import { MxMenu, MxMenuProps } from "../MxMenu"; + +const mockOverlayMounted = jest.fn(); +jest.mock("../../MxOverlay", () => { + const actual = jest.requireActual("../../MxOverlay"); + const react = jest.requireActual("react"); + return { + ...actual, + // Counts how often the overlay is created, to see when the menu starts over with a fresh one + MxOverlay: (props: unknown): unknown => { + react.useEffect(() => { + mockOverlayMounted(); + }, []); + return actual.MxOverlay(props); + } + }; +}); + +// The jest window is 750 x 1334 +const anchor = { x: 100, y: 300, width: 180, height: 40 }; +const menuSize = { width: 150, height: 200 }; + +const flat = (style: unknown): Record => + (StyleSheet.flatten(style as never) as Record | undefined) ?? {}; + +const element = (props: Partial = {}): ReactElement => ( + + item + +); + +/** The element that gets the menu's look and is measured */ +const surfaceOf = (component: RenderAPI): ReturnType[number] => + component.UNSAFE_root.findAll( + node => + typeof node.type === "string" && + typeof node.props.onLayout === "function" && + flat(node.props.style).backgroundColor !== undefined + )[0]; + +const measure = (component: RenderAPI, size = menuSize): void => { + fireEvent(surfaceOf(component), "layout", { nativeEvent: { layout: { x: 0, y: 0, ...size } } }); +}; + +const overlayPosition = (component: RenderAPI): { top: unknown; left: unknown } => { + const style = flat(component.getByTestId("menu-overlay-content").props.style); + return { top: style.top, left: style.left }; +}; + +const originalStatusBarHeight = Object.getOwnPropertyDescriptor(StatusBar, "currentHeight"); +const setStatusBarHeight = (value: number): void => { + Object.defineProperty(StatusBar, "currentHeight", { value, configurable: true }); +}; + +describe("MxMenu", () => { + beforeEach(() => { + mockOverlayMounted.mockClear(); + // Jest reports a status bar of 42, which the positions below should not depend on + setStatusBarHeight(0); + }); + + afterEach(() => { + if (originalStatusBarHeight) { + Object.defineProperty(StatusBar, "currentHeight", originalStatusBarHeight); + } + }); + + describe("placing the menu", () => { + it("is invisible until it has been measured", () => { + const component = render(element()); + + expect(flat(surfaceOf(component).props.style).opacity).toBe(0); + + measure(component); + + expect(flat(surfaceOf(component).props.style).opacity).toBeUndefined(); + }); + + it("puts the menu on the trigger by default", () => { + const component = render(element()); + measure(component); + + expect(overlayPosition(component)).toEqual({ top: 300, left: 100 }); + }); + + it("puts the menu under the trigger with placement below", () => { + const component = render(element({ placement: "below" })); + measure(component); + + expect(overlayPosition(component)).toEqual({ top: 340, left: 100 }); + }); + + it("keeps the menu on the screen", () => { + const component = render(element({ anchor: { x: 700, y: 1300, width: 40, height: 30 } })); + measure(component); + + expect(overlayPosition(component)).toEqual({ top: 1126, left: 590 }); + }); + + it("is not drawn under the status bar, so it is placed in the space the trigger was measured in", () => { + const component = render(element()); + + expect(component.UNSAFE_getByType(Modal).props.statusBarTranslucent).toBe(false); + }); + + describe("with a status bar", () => { + beforeEach(() => setStatusBarHeight(24)); + + it("does not count the status bar as room below the trigger", () => { + const component = render(element({ anchor: { x: 700, y: 1300, width: 40, height: 30 } })); + measure(component); + + // 1334 - 24 = 1310 of room, so the menu's top is at 1310 - 8 - 200 instead of 1334 - 8 - 200 + expect(overlayPosition(component)).toEqual({ top: 1102, left: 590 }); + }); + + it("places a menu that fits exactly where the trigger is", () => { + const component = render(element()); + measure(component); + + expect(overlayPosition(component)).toEqual({ top: 300, left: 100 }); + }); + }); + + it("makes the menu as wide as the trigger", () => { + const component = render(element({ matchAnchorWidth: true })); + + expect(flat(surfaceOf(component).props.style).width).toBe(180); + }); + + it("limits the height", () => { + const component = render(element({ maxHeight: 120 })); + + expect(flat(surfaceOf(component).props.style).maxHeight).toBe(120); + }); + + describe("right to left", () => { + const original = { isRTL: I18nManager.isRTL, swap: I18nManager.doLeftAndRightSwapInRTL }; + const setRtl = (isRTL: boolean, swap: boolean): void => { + Object.assign(I18nManager, { isRTL, doLeftAndRightSwapInRTL: swap }); + }; + + afterEach(() => setRtl(original.isRTL, original.swap)); + + it("aligns with the trigger's right edge and turns x into the swapped left", () => { + setRtl(true, true); + const component = render(element()); + measure(component); + + // x = 280 - 150 = 130, and left is the distance from the right edge: 750 - 130 - 150 + expect(overlayPosition(component)).toEqual({ top: 300, left: 470 }); + }); + + it("uses x as is when left and right are not swapped", () => { + setRtl(true, false); + const component = render(element()); + measure(component); + + expect(overlayPosition(component)).toEqual({ top: 300, left: 130 }); + }); + }); + }); + + describe("the menu", () => { + it("is a menu", () => { + const component = render(element({ accessibilityLabel: "Actions" })); + const menu = component.getByTestId("menu"); + + expect(menu.props.accessibilityRole).toBe("menu"); + expect(menu.props.accessibilityLabel).toBe("Actions"); + }); + + it("has a white, rounded surface with a shadow unless the style says otherwise", () => { + const component = render(element()); + const surface = flat(surfaceOf(component).props.style); + + expect(surface).toMatchObject({ backgroundColor: "white", borderRadius: 4 }); + expect(flat(component.getByTestId("menu").props.style)).toMatchObject({ + overflow: "hidden", + borderRadius: 4 + }); + }); + + it("applies the style on top, and rounds the clipping with the same radius", () => { + const component = render(element({ style: { backgroundColor: "#eeeeee", borderRadius: 12 } })); + + expect(flat(surfaceOf(component).props.style)).toMatchObject({ + backgroundColor: "#eeeeee", + borderRadius: 12 + }); + expect(flat(component.getByTestId("menu").props.style).borderRadius).toBe(12); + }); + }); + + describe("closing", () => { + it("closes with a press outside the menu", () => { + const onRequestClose = jest.fn(); + const component = render(element({ onRequestClose })); + + fireEvent.press(component.getByTestId("menu-overlay-backdrop", { includeHiddenElements: true })); + + expect(onRequestClose).toHaveBeenCalledTimes(1); + }); + + it("closes with the Android back button", () => { + const onRequestClose = jest.fn(); + const component = render(element({ onRequestClose })); + + act(() => component.UNSAFE_getByType(Modal).props.onRequestClose()); + + expect(onRequestClose).toHaveBeenCalledTimes(1); + }); + + it("has a see-through backdrop", () => { + const component = render(element()); + const backdrop = component.getByTestId("menu-overlay-backdrop", { includeHiddenElements: true }); + const [dim] = backdrop.findAll(node => node.props.pointerEvents === "none"); + + expect(flat(dim.props.style)).toMatchObject({ backgroundColor: "transparent" }); + }); + }); + + describe("never more than one modal (the iOS double modal)", () => { + const showing = (visible: boolean): ReactElement => element({ visible }); + + it("starts over with a fresh overlay every time the menu has completely closed", () => { + const component = render(showing(false)); + expect(mockOverlayMounted).toHaveBeenCalledTimes(1); + + component.rerender(showing(true)); + expect(component.UNSAFE_queryAllByType(Modal)).toHaveLength(1); + expect(mockOverlayMounted).toHaveBeenCalledTimes(1); + + component.rerender(showing(false)); + expect(component.UNSAFE_queryAllByType(Modal)).toHaveLength(0); + expect(mockOverlayMounted).toHaveBeenCalledTimes(2); + + component.rerender(showing(true)); + expect(component.UNSAFE_queryAllByType(Modal)).toHaveLength(1); + expect(mockOverlayMounted).toHaveBeenCalledTimes(2); + + component.rerender(showing(false)); + expect(mockOverlayMounted).toHaveBeenCalledTimes(3); + }); + + it("keeps a single modal when it is opened again while it is still closing", () => { + jest.useFakeTimers(); + try { + const animated = (visible: boolean): ReactElement => element({ visible, animationDuration: 200 }); + const component = render(animated(true)); + act(() => { + jest.advanceTimersByTime(250); + }); + + // Under Jest the exit animation completes on the first timer tick, so before that it is still closing + component.rerender(animated(false)); + expect(component.UNSAFE_queryAllByType(Modal)).toHaveLength(1); + + component.rerender(animated(true)); + expect(component.UNSAFE_queryAllByType(Modal)).toHaveLength(1); + act(() => { + jest.advanceTimersByTime(250); + }); + + expect(component.UNSAFE_queryAllByType(Modal)).toHaveLength(1); + expect(mockOverlayMounted).toHaveBeenCalledTimes(1); + } finally { + jest.useRealTimers(); + } + }); + + it("never has two modals across quick open and close cycles", () => { + const component = render(showing(false)); + const counts: number[] = []; + + for (let i = 0; i < 5; i++) { + component.rerender(showing(true)); + counts.push(component.UNSAFE_queryAllByType(Modal).length); + component.rerender(showing(false)); + counts.push(component.UNSAFE_queryAllByType(Modal).length); + } + + expect(Math.max(...counts)).toBe(1); + expect(counts.filter(count => count === 0)).toHaveLength(5); + }); + }); + + it("renders its children", () => { + expect(render(element()).getByText("item")).toBeTruthy(); + }); +}); diff --git a/packages/tools/piw-native-utils-internal/src/components/menu/__tests__/MxMenuItem.spec.tsx b/packages/tools/piw-native-utils-internal/src/components/menu/__tests__/MxMenuItem.spec.tsx new file mode 100644 index 000000000..2d84207d1 --- /dev/null +++ b/packages/tools/piw-native-utils-internal/src/components/menu/__tests__/MxMenuItem.spec.tsx @@ -0,0 +1,228 @@ +import { fireEvent, render, RenderAPI } from "@testing-library/react-native"; +import { Platform, StyleSheet, Text, View } from "react-native"; +import { MxMenuDivider } from "../MxMenuDivider"; +import { MxMenuItem, MxMenuItemProps } from "../MxMenuItem"; + +const setPlatform = (os: "ios" | "android"): void => { + (Platform as { OS: string }).OS = os; +}; + +const flat = (style: unknown): Record => + (StyleSheet.flatten(style as never) as Record | undefined) ?? {}; + +/** The props the item gave to React Native's Pressable (it is a wrapped component, so it cannot be found by type) */ +const pressableProps = (component: RenderAPI): Record => + component.UNSAFE_root.findAll( + node => typeof node.type !== "string" && node.props.testID === "item" && "disabled" in node.props + )[0].props; + +const renderItem = (props: Partial = {}): RenderAPI => + render( + + {props.children ?? "Label"} + + ); + +describe("MxMenuItem", () => { + const originalOS = Platform.OS; + + afterEach(() => { + (Platform as { OS: string }).OS = originalOS; + }); + + describe("content", () => { + it("renders text on a single line", () => { + const text = renderItem().getByText("Label"); + + expect(text.props.numberOfLines).toBe(1); + expect(flat(text.props.style)).toMatchObject({ fontSize: 14, paddingHorizontal: 16, textAlign: "left" }); + }); + + it.each([ + ["ios", "clip"], + ["android", "tail"] + ] as const)("clips overflowing text with %s defaults", (os, mode) => { + setPlatform(os); + + expect(renderItem().getByText("Label").props.ellipsizeMode).toBe(mode); + }); + + it("lets the caller choose how overflowing text is clipped", () => { + expect(renderItem({ ellipsizeMode: "middle" }).getByText("Label").props.ellipsizeMode).toBe("middle"); + }); + + it("renders other content as is", () => { + const component = renderItem({ children: }); + + expect(component.getByTestId("custom")).toBeTruthy(); + expect(component.UNSAFE_queryAllByType(Text)).toHaveLength(0); + }); + + it("applies the text style on top of the defaults", () => { + const text = renderItem({ textStyle: { color: "#123456", fontSize: 20 } }).getByText("Label"); + + expect(flat(text.props.style)).toMatchObject({ color: "#123456", fontSize: 20, paddingHorizontal: 16 }); + }); + + it("hides the text instead of rendering fontSize 0, which crashes the new architecture", () => { + const text = renderItem({ textStyle: { fontSize: 0 } }).getByText("Label", { includeHiddenElements: true }); + const style = flat(text.props.style); + + expect(style.display).toBe("none"); + expect(style).not.toHaveProperty("fontSize"); + }); + + it("applies the item style to the row", () => { + const component = renderItem({ style: { height: 48, maxWidth: 248 } }); + const [row] = component.UNSAFE_root.findAll( + node => typeof node.type === "string" && flat(node.props.style).minHeight === 48 + ); + + expect(flat(row.props.style)).toMatchObject({ minHeight: 48, minWidth: 124, height: 48, maxWidth: 248 }); + }); + }); + + describe("menu accessibility", () => { + it("is a menu item", () => { + expect(renderItem().getByTestId("item").props.accessibilityRole).toBe("menuitem"); + }); + + it("is reported as enabled or disabled", () => { + expect(renderItem().getByTestId("item").props.accessibilityState).toMatchObject({ disabled: false }); + expect(renderItem({ disabled: true }).getByTestId("item").props.accessibilityState).toMatchObject({ + disabled: true + }); + }); + + it("is reported as selected", () => { + expect(renderItem({ selected: true }).getByTestId("item").props.accessibilityState).toMatchObject({ + selected: true + }); + expect(renderItem().getByTestId("item").props.accessibilityState.selected).toBeUndefined(); + }); + + it("passes an accessibility label", () => { + expect(renderItem({ accessibilityLabel: "Delete" }).getByTestId("item").props.accessibilityLabel).toBe( + "Delete" + ); + }); + }); + + describe("pressing", () => { + it("calls onPress", () => { + const onPress = jest.fn(); + const component = renderItem({ onPress }); + + fireEvent.press(component.getByTestId("item")); + + expect(onPress).toHaveBeenCalledTimes(1); + }); + + it("does nothing when disabled", () => { + const onPress = jest.fn(); + const component = renderItem({ onPress, disabled: true }); + + fireEvent.press(component.getByTestId("item")); + + expect(onPress).not.toHaveBeenCalled(); + }); + + it("greys out disabled text, unless the text style sets a colour", () => { + expect(flat(renderItem({ disabled: true }).getByText("Label").props.style).color).toBe("#bdbdbd"); + expect( + flat(renderItem({ disabled: true, disabledTextColor: "#999999" }).getByText("Label").props.style).color + ).toBe("#999999"); + expect( + flat(renderItem({ disabled: true, textStyle: { color: "#ff0000" } }).getByText("Label").props.style) + .color + ).toBe("#ff0000"); + }); + }); + + describe("Android press feedback", () => { + beforeEach(() => setPlatform("android")); + + it("uses a bounded ripple with the default colour", () => { + const ripple = pressableProps(renderItem()).android_ripple; + + expect(ripple).toMatchObject({ color: "rgba(0, 0, 0, 0.2)", borderless: false }); + }); + + it("uses the ripple colour", () => { + expect(pressableProps(renderItem({ rippleColor: "#00ff00" })).android_ripple.color).toBe("#00ff00"); + }); + + it("ignores the iOS underlay", () => { + expect(typeof pressableProps(renderItem({ underlayColor: "#ff0000" })).style).not.toBe("function"); + }); + }); + + describe("iOS press feedback", () => { + beforeEach(() => setPlatform("ios")); + + const pressedStyle = (props: Partial): Record => { + return flat(pressableProps(renderItem(props)).style({ pressed: true })); + }; + + it("has no ripple", () => { + expect(pressableProps(renderItem()).android_ripple).toBeUndefined(); + }); + + it("shows nothing while it is not pressed", () => { + expect(flat(pressableProps(renderItem({ underlayColor: "#ff0000" })).style({ pressed: false }))).toEqual( + {} + ); + }); + + it("shows the underlay colour and dims while pressed", () => { + expect(pressedStyle({ underlayColor: "#ff0000" })).toMatchObject({ + backgroundColor: "#ff0000", + opacity: 0.2 + }); + }); + + it("only dims while pressed when there is no underlay colour", () => { + const style = pressedStyle({}); + + expect(style.opacity).toBe(0.2); + expect(style).not.toHaveProperty("backgroundColor"); + }); + + it("uses the active opacity", () => { + expect(pressedStyle({ activeOpacity: 0.6 }).opacity).toBe(0.6); + }); + + it("ignores the Android ripple colour", () => { + expect(pressedStyle({ rippleColor: "#00ff00" })).not.toHaveProperty("backgroundColor"); + }); + }); +}); + +describe("MxMenuDivider", () => { + it("is a hairline with the default colour", () => { + const divider = render().getByTestId("divider", { + includeHiddenElements: true + }); + + expect(flat(divider.props.style)).toMatchObject({ + borderBottomWidth: StyleSheet.hairlineWidth, + borderBottomColor: "rgba(0, 0, 0, 0.12)" + }); + }); + + it("uses the colour", () => { + const divider = render().getByTestId("divider", { + includeHiddenElements: true + }); + + expect(flat(divider.props.style).borderBottomColor).toBe("#abcdef"); + }); + + it("is hidden from screen readers", () => { + const divider = render().getByTestId("divider", { + includeHiddenElements: true + }); + + expect(divider.props.importantForAccessibility).toBe("no"); + }); +}); diff --git a/packages/tools/piw-native-utils-internal/src/components/menu/__tests__/position.spec.ts b/packages/tools/piw-native-utils-internal/src/components/menu/__tests__/position.spec.ts new file mode 100644 index 000000000..54dabfdfe --- /dev/null +++ b/packages/tools/piw-native-utils-internal/src/components/menu/__tests__/position.spec.ts @@ -0,0 +1,85 @@ +import { computeMenuPosition, MenuPositionInput, toStyleLeft } from "../position"; + +const window = { width: 400, height: 800 }; +const menu = { width: 150, height: 200 }; + +const position = (overrides: Partial): { x: number; y: number } => + computeMenuPosition({ + anchor: { x: 100, y: 300, width: 80, height: 40 }, + menu, + window, + ...overrides + }); + +describe("computeMenuPosition", () => { + describe("left to right", () => { + it("puts the menu on the trigger when there is room", () => { + expect(position({})).toEqual({ x: 100, y: 300 }); + }); + + it("aligns with the trigger's right edge when the menu would run off the right of the screen", () => { + // trigger spans 300..380, a 150 wide menu from 300 would end at 450 + expect(position({ anchor: { x: 300, y: 300, width: 80, height: 40 } })).toEqual({ x: 230, y: 300 }); + }); + + it("keeps the indent when the trigger itself touches the right edge", () => { + expect(position({ anchor: { x: 360, y: 300, width: 40, height: 40 } }).x).toBe(242); + }); + + it("keeps the indent from the left edge", () => { + expect(position({ anchor: { x: 2, y: 300, width: 80, height: 40 } }).x).toBe(8); + }); + }); + + describe("right to left", () => { + it("aligns with the trigger's right edge", () => { + expect(position({ rtl: true })).toEqual({ x: 30, y: 300 }); + }); + + it("falls back to the trigger's left edge when the menu would run off the left of the screen", () => { + expect(position({ rtl: true, anchor: { x: 20, y: 300, width: 80, height: 40 } }).x).toBe(20); + }); + + it("still keeps the indent from the right edge", () => { + expect(position({ rtl: true, anchor: { x: 330, y: 300, width: 70, height: 40 } }).x).toBe(242); + }); + }); + + describe("vertical", () => { + it("moves up to keep the indent from the bottom of the screen", () => { + expect(position({ anchor: { x: 100, y: 700, width: 80, height: 40 } }).y).toBe(592); + }); + + it("keeps the indent from the top of the screen", () => { + expect(position({ anchor: { x: 100, y: 2, width: 80, height: 40 } }).y).toBe(8); + }); + + it("never goes above the indent when the menu is taller than the screen", () => { + expect(position({ menu: { width: 150, height: 900 } }).y).toBe(8); + }); + }); + + describe("placement below", () => { + it("puts the menu right under the trigger", () => { + expect(position({ placement: "below" })).toEqual({ x: 100, y: 340 }); + }); + + it("still stays inside the screen", () => { + expect(position({ placement: "below", anchor: { x: 100, y: 700, width: 80, height: 40 } }).y).toBe(592); + }); + }); + + it("uses a custom indent", () => { + expect(position({ indent: 20, anchor: { x: 2, y: 2, width: 80, height: 40 } })).toEqual({ x: 20, y: 20 }); + }); +}); + +describe("toStyleLeft", () => { + it("keeps x where left and right are not swapped", () => { + expect(toStyleLeft(30, 150, 400, false)).toBe(30); + }); + + it("turns x into the distance from the right edge where they are swapped", () => { + expect(toStyleLeft(30, 150, 400, true)).toBe(220); + }); +}); diff --git a/packages/tools/piw-native-utils-internal/src/components/menu/__tests__/useMxMenu.spec.tsx b/packages/tools/piw-native-utils-internal/src/components/menu/__tests__/useMxMenu.spec.tsx new file mode 100644 index 000000000..7b5dd5f23 --- /dev/null +++ b/packages/tools/piw-native-utils-internal/src/components/menu/__tests__/useMxMenu.spec.tsx @@ -0,0 +1,110 @@ +import { act, renderHook } from "@testing-library/react-native"; +import { View } from "react-native"; +import { MxMenuControl, useMxMenu } from "../useMxMenu"; + +type Measure = (callback: (x: number, y: number, width: number, height: number) => void) => void; + +/** A trigger that reports being at (10, 20) and 30 x 40 big */ +const attachAnchor = (control: MxMenuControl, measureInWindow: Measure): void => { + (control.anchorRef as { current: unknown }).current = { measureInWindow } as unknown as View; +}; + +const instantMeasure: Measure = callback => callback(10, 20, 30, 40); + +describe("useMxMenu", () => { + beforeEach(() => jest.useFakeTimers()); + afterEach(() => jest.useRealTimers()); + + const frame = (): void => { + act(() => { + jest.advanceTimersByTime(20); + }); + }; + + it("starts closed", () => { + const { result } = renderHook(() => useMxMenu()); + + expect(result.current.visible).toBe(false); + expect(result.current.expanded).toBe(false); + expect(result.current.anchor).toBeNull(); + }); + + it("measures the trigger when it opens, and shows the menu a frame later", () => { + const { result } = renderHook(() => useMxMenu()); + attachAnchor(result.current, instantMeasure); + + act(() => result.current.open()); + + expect(result.current.anchor).toEqual({ x: 10, y: 20, width: 30, height: 40 }); + expect(result.current.visible).toBe(false); + + frame(); + + expect(result.current.visible).toBe(true); + expect(result.current.expanded).toBe(true); + }); + + it("closes", () => { + const { result } = renderHook(() => useMxMenu()); + attachAnchor(result.current, instantMeasure); + act(() => result.current.open()); + frame(); + + act(() => result.current.close()); + + expect(result.current.visible).toBe(false); + expect(result.current.expanded).toBe(false); + }); + + it("measures again for every opening, so a trigger that moved is found", () => { + const { result } = renderHook(() => useMxMenu()); + const measure = jest.fn>(callback => callback(10, 20, 30, 40)); + attachAnchor(result.current, measure); + act(() => result.current.open()); + frame(); + act(() => result.current.close()); + + attachAnchor(result.current, callback => callback(50, 60, 70, 80)); + act(() => result.current.open()); + frame(); + + expect(measure).toHaveBeenCalledTimes(1); + expect(result.current.anchor).toEqual({ x: 50, y: 60, width: 70, height: 80 }); + }); + + it("does nothing when nothing is attached", () => { + const { result } = renderHook(() => useMxMenu()); + + act(() => result.current.open()); + frame(); + + expect(result.current.visible).toBe(false); + }); + + it("keeps its functions the same between renders", () => { + const { result, rerender } = renderHook(() => useMxMenu()); + const { open, close } = result.current; + + rerender({}); + + expect(result.current.open).toBe(open); + expect(result.current.close).toBe(close); + }); + + it("does not show the menu when it was unmounted while measuring", () => { + const { result, unmount } = renderHook(() => useMxMenu()); + let finishMeasuring: () => void = () => undefined; + attachAnchor(result.current, callback => { + finishMeasuring = () => callback(10, 20, 30, 40); + }); + const errors = jest.spyOn(console, "error").mockImplementation(() => undefined); + + act(() => result.current.open()); + unmount(); + finishMeasuring(); + frame(); + + expect(errors).not.toHaveBeenCalled(); + errors.mockRestore(); + }); +}); diff --git a/packages/tools/piw-native-utils-internal/src/components/menu/index.ts b/packages/tools/piw-native-utils-internal/src/components/menu/index.ts new file mode 100644 index 000000000..d979e4471 --- /dev/null +++ b/packages/tools/piw-native-utils-internal/src/components/menu/index.ts @@ -0,0 +1,5 @@ +export { MxMenu, MxMenuProps } from "./MxMenu"; +export { MxMenuItem, MxMenuItemProps } from "./MxMenuItem"; +export { MxMenuDivider, MxMenuDividerProps } from "./MxMenuDivider"; +export { useMxMenu, MxMenuControl } from "./useMxMenu"; +export { computeMenuPosition, MenuPlacement, MenuRect, MenuSize, MenuPositionInput } from "./position"; diff --git a/packages/tools/piw-native-utils-internal/src/components/menu/position.ts b/packages/tools/piw-native-utils-internal/src/components/menu/position.ts new file mode 100644 index 000000000..ce110deba --- /dev/null +++ b/packages/tools/piw-native-utils-internal/src/components/menu/position.ts @@ -0,0 +1,72 @@ +export interface MenuRect { + x: number; + y: number; + width: number; + height: number; +} + +export interface MenuSize { + width: number; + height: number; +} + +/** + * "overlap" puts the menu's top on the trigger's top, like a Material menu. + * "below" puts it right under the trigger, like a drop-down. + */ +export type MenuPlacement = "overlap" | "below"; + +export interface MenuPositionInput { + /** The trigger, in window coordinates */ + anchor: MenuRect; + /** The measured size of the menu */ + menu: MenuSize; + window: MenuSize; + rtl?: boolean; + placement?: MenuPlacement; + /** Minimum distance to keep from the screen edges */ + indent?: number; +} + +export const MENU_SCREEN_INDENT = 8; + +/** + * Where the menu goes, in physical window coordinates (x from the left edge, y from the top). + * + * Follows the rules react-native-material-menu applied, so existing menus land where they used to: + * - left to right menus align with the trigger's left edge; when that would run off the right edge of the + * screen they align with the trigger's right edge instead + * - right to left menus mirror that + * - the menu always stays `indent` away from every screen edge + */ +export function computeMenuPosition(input: MenuPositionInput): { x: number; y: number } { + const { anchor, menu, window, rtl = false, placement = "overlap", indent = MENU_SCREEN_INDENT } = input; + const anchorRight = anchor.x + anchor.width; + + let x: number; + if (rtl) { + x = anchorRight - menu.width; + if (x < indent) { + x = anchor.x; + } + } else { + x = anchor.x; + if (x + menu.width > window.width - indent) { + x = Math.min(window.width - indent, anchorRight) - menu.width; + } + } + x = Math.max(indent, Math.min(x, window.width - indent - menu.width)); + + let y = placement === "below" ? anchor.y + anchor.height : anchor.y; + y = Math.max(indent, Math.min(y, window.height - indent - menu.height)); + + return { x, y }; +} + +/** + * React Native swaps `left` and `right` styles in right to left layouts, so a physical x has to be turned + * into the value that `left` means there: the distance from the right edge. + */ +export function toStyleLeft(x: number, menuWidth: number, windowWidth: number, swapsInRtl: boolean): number { + return swapsInRtl ? windowWidth - x - menuWidth : x; +} diff --git a/packages/tools/piw-native-utils-internal/src/components/menu/useMxMenu.ts b/packages/tools/piw-native-utils-internal/src/components/menu/useMxMenu.ts new file mode 100644 index 000000000..b50a49fbe --- /dev/null +++ b/packages/tools/piw-native-utils-internal/src/components/menu/useMxMenu.ts @@ -0,0 +1,51 @@ +import { RefObject, useCallback, useEffect, useRef, useState } from "react"; +import { View } from "react-native"; +import { MenuRect } from "./position"; + +export interface MxMenuControl { + /** Put on the element that opens the menu: it is measured so the menu can be placed next to it */ + anchorRef: RefObject; + /** Where the trigger is in the window, as measured when the menu was opened */ + anchor: MenuRect | null; + visible: boolean; + /** Whether the menu is open, for the trigger's `accessibilityState.expanded` */ + expanded: boolean; + open: () => void; + close: () => void; +} + +/** + * Open and close state of a menu, plus the measuring of the element that opens it. + */ +export function useMxMenu(): MxMenuControl { + const anchorRef = useRef(null); + const mounted = useRef(true); + const [anchor, setAnchor] = useState(null); + const [visible, setVisible] = useState(false); + + useEffect(() => { + mounted.current = true; + return () => { + mounted.current = false; + }; + }, []); + + const open = useCallback(() => { + anchorRef.current?.measureInWindow((x, y, width, height) => { + if (!mounted.current) { + return; + } + setAnchor({ x, y, width, height }); + // Show the menu a frame later so it is placed using the anchor that was just measured + requestAnimationFrame(() => { + if (mounted.current) { + setVisible(true); + } + }); + }); + }, []); + + const close = useCallback(() => setVisible(false), []); + + return { anchorRef, anchor, visible, expanded: visible, open, close }; +} diff --git a/packages/tools/piw-native-utils-internal/src/index.ts b/packages/tools/piw-native-utils-internal/src/index.ts index 5ffd78bff..8a9361288 100644 --- a/packages/tools/piw-native-utils-internal/src/index.ts +++ b/packages/tools/piw-native-utils-internal/src/index.ts @@ -2,6 +2,21 @@ export { flattenStyles, Style } from "./styles"; export { only, exclude } from "./objectFilters"; export { available, toNumber, unavailable } from "./properties"; export { MxOverlay, MxOverlayProps, MxOverlayPlacement } from "./components/MxOverlay"; +export { + MxMenu, + MxMenuProps, + MxMenuItem, + MxMenuItemProps, + MxMenuDivider, + MxMenuDividerProps, + useMxMenu, + MxMenuControl, + computeMenuPosition, + MenuPlacement, + MenuRect, + MenuSize, + MenuPositionInput +} from "./components/menu"; export { Slider, SliderProps, RangeSlider, RangeSliderProps, RangeSliderValue } from "./components/Slider"; export { Bar, BarProps } from "./components/Bar"; export { Arc, ArcProps, makeArcPath } from "./components/Arc"; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7638fb0af..b4dc7a925 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -656,16 +656,10 @@ importers: '@mendix/piw-utils-internal': specifier: '*' version: link:../../tools/piw-utils-internal - react-native-material-menu: - specifier: 1.2.0 - version: 1.2.0(react-native@0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.86.1(@babel/core@7.29.7))(@types/react@19.2.17)(react@19.2.3))(react@19.2.3) devDependencies: '@mendix/pluggable-widgets-tools': specifier: 11.12.0 version: 11.12.0(patch_hash=c3d32a9026cacb93268037356ae25d0e56d1b9b3ecb22aea09cbf1c69542670e)(@jest/transform@30.3.0)(@jest/types@30.4.1)(@types/babel__core@7.20.5)(@types/node@20.19.43)(jest-util@30.4.1)(jiti@2.6.1)(picomatch@4.0.5)(react-dom@19.2.3(react@19.2.3))(react-native@0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.86.1(@babel/core@7.29.7))(@types/react@19.2.17)(react@19.2.3))(react@19.2.3)(tslib@2.8.1) - '@types/react-native-material-menu': - specifier: ^1.0.6 - version: 1.0.10(@babel/core@7.29.7)(@react-native/metro-config@0.86.1(@babel/core@7.29.7))(react@19.2.3) packages/pluggableWidgets/progress-bar-native: dependencies: @@ -2858,9 +2852,6 @@ packages: '@types/react-native-actionsheet@2.4.7': resolution: {integrity: sha512-OxseY74NqeSbUDLhXGuWmxrViZRQ0arLFGMcrkvm1RaWhOGGBMhVsa6LDjHTtk4fDkVGsnwakXyLo/iwJw/b3A==} - '@types/react-native-material-menu@1.0.10': - resolution: {integrity: sha512-aLrBRTswRNGWAtPZs6Hcis7Fw8cuMDV/I9WDXhdhwfHd8lM8yVH4674SMH1MjV38C1HnKf3oSa84MebS8Ow4yw==} - '@types/react-native-modal@4.1.1': resolution: {integrity: sha512-Synwj+cdwhHOi9SFNmu7voLv3AQM24e3Hy78Qz7nNb6spkftkv0gtaZlIWMJ5G0pywcs08JFX/cve8vCWUX6xw==} deprecated: This is a stub types definition for react-native-modal (https://github.com/react-native-community/react-native-modal). react-native-modal provides its own type definitions, so you don't need @types/react-native-modal installed! @@ -6423,12 +6414,6 @@ packages: react-native-web: optional: true - react-native-material-menu@1.2.0: - resolution: {integrity: sha512-1XbzJP8Uo09YjW0G8xuKcL2BD76BL/IYOq1KQuQ2yGMuwqBvfU/+AKvhvHWuckQK+bhcDSUgTWbH8qv1mRAX6w==} - peerDependencies: - react: 19.2.3 - react-native: 0.84.1 - react-native-modal@13.0.1: resolution: {integrity: sha512-UB+mjmUtf+miaG/sDhOikRfBOv0gJdBU2ZE1HtFWp6UixW9jCk/bhGdHUgmZljbPpp0RaO/6YiMmQSSK3kkMaw==} peerDependencies: @@ -10250,19 +10235,6 @@ snapshots: dependencies: '@types/react': 19.2.17 - '@types/react-native-material-menu@1.0.10(@babel/core@7.29.7)(@react-native/metro-config@0.86.1(@babel/core@7.29.7))(react@19.2.3)': - dependencies: - '@types/react': 19.2.17 - react-native: 0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.86.1(@babel/core@7.29.7))(@types/react@19.2.17)(react@19.2.3) - transitivePeerDependencies: - - '@babel/core' - - '@react-native-community/cli' - - '@react-native/metro-config' - - bufferutil - - react - - supports-color - - utf-8-validate - '@types/react-native-modal@4.1.1(react-native@0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.86.1(@babel/core@7.29.7))(@types/react@19.2.17)(react@19.2.3))(react@19.2.3)': dependencies: react-native-modal: 13.0.1(react-native@0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.86.1(@babel/core@7.29.7))(@types/react@19.2.17)(react@19.2.3))(react@19.2.3) @@ -14532,11 +14504,6 @@ snapshots: react: 19.2.3 react-native: 0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.86.1(@babel/core@7.29.7))(@types/react@19.2.17)(react@19.2.3) - react-native-material-menu@1.2.0(react-native@0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.86.1(@babel/core@7.29.7))(@types/react@19.2.17)(react@19.2.3))(react@19.2.3): - dependencies: - react: 19.2.3 - react-native: 0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.86.1(@babel/core@7.29.7))(@types/react@19.2.17)(react@19.2.3) - react-native-modal@13.0.1(react-native@0.84.1(@babel/core@7.29.7)(@react-native/metro-config@0.86.1(@babel/core@7.29.7))(@types/react@19.2.17)(react@19.2.3))(react@19.2.3): dependencies: prop-types: 15.8.1