Skip to content

Conversation

@batuhanoztrk
Copy link
Contributor

@batuhanoztrk batuhanoztrk commented Sep 3, 2025

Overview

This PR implements Fabric commands support for the Android MenuView component, enabling proper command handling in React Native's New Architecture while maintaining full backward compatibility with the legacy Paper architecture.

Changes Made

Android Native Layer (MenuViewManagerBase.kt)

  • Added Fabric command support: Implemented receiveCommand(root: MenuView, commandId: String, args: ReadableArray?) method to handle string-based commands used by Fabric
  • Updated command constants: Changed COMMAND_SHOW from val to const val and added NEW_ARCH_COMMAND_SHOW constant for Fabric compatibility
  • Maintained backward compatibility: Existing integer-based command handling remains intact for Paper architecture

React Native Layer (UIMenuView.android.tsx)

  • Added Fabric detection: Implemented runtime detection of Fabric architecture using global.nativeFabricUIManager
  • Integrated codegenNativeCommands: Added proper Fabric command generation using React Native's codegen utilities
  • Dual command dispatch:
    • Fabric architecture: Uses codegenNativeCommands for type-safe command dispatch
    • Paper architecture: Falls back to legacy UIManager.dispatchViewManagerCommand

Technical Details

Architecture Detection

The component now detects the current React Native architecture at runtime:

const isFabric = !!(global as any).nativeFabricUIManager;

Command Handling

  • Fabric: Uses string-based commands ("show") with codegen-generated command interfaces
  • Paper: Uses integer-based commands (1) with traditional UIManager dispatch

Testing

  • ✅ Maintains full backward compatibility with existing Paper-based apps
  • ✅ Enables MenuView functionality in Fabric-enabled applications
  • ✅ Runtime architecture detection ensures correct command dispatch method

Breaking Changes

None. This change is fully backward compatible.

Related Issues

Fixes #1001 - Error: Exception in HostFunction: com.facebook.react.bridge.UnexpectedNativeTypeException when calling menuRef.current?.show() in React Native 0.76.3

@vonovak
Copy link
Collaborator

vonovak commented Sep 9, 2025

Hello,
thanks for the PR. Can you provide a code snippet that reproduces the issue that this is fixing?

@batuhanoztrk
Copy link
Contributor Author

Hi @vonovak,
As requested, I’ve added a minimal reproducible example. Steps:

  1. Run the example app with the New Architecture disabled
  2. Launch the example.
  3. Press the button “Show Menu with ref (Android only)”.

With these steps the exact error fixed by this PR is reproduced (you’ll see it on screen / in the console).

@vonovak vonovak merged commit e810321 into react-native-menu:master Sep 12, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: Exception in HostFunction: com.facebook.react.bridge.UnexpectedNativeTypeException: expected Array, got a null

2 participants