menu/ios/MenuViewManager.mm
Mohammed Alkailany d7dcacd53e
feat: Add onOpenMenu and onCloseMenu event handlers (#998)
* revert: back to original

* feat: close menu support

* feat: close menu support

* feat: close menu support

* feat: close menu support

* feat: close menu support

* chore: removed package lock file

* feat(events): add menu close detection

Add onMenuClose event that fires when menu is dismissed.
- Implement for both iOS and Android platforms
- Add event at start of dismissal for better responsiveness
- Support both old and new React Native architectures
- Add tests and update documentation

The event fires when:
- User taps outside the menu
- User selects a menu item

* feat(events): add onOpenMenu event and rename onMenuClose

* refactor(menu): simplify menu event handlers by removing native event parameters

* fix(types): update onCloseMenu and onOpenMenu event handlers to use undefined event parameter

* fix(types): update onCloseMenu and onOpenMenu event handlers to accept string event parameters

* refactor(menu): rename onMenuOpen to onOpenMenu across iOS implementations

* feat(menu): implement onOpenMenu event and update event handling in iOS and Android

* refactor(menu): streamline event handling for onCloseMenu and onOpenMenu

---------

Co-authored-by: mohammed <malkailany@hotmail.com>
2024-12-27 16:02:09 +09:00

83 lines
2.0 KiB
Plaintext

#import <React/RCTViewManager.h>
#import <React/RCTUIManager.h>
#import "RCTBridge.h"
#ifdef RCT_NEW_ARCH_ENABLED
// NEW ARCH
#import "MenuView.h"
#else
// OLD ARCH
#if __has_include(<react_native_menu/react_native_menu-Swift.h>)
#import <react_native_menu/react_native_menu-Swift.h>
#else
#import <react_native_menu-Swift.h>
#endif
#endif
@interface MenuViewManager : RCTViewManager
@end
@implementation MenuViewManager
RCT_EXPORT_MODULE(MenuView)
- (UIView *)view
{
#ifdef RCT_NEW_ARCH_ENABLED
// NEW ARCH
return [[MenuView alloc] init];
#else
// OLD ARCH
if (@available(iOS 14.0, *)) {
return [[LegacyMenuViewImplementation alloc] init];
} else {
return [[LegacyActionSheetView alloc] init];
}
#endif /* RCT_NEW_ARCH_ENABLED */
}
/**
* title: Short description to be displayed above the menu.
*/
RCT_EXPORT_VIEW_PROPERTY(title, NSString);
/**
* actions: Array of actions that are included in the menu
*/
RCT_EXPORT_VIEW_PROPERTY(actions, NSArray);
/**
* actionsHash: String hash that changes any time the actions change (so that we don't have to deeply compare values)
*/
#ifdef RCT_NEW_ARCH_ENABLED
// NEW ARCH
RCT_EXPORT_VIEW_PROPERTY(actionsHash, NSString);
#endif
/**
* onPressAction: callback to be called once user selects an action
*/
RCT_EXPORT_VIEW_PROPERTY(onPressAction, RCTDirectEventBlock);
/**
* onCloseMenu: callback to be called when the menu is closed
*/
RCT_EXPORT_VIEW_PROPERTY(onCloseMenu, RCTDirectEventBlock);
/**
* onOpenMenu: callback to be called when the menu is opened
*/
RCT_EXPORT_VIEW_PROPERTY(onOpenMenu, RCTDirectEventBlock);
/**
* shouldOpenOnLongPress: determines whether menu should be opened after long press or normal press
*/
RCT_EXPORT_VIEW_PROPERTY(shouldOpenOnLongPress, BOOL)
/**
* themeVariant: determines whether menu should use dark theme, light theme or system theme
*/
RCT_EXPORT_VIEW_PROPERTY(themeVariant, NSString)
/**
* hitSlop: The same as hitSlop in React Native
*/
RCT_EXPORT_VIEW_PROPERTY(hitSlop, UIEdgeInsets)
@end