Repository navigation
fix: stop MenuView.show() from throwing on Android and iOS - #1265
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1228, fixes #957.
Problem
Android (#1228).
show()falls back toUIManager.dispatchViewManagerCommand(node, command, undefined)whenglobal.nativeFabricUIManagerisn't set.undefinedreaches native code as null, and on the New Architecture that throws: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).
MenuComponentRefdeclaresshow(): void, butsrc/UIMenuView.ios.tsxre-exported the native component directly, so the ref had noshow. Shared code callingref.current?.show()throwsshow 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 ofundefinedas the command arguments.src/UIMenuView.ios.tsx: wrap the native component inforwardRef+useImperativeHandleand exposeshow(). iOS has no public API to present aUIMenufrom code, so it does nothing and warns in__DEV__.src/types.ts/README.md: documentshow()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,
refnow points to the{ show }handle instead of the native host instance. That matches Android, which already exposes only{ show }, and the publicMenuComponentReftype, which only declaresshow. 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 preparepass. Biome is clean on the new iOS file; the other files only have pre-existing import-sorting suggestions.🤖 Generated with Claude Code