Skip to content

fix: stop MenuView.show() from throwing on Android and iOS - #1265

Merged
Naturalclar merged 2 commits into
masterfrom
fix/show-android-args-ios-noop
Nov 25, 2026
Merged

Naturalclar merged 2 commits into
masterfrom
fix/show-android-args-ios-noop

Conversation

@Naturalclar

Copy link
Copy Markdown
Member

Fixes #1228, fixes #957.

Problem

Android (#1228). show() falls back to UIManager.dispatchViewManagerCommand(node, command, undefined) when global.nativeFabricUIManager isn't set. undefined reaches native code as null, and on the New Architecture that throws:

com.facebook.react.bridge.UnexpectedNativeTypeException: expected Array, got a null

The menu doesn't open, and the pressable that triggered it stays pressed. The reporter hit this on Expo SDK 57 / RN 0.86.

iOS (#957). MenuComponentRef declares show(): void, but src/UIMenuView.ios.tsx re-exported the native component directly, so the ref had no show. Shared code calling ref.current?.show() throws show is not a function. That's what the example app's "Show Menu with ref (Android only)" button did on iOS.

Change

  • src/UIMenuView.android.tsx: pass [] instead of undefined as the command arguments.
  • src/UIMenuView.ios.tsx: wrap the native component in forwardRef + useImperativeHandle and expose show(). iOS has no public API to present a UIMenu from code, so it does nothing and warns in __DEV__.
  • src/types.ts / README.md: document show() as Android-only and a no-op on iOS.
  • example/src/App.tsx: render the "Android only" button only on Android.

Behavior note

On iOS, ref now points to the { show } handle instead of the native host instance. That matches Android, which already exposes only { show }, and the public MenuComponentRef type, which only declares show. Code that relied on the untyped host instance on iOS (e.g. ref.current.measure) would no longer get it.

Verification

  • yarn typescript, yarn test, yarn prepare pass. Biome is clean on the new iOS file; the other files only have pre-existing import-sorting suggestions.
  • Not run on a device or simulator: neither the Android old-architecture fallback path nor the iOS warning was exercised. CI builds both native apps.

🤖 Generated with Claude Code

Naturalclar and others added 2 commits November 25, 2026 12:41
Android: show() fell back to UIManager.dispatchViewManagerCommand with
`undefined` as the command arguments. That reaches native code as null,
and on the New Architecture it throws `UnexpectedNativeTypeException:
expected Array, got a null`, leaving the trigger pressed. Pass `[]`.

iOS: MenuComponentRef declares show(), but iOS re-exported the native
component directly, so `ref.current?.show()` threw `show is not a
function`. iOS has no public API to present a UIMenu from code, so wrap
the component and expose show() as a no-op that warns in development.

Also show the example's "Android only" button only on Android, and say
in the README and the type's doc comment that show() is Android-only.

Fixes #1228
Fixes #957

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Naturalclar
Naturalclar merged commit 2dc80ee into master Nov 25, 2026
6 checks passed
@Naturalclar
Naturalclar deleted the fix/show-android-args-ios-noop branch November 25, 2026 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant