forked from react-native-menu/menu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add onOpenMenu and onCloseMenu event handlers (react-native-men…
…u#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 <[email protected]>
- Loading branch information
1 parent
0a38464
commit d7dcacd
Showing
17 changed files
with
324 additions
and
74 deletions.
There are no files selected for viewing
This file contains 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
13 changes: 13 additions & 0 deletions
13
android/src/main/java/com/reactnativemenu/MenuOnCloseEvent.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.reactnativemenu | ||
|
||
import com.facebook.react.bridge.Arguments | ||
import com.facebook.react.bridge.WritableMap | ||
import com.facebook.react.uimanager.events.Event | ||
|
||
class MenuOnCloseEvent(surfaceId: Int, viewId: Int, private val targetId: Int) : Event<MenuOnCloseEvent>(surfaceId, viewId) { | ||
override fun getEventName() = "onCloseMenu" | ||
|
||
override fun getEventData(): WritableMap? { | ||
return Arguments.createMap() | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
android/src/main/java/com/reactnativemenu/MenuOnOpenEvent.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.reactnativemenu | ||
|
||
import com.facebook.react.bridge.Arguments | ||
import com.facebook.react.bridge.WritableMap | ||
import com.facebook.react.uimanager.events.Event | ||
|
||
class MenuOnOpenEvent(surfaceId: Int, viewId: Int, private val targetId: Int) : Event<MenuOnOpenEvent>(surfaceId, viewId) { | ||
override fun getEventName() = "onOpenMenu" | ||
|
||
override fun getEventData(): WritableMap? { | ||
return Arguments.createMap() | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
|
||
@objc(FabricActionSheetView) | ||
public class FabricActionSheetView: ActionSheetView, FabricViewImplementationProtocol { | ||
public var onPressAction: ((String) -> Void)? | ||
|
||
public var onCloseMenu: (() -> Void)? | ||
public var onOpenMenu: (() -> Void)? | ||
|
||
@objc override func sendButtonAction(_ action: String) { | ||
if let onPress = onPressAction { | ||
onPress(action) | ||
} | ||
} | ||
|
||
@objc override func sendMenuClose() { | ||
if let onCloseMenu = onCloseMenu { | ||
onCloseMenu() | ||
} | ||
} | ||
@objc override func sendMenuOpen() { | ||
if let onOpenMenu = onOpenMenu { | ||
onOpenMenu() | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
|
||
@objc(LegacyActionSheetView) | ||
public class LegacyActionSheetView: ActionSheetView { | ||
@objc var onPressAction: RCTDirectEventBlock? | ||
|
||
@objc var onCloseMenu: RCTDirectEventBlock? | ||
@objc var onOpenMenu: RCTDirectEventBlock? | ||
|
||
|
||
|
||
@objc override func sendButtonAction(_ action: String) { | ||
if let onPress = onPressAction { | ||
onPress(["event":action]) | ||
} | ||
} | ||
|
||
@objc override func sendMenuClose() { | ||
if let onCloseMenu = onCloseMenu { | ||
onCloseMenu([:]) | ||
} | ||
} | ||
|
||
@objc override func sendMenuOpen() { | ||
if let onOpenMenu = onOpenMenu { | ||
onOpenMenu([:]) | ||
} | ||
} | ||
} |
Oops, something went wrong.