Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(android): add show method to MenuView component #954

Conversation

batuhanoztrk
Copy link
Contributor

Add Imperative Menu Control for Android

Changes

  • Added a new show() method to programmatically display menus on Android
  • Implemented ref forwarding to expose the show() method to React Native components
  • Added TypeScript types to support the new functionality
  • Updated example app to demonstrate the new feature

Implementation Details

  • Added native Android command handling in MenuViewManagerBase.kt
  • Created a new MenuComponentRef type for TypeScript support
  • Wrapped the native component with ref forwarding in UIMenuView.android.tsx
  • Added example usage with a button trigger in the example app

Example Usage

const menuRef = useRef<MenuComponentRef>(null);
// Show menu programmatically
menuRef.current?.show();
// In JSX
<MenuView
    ref={menuRef}
    title="Menu Title"
    actions={...}
/>

Testing

  • Verified menu display using the example app
  • Confirmed TypeScript types work correctly
  • Tested compatibility with existing menu functionality

Notes

  • This feature is currently Android-only
  • Existing menu behavior remains unchanged

Copy link
Member

@Naturalclar Naturalclar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏻

@Naturalclar Naturalclar merged commit 205c4bb into react-native-menu:master Oct 31, 2024
4 of 5 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants