@react-native-menu/menu 1.1.6 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +49 -1
  2. package/android/src/main/java/com/reactnativemenu/MenuOnCloseEvent.kt +13 -0
  3. package/android/src/main/java/com/reactnativemenu/MenuOnOpenEvent.kt +13 -0
  4. package/android/src/main/java/com/reactnativemenu/MenuView.kt +10 -0
  5. package/android/src/main/java/com/reactnativemenu/MenuViewManagerBase.kt +89 -23
  6. package/ios/MenuViewManager.mm +8 -0
  7. package/ios/NewArch/FabricActionSheetView.swift +14 -2
  8. package/ios/NewArch/FabricMenuViewImplementation.swift +15 -1
  9. package/ios/NewArch/FabricViewImplementationProtocol.swift +5 -0
  10. package/ios/NewArch/MenuView.mm +39 -0
  11. package/ios/OldArch/LegacyActionSheetView.swift +17 -2
  12. package/ios/OldArch/LegacyMenuViewImplementation.swift +14 -0
  13. package/ios/Shared/ActionSheetView.swift +15 -3
  14. package/ios/Shared/MenuViewImplementation.swift +35 -15
  15. package/lib/commonjs/NativeModuleSpecs/UIMenuNativeComponent.js +1 -1
  16. package/lib/commonjs/NativeModuleSpecs/UIMenuNativeComponent.js.map +1 -1
  17. package/lib/commonjs/UIMenuView.android.js +19 -1
  18. package/lib/commonjs/UIMenuView.android.js.map +1 -1
  19. package/lib/commonjs/UIMenuView.js +0 -3
  20. package/lib/commonjs/UIMenuView.js.map +1 -1
  21. package/lib/commonjs/index.js +6 -8
  22. package/lib/commonjs/index.js.map +1 -1
  23. package/lib/commonjs/utils.js +1 -1
  24. package/lib/commonjs/utils.js.map +1 -1
  25. package/lib/module/NativeModuleSpecs/UIMenuNativeComponent.js +2 -2
  26. package/lib/module/NativeModuleSpecs/UIMenuNativeComponent.js.map +1 -1
  27. package/lib/module/UIMenuView.android.js +20 -2
  28. package/lib/module/UIMenuView.android.js.map +1 -1
  29. package/lib/module/UIMenuView.ios.js +1 -1
  30. package/lib/module/UIMenuView.js +1 -2
  31. package/lib/module/UIMenuView.js.map +1 -1
  32. package/lib/module/index.js +9 -8
  33. package/lib/module/index.js.map +1 -1
  34. package/lib/module/utils.js +1 -1
  35. package/lib/module/utils.js.map +1 -1
  36. package/lib/typescript/src/NativeModuleSpecs/UIMenuNativeComponent.d.ts +16 -2
  37. package/lib/typescript/src/NativeModuleSpecs/UIMenuNativeComponent.d.ts.map +1 -1
  38. package/lib/typescript/src/UIMenuView.android.d.ts +2 -3
  39. package/lib/typescript/src/UIMenuView.android.d.ts.map +1 -1
  40. package/lib/typescript/src/UIMenuView.d.ts +2 -2
  41. package/lib/typescript/src/UIMenuView.d.ts.map +1 -1
  42. package/lib/typescript/src/UIMenuView.ios.d.ts +1 -1
  43. package/lib/typescript/src/index.d.ts +22 -4
  44. package/lib/typescript/src/index.d.ts.map +1 -1
  45. package/lib/typescript/src/types.d.ts +20 -6
  46. package/lib/typescript/src/types.d.ts.map +1 -1
  47. package/lib/typescript/src/utils.d.ts +1 -1
  48. package/lib/typescript/src/utils.d.ts.map +1 -1
  49. package/package.json +10 -44
  50. package/src/NativeModuleSpecs/UIMenuNativeComponent.ts +48 -37
  51. package/src/UIMenuView.android.tsx +34 -4
  52. package/src/UIMenuView.ios.tsx +1 -1
  53. package/src/UIMenuView.tsx +11 -11
  54. package/src/index.tsx +42 -36
  55. package/src/types.ts +168 -153
  56. package/src/utils.ts +17 -17
package/README.md CHANGED
@@ -40,14 +40,20 @@ npx pod-install
40
40
  ## Usage
41
41
 
42
42
  ```jsx
43
- import { MenuView } from '@react-native-menu/menu';
43
+ import { MenuView, MenuComponentRef } from '@react-native-menu/menu';
44
44
 
45
45
  // ...
46
46
 
47
47
  const App = () => {
48
+ const menuRef = useRef<MenuComponentRef>(null);
48
49
  return (
49
50
  <View style={styles.container}>
51
+ <Button
52
+ title="Show Menu with ref (Android only)"
53
+ onPress={() => menuRef.current?.show()}
54
+ />
50
55
  <MenuView
56
+ ref={menuRef}
51
57
  title="Menu Title"
52
58
  onPressAction={({ nativeEvent }) => {
53
59
  console.warn(JSON.stringify(nativeEvent));
@@ -131,6 +137,14 @@ It's also possible to obtain the `action` is a more React-ish, declarative fashi
131
137
 
132
138
  ### Props
133
139
 
140
+ #### `ref` (Android only)
141
+
142
+ Ref to the menu component.
143
+
144
+ | Type | Required |
145
+ |------|----------|
146
+ | ref | No |
147
+
134
148
  ### `title` (iOS only)
135
149
 
136
150
  The title of the menu.
@@ -277,6 +291,40 @@ It will contain id of the given action.
277
291
  |-------------------------|----------|
278
292
  | ({nativeEvent}) => void | No |
279
293
 
294
+ ### Events
295
+
296
+ #### `onCloseMenu`
297
+
298
+ Callback function that will be called when the menu is dismissed. This event fires at the start of the dismissal, before any animations complete.
299
+
300
+ | Type | Required |
301
+ |------------|----------|
302
+ | () => void | No |
303
+
304
+ #### `onOpenMenu`
305
+
306
+ Callback function that will be called when the menu is opened. This event fires right before the menu is displayed.
307
+
308
+ | Type | Required |
309
+ |------------|----------|
310
+ | () => void | No |
311
+
312
+ Example usage:
313
+ ```jsx
314
+ <MenuView
315
+ onOpenMenu={() => {
316
+ console.log('Menu was opened');
317
+ }}
318
+ onCloseMenu={() => {
319
+ console.log('Menu was closed');
320
+ }}
321
+ // ... other props
322
+ >
323
+ <View>
324
+ <Text>Open Menu</Text>
325
+ </View>
326
+ </MenuView>
327
+ ```
280
328
  ## Testing with Jest
281
329
 
282
330
  In some cases, you might want to mock the package to test your components. You can do this by using the `jest.mock` function.
@@ -0,0 +1,13 @@
1
+ package com.reactnativemenu
2
+
3
+ import com.facebook.react.bridge.Arguments
4
+ import com.facebook.react.bridge.WritableMap
5
+ import com.facebook.react.uimanager.events.Event
6
+
7
+ class MenuOnCloseEvent(surfaceId: Int, viewId: Int, private val targetId: Int) : Event<MenuOnCloseEvent>(surfaceId, viewId) {
8
+ override fun getEventName() = "onCloseMenu"
9
+
10
+ override fun getEventData(): WritableMap? {
11
+ return Arguments.createMap()
12
+ }
13
+ }
@@ -0,0 +1,13 @@
1
+ package com.reactnativemenu
2
+
3
+ import com.facebook.react.bridge.Arguments
4
+ import com.facebook.react.bridge.WritableMap
5
+ import com.facebook.react.uimanager.events.Event
6
+
7
+ class MenuOnOpenEvent(surfaceId: Int, viewId: Int, private val targetId: Int) : Event<MenuOnOpenEvent>(surfaceId, viewId) {
8
+ override fun getEventName() = "onOpenMenu"
9
+
10
+ override fun getEventData(): WritableMap? {
11
+ return Arguments.createMap()
12
+ }
13
+ }
@@ -43,6 +43,10 @@ class MenuView(private val mContext: ReactContext) : ReactViewGroup(mContext) {
43
43
  })
44
44
  }
45
45
 
46
+ fun show(){
47
+ prepareMenu()
48
+ }
49
+
46
50
  override fun setHitSlopRect(rect: Rect?) {
47
51
  super.setHitSlopRect(rect)
48
52
  mHitSlopRect = rect
@@ -257,8 +261,14 @@ class MenuView(private val mContext: ReactContext) : ReactViewGroup(mContext) {
257
261
  }
258
262
  mPopupMenu.setOnDismissListener {
259
263
  mIsMenuDisplayed = false
264
+ val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(mContext, id)
265
+ val surfaceId: Int = UIManagerHelper.getSurfaceId(this)
266
+ dispatcher?.dispatchEvent(MenuOnCloseEvent(surfaceId, id, id))
260
267
  }
261
268
  mIsMenuDisplayed = true
269
+ val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(mContext, id)
270
+ val surfaceId: Int = UIManagerHelper.getSurfaceId(this)
271
+ dispatcher?.dispatchEvent(MenuOnOpenEvent(surfaceId, id, id))
262
272
  mPopupMenu.show()
263
273
  }
264
274
  }
@@ -17,7 +17,7 @@ import com.facebook.react.views.view.ReactDrawableHelper
17
17
  import com.facebook.react.views.view.ReactViewGroup
18
18
  import com.facebook.yoga.YogaConstants
19
19
 
20
- abstract class MenuViewManagerBase: ReactClippingViewManager<MenuView>() {
20
+ abstract class MenuViewManagerBase : ReactClippingViewManager<MenuView>() {
21
21
  override fun getName() = "MenuView"
22
22
 
23
23
  @ReactProp(name = "actions")
@@ -37,8 +37,12 @@ abstract class MenuViewManagerBase: ReactClippingViewManager<MenuView>() {
37
37
 
38
38
  override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
39
39
  return MapBuilder.of(
40
- "onPressAction",
41
- MapBuilder.of("registrationName", "onPressAction")
40
+ "onPressAction",
41
+ MapBuilder.of("registrationName", "onPressAction"),
42
+ "onCloseMenu",
43
+ MapBuilder.of("registrationName", "onCloseMenu"),
44
+ "onOpenMenu",
45
+ MapBuilder.of("registrationName", "onOpenMenu")
42
46
  )
43
47
  }
44
48
 
@@ -82,7 +86,19 @@ abstract class MenuViewManagerBase: ReactClippingViewManager<MenuView>() {
82
86
  view.nextFocusUpId = viewId
83
87
  }
84
88
 
85
- @ReactPropGroup(names = [ViewProps.BORDER_RADIUS, ViewProps.BORDER_TOP_LEFT_RADIUS, ViewProps.BORDER_TOP_RIGHT_RADIUS, ViewProps.BORDER_BOTTOM_RIGHT_RADIUS, ViewProps.BORDER_BOTTOM_LEFT_RADIUS, ViewProps.BORDER_TOP_START_RADIUS, ViewProps.BORDER_TOP_END_RADIUS, ViewProps.BORDER_BOTTOM_START_RADIUS, ViewProps.BORDER_BOTTOM_END_RADIUS])
89
+ @ReactPropGroup(
90
+ names =
91
+ [
92
+ ViewProps.BORDER_RADIUS,
93
+ ViewProps.BORDER_TOP_LEFT_RADIUS,
94
+ ViewProps.BORDER_TOP_RIGHT_RADIUS,
95
+ ViewProps.BORDER_BOTTOM_RIGHT_RADIUS,
96
+ ViewProps.BORDER_BOTTOM_LEFT_RADIUS,
97
+ ViewProps.BORDER_TOP_START_RADIUS,
98
+ ViewProps.BORDER_TOP_END_RADIUS,
99
+ ViewProps.BORDER_BOTTOM_START_RADIUS,
100
+ ViewProps.BORDER_BOTTOM_END_RADIUS]
101
+ )
86
102
  fun setBorderRadius(view: ReactViewGroup, index: Int, borderRadius: Float) {
87
103
  var borderRadius = borderRadius
88
104
  if (!YogaConstants.isUndefined(borderRadius) && borderRadius < 0) {
@@ -109,33 +125,60 @@ abstract class MenuViewManagerBase: ReactClippingViewManager<MenuView>() {
109
125
  // We should keep using setters as `Val cannot be reassigned`
110
126
  view.setHitSlopRect(null)
111
127
  } else {
112
- view.setHitSlopRect(Rect(
113
- if (hitSlop.hasKey("left")) PixelUtil.toPixelFromDIP(hitSlop.getDouble("left")).toInt() else 0,
114
- if (hitSlop.hasKey("top")) PixelUtil.toPixelFromDIP(hitSlop.getDouble("top")).toInt() else 0,
115
- if (hitSlop.hasKey("right")) PixelUtil.toPixelFromDIP(hitSlop.getDouble("right")).toInt() else 0,
116
- if (hitSlop.hasKey("bottom")) PixelUtil.toPixelFromDIP(hitSlop.getDouble("bottom")).toInt() else 0))
128
+ view.setHitSlopRect(
129
+ Rect(
130
+ if (hitSlop.hasKey("left"))
131
+ PixelUtil.toPixelFromDIP(hitSlop.getDouble("left")).toInt()
132
+ else 0,
133
+ if (hitSlop.hasKey("top"))
134
+ PixelUtil.toPixelFromDIP(hitSlop.getDouble("top")).toInt()
135
+ else 0,
136
+ if (hitSlop.hasKey("right"))
137
+ PixelUtil.toPixelFromDIP(hitSlop.getDouble("right")).toInt()
138
+ else 0,
139
+ if (hitSlop.hasKey("bottom"))
140
+ PixelUtil.toPixelFromDIP(hitSlop.getDouble("bottom")).toInt()
141
+ else 0
142
+ )
143
+ )
117
144
  }
118
145
  }
119
146
 
120
147
  @ReactProp(name = "nativeBackgroundAndroid")
121
148
  fun setNativeBackground(view: ReactViewGroup, @Nullable bg: ReadableMap?) {
122
149
  view.setTranslucentBackgroundDrawable(
123
- if (bg == null) null else ReactDrawableHelper.createDrawableFromJSDescription(view.context, bg))
150
+ if (bg == null) null
151
+ else ReactDrawableHelper.createDrawableFromJSDescription(view.context, bg)
152
+ )
124
153
  }
125
154
 
126
155
  @TargetApi(Build.VERSION_CODES.M)
127
156
  @ReactProp(name = "nativeForegroundAndroid")
128
157
  fun setNativeForeground(view: ReactViewGroup, @Nullable fg: ReadableMap?) {
129
- view.foreground = if (fg == null) null else ReactDrawableHelper.createDrawableFromJSDescription(view.context, fg)
158
+ view.foreground =
159
+ if (fg == null) null
160
+ else ReactDrawableHelper.createDrawableFromJSDescription(view.context, fg)
130
161
  }
131
162
 
132
163
  @ReactProp(name = ViewProps.NEEDS_OFFSCREEN_ALPHA_COMPOSITING)
133
164
  fun setNeedsOffscreenAlphaCompositing(
134
- view: ReactViewGroup, needsOffscreenAlphaCompositing: Boolean) {
165
+ view: ReactViewGroup,
166
+ needsOffscreenAlphaCompositing: Boolean
167
+ ) {
135
168
  view.setNeedsOffscreenAlphaCompositing(needsOffscreenAlphaCompositing)
136
169
  }
137
170
 
138
- @ReactPropGroup(names = [ViewProps.BORDER_WIDTH, ViewProps.BORDER_LEFT_WIDTH, ViewProps.BORDER_RIGHT_WIDTH, ViewProps.BORDER_TOP_WIDTH, ViewProps.BORDER_BOTTOM_WIDTH, ViewProps.BORDER_START_WIDTH, ViewProps.BORDER_END_WIDTH])
171
+ @ReactPropGroup(
172
+ names =
173
+ [
174
+ ViewProps.BORDER_WIDTH,
175
+ ViewProps.BORDER_LEFT_WIDTH,
176
+ ViewProps.BORDER_RIGHT_WIDTH,
177
+ ViewProps.BORDER_TOP_WIDTH,
178
+ ViewProps.BORDER_BOTTOM_WIDTH,
179
+ ViewProps.BORDER_START_WIDTH,
180
+ ViewProps.BORDER_END_WIDTH]
181
+ )
139
182
  fun setBorderWidth(view: ReactViewGroup, index: Int, width: Float) {
140
183
  var width = width
141
184
  if (!YogaConstants.isUndefined(width) && width < 0) {
@@ -147,7 +190,18 @@ abstract class MenuViewManagerBase: ReactClippingViewManager<MenuView>() {
147
190
  view.setBorderWidth(SPACING_TYPES[index], width)
148
191
  }
149
192
 
150
- @ReactPropGroup(names = [ViewProps.BORDER_COLOR, ViewProps.BORDER_LEFT_COLOR, ViewProps.BORDER_RIGHT_COLOR, ViewProps.BORDER_TOP_COLOR, ViewProps.BORDER_BOTTOM_COLOR, ViewProps.BORDER_START_COLOR, ViewProps.BORDER_END_COLOR], customType = "Color")
193
+ @ReactPropGroup(
194
+ names =
195
+ [
196
+ ViewProps.BORDER_COLOR,
197
+ ViewProps.BORDER_LEFT_COLOR,
198
+ ViewProps.BORDER_RIGHT_COLOR,
199
+ ViewProps.BORDER_TOP_COLOR,
200
+ ViewProps.BORDER_BOTTOM_COLOR,
201
+ ViewProps.BORDER_START_COLOR,
202
+ ViewProps.BORDER_END_COLOR],
203
+ customType = "Color"
204
+ )
151
205
  abstract fun setBorderColor(view: ReactViewGroup, index: Int, color: Int?)
152
206
 
153
207
  @ReactProp(name = ViewProps.OVERFLOW)
@@ -169,15 +223,27 @@ abstract class MenuViewManagerBase: ReactClippingViewManager<MenuView>() {
169
223
  view.setBackfaceVisibilityDependantOpacity()
170
224
  }
171
225
 
226
+ override fun getCommandsMap(): MutableMap<String, Int>? {
227
+ return MapBuilder.of("show", COMMAND_SHOW)
228
+ }
229
+
230
+ override fun receiveCommand(root: MenuView, commandId: Int, args: ReadableArray?) {
231
+ when (commandId) {
232
+ COMMAND_SHOW -> root.show()
233
+ }
234
+ }
235
+
172
236
  companion object {
173
- val SPACING_TYPES = arrayOf(
174
- Spacing.ALL,
175
- Spacing.LEFT,
176
- Spacing.RIGHT,
177
- Spacing.TOP,
178
- Spacing.BOTTOM,
179
- Spacing.START,
180
- Spacing.END
181
- )
237
+ val COMMAND_SHOW = 1
238
+ val SPACING_TYPES =
239
+ arrayOf(
240
+ Spacing.ALL,
241
+ Spacing.LEFT,
242
+ Spacing.RIGHT,
243
+ Spacing.TOP,
244
+ Spacing.BOTTOM,
245
+ Spacing.START,
246
+ Spacing.END
247
+ )
182
248
  }
183
249
  }
@@ -57,6 +57,14 @@ RCT_EXPORT_VIEW_PROPERTY(actionsHash, NSString);
57
57
  * onPressAction: callback to be called once user selects an action
58
58
  */
59
59
  RCT_EXPORT_VIEW_PROPERTY(onPressAction, RCTDirectEventBlock);
60
+ /**
61
+ * onCloseMenu: callback to be called when the menu is closed
62
+ */
63
+ RCT_EXPORT_VIEW_PROPERTY(onCloseMenu, RCTDirectEventBlock);
64
+ /**
65
+ * onOpenMenu: callback to be called when the menu is opened
66
+ */
67
+ RCT_EXPORT_VIEW_PROPERTY(onOpenMenu, RCTDirectEventBlock);
60
68
  /**
61
69
  * shouldOpenOnLongPress: determines whether menu should be opened after long press or normal press
62
70
  */
@@ -1,11 +1,23 @@
1
-
2
1
  @objc(FabricActionSheetView)
3
2
  public class FabricActionSheetView: ActionSheetView, FabricViewImplementationProtocol {
4
3
  public var onPressAction: ((String) -> Void)?
5
-
4
+ public var onCloseMenu: (() -> Void)?
5
+ public var onOpenMenu: (() -> Void)?
6
+
6
7
  @objc override func sendButtonAction(_ action: String) {
7
8
  if let onPress = onPressAction {
8
9
  onPress(action)
9
10
  }
10
11
  }
12
+
13
+ @objc override func sendMenuClose() {
14
+ if let onCloseMenu = onCloseMenu {
15
+ onCloseMenu()
16
+ }
17
+ }
18
+ @objc override func sendMenuOpen() {
19
+ if let onOpenMenu = onOpenMenu {
20
+ onOpenMenu()
21
+ }
22
+ }
11
23
  }
@@ -10,11 +10,25 @@ import UIKit
10
10
  @objc(FabricMenuViewImplementation)
11
11
  public class FabricMenuViewImplementation: MenuViewImplementation, FabricViewImplementationProtocol {
12
12
  public var onPressAction: ((String) -> Void)?
13
-
13
+ public var onCloseMenu: (() -> Void)?
14
+ public var onOpenMenu: (() -> Void)?
15
+
14
16
  @objc override func sendButtonAction(_ action: UIAction) {
15
17
  if let onPress = onPressAction {
16
18
  onPress(action.identifier.rawValue)
17
19
  }
18
20
  }
19
21
 
22
+ @objc override func sendMenuClose() {
23
+ if let onCloseMenu = onCloseMenu {
24
+ onCloseMenu()
25
+ }
26
+ }
27
+
28
+ @objc override func sendMenuOpen() {
29
+ if let onOpenMenu = onOpenMenu {
30
+ onOpenMenu()
31
+ }
32
+ }
33
+
20
34
  }
@@ -2,5 +2,10 @@ import Foundation
2
2
  @objc public protocol FabricViewImplementationProtocol {
3
3
  var actions: [NSDictionary]? { get set }
4
4
  var title: NSString? { get set }
5
+ var themeVariant: NSString? { get set }
6
+ var shouldOpenOnLongPress: Bool { get set }
7
+ @objc optional var hitSlop: UIEdgeInsets { get set }
5
8
  var onPressAction: ((String) -> Void)? { get set }
9
+ var onCloseMenu: (() -> Void)? { get set }
10
+ var onOpenMenu: (() -> Void)? { get set }
6
11
  }
@@ -41,6 +41,9 @@ using namespace facebook::react;
41
41
  _view.onPressAction = ^(NSString *eventString) {
42
42
  [self onPressAction:eventString];
43
43
  };
44
+ _view.onCloseMenu = ^{
45
+ [self onCloseMenu];
46
+ };
44
47
  self.contentView = _view;
45
48
  }
46
49
 
@@ -68,6 +71,22 @@ using namespace facebook::react;
68
71
  }
69
72
  }
70
73
 
74
+ - (void)onCloseMenu {
75
+ // If screen is already unmounted then there will be no event emitter
76
+ const auto eventEmitter = [self getEventEmitter];
77
+ if (eventEmitter != nullptr) {
78
+ eventEmitter->onCloseMenu({});
79
+ }
80
+ }
81
+
82
+ - (void)onOpenMenu {
83
+ // If screen is already unmounted then there will be no event emitter
84
+ const auto eventEmitter = [self getEventEmitter];
85
+ if (eventEmitter != nullptr) {
86
+ eventEmitter->onOpenMenu({});
87
+ }
88
+ }
89
+
71
90
  /**
72
91
  Responsible for iterating through the C++ vector<struct> and convert each struct element to NSDictionary, then return it all in an NSArray
73
92
  */
@@ -137,6 +156,26 @@ using namespace facebook::react;
137
156
  _view.title = [NSString stringWithUTF8String:newViewProps.title.c_str()];
138
157
  }
139
158
 
159
+ if (oldViewProps.themeVariant != newViewProps.themeVariant) {
160
+ _view.themeVariant = [NSString stringWithUTF8String:newViewProps.themeVariant.c_str()];
161
+ }
162
+
163
+ if (oldViewProps.shouldOpenOnLongPress != newViewProps.shouldOpenOnLongPress) {
164
+ _view.shouldOpenOnLongPress = newViewProps.shouldOpenOnLongPress;
165
+ }
166
+
167
+ if (oldViewProps.hitSlop.top != newViewProps.hitSlop.top ||
168
+ oldViewProps.hitSlop.bottom != newViewProps.hitSlop.bottom ||
169
+ oldViewProps.hitSlop.left != newViewProps.hitSlop.left ||
170
+ oldViewProps.hitSlop.right != newViewProps.hitSlop.right) {
171
+ _view.hitSlop = UIEdgeInsetsMake(
172
+ newViewProps.hitSlop.top,
173
+ newViewProps.hitSlop.left,
174
+ newViewProps.hitSlop.bottom,
175
+ newViewProps.hitSlop.right
176
+ );
177
+ }
178
+
140
179
  [super updateProps:props oldProps:oldProps];
141
180
  }
142
181
 
@@ -1,11 +1,26 @@
1
-
2
1
  @objc(LegacyActionSheetView)
3
2
  public class LegacyActionSheetView: ActionSheetView {
4
3
  @objc var onPressAction: RCTDirectEventBlock?
5
-
4
+ @objc var onCloseMenu: RCTDirectEventBlock?
5
+ @objc var onOpenMenu: RCTDirectEventBlock?
6
+
7
+
8
+
6
9
  @objc override func sendButtonAction(_ action: String) {
7
10
  if let onPress = onPressAction {
8
11
  onPress(["event":action])
9
12
  }
10
13
  }
14
+
15
+ @objc override func sendMenuClose() {
16
+ if let onCloseMenu = onCloseMenu {
17
+ onCloseMenu([:])
18
+ }
19
+ }
20
+
21
+ @objc override func sendMenuOpen() {
22
+ if let onOpenMenu = onOpenMenu {
23
+ onOpenMenu([:])
24
+ }
25
+ }
11
26
  }
@@ -3,6 +3,8 @@ import UIKit
3
3
  @objc(LegacyMenuViewImplementation)
4
4
  public class LegacyMenuViewImplementation: MenuViewImplementation {
5
5
  @objc var onPressAction: RCTDirectEventBlock?
6
+ @objc var onCloseMenu: RCTDirectEventBlock?
7
+ @objc var onOpenMenu: RCTDirectEventBlock?
6
8
 
7
9
  @objc override func sendButtonAction(_ action: UIAction) {
8
10
  if let onPress = onPressAction {
@@ -10,4 +12,16 @@ public class LegacyMenuViewImplementation: MenuViewImplementation {
10
12
  }
11
13
  }
12
14
 
15
+ @objc override func sendMenuClose() {
16
+ if let onCloseMenu = onCloseMenu {
17
+ onCloseMenu([:])
18
+ }
19
+ }
20
+
21
+ @objc override func sendMenuOpen() {
22
+ if let onOpenMenu = onOpenMenu {
23
+ onOpenMenu([:])
24
+ }
25
+ }
26
+
13
27
  }
@@ -26,6 +26,7 @@ public class ActionSheetView: UIView {
26
26
  actions.forEach({ alertAction in
27
27
  if let action = RCTAlertAction(details: alertAction).createAction({
28
28
  event in self.sendButtonAction(event)
29
+ self.sendMenuClose()
29
30
  }) {
30
31
  _actions.append(action)
31
32
  }
@@ -33,10 +34,10 @@ public class ActionSheetView: UIView {
33
34
  }
34
35
  }
35
36
 
36
- @objc var shouldOpenOnLongPress: Bool = false
37
+ @objc public var shouldOpenOnLongPress: Bool = false
37
38
 
38
39
  private var _themeVariant: String?
39
- @objc var themeVariant: NSString? {
40
+ @objc public var themeVariant: NSString? {
40
41
  didSet { self._themeVariant = themeVariant as? String }
41
42
  }
42
43
 
@@ -49,6 +50,7 @@ public class ActionSheetView: UIView {
49
50
  }
50
51
 
51
52
  func launchActionSheet() {
53
+ self.sendMenuOpen()
52
54
 
53
55
  let alert = UIAlertController(title: _title, message: nil, preferredStyle: .actionSheet)
54
56
 
@@ -68,7 +70,9 @@ public class ActionSheetView: UIView {
68
70
  alert.addAction(action.copy() as! UIAlertAction)
69
71
  })
70
72
 
71
- alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
73
+ alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { _ in
74
+ self.sendMenuClose()
75
+ }))
72
76
 
73
77
  if UIDevice.current.userInterfaceIdiom == .pad {
74
78
  alert.modalPresentationStyle = .popover
@@ -109,6 +113,14 @@ public class ActionSheetView: UIView {
109
113
  // NO-OP (should be overriden by parent)
110
114
  }
111
115
 
116
+ @objc func sendMenuClose() {
117
+ // NO-OP (should be overriden by parent)
118
+ }
119
+
120
+ @objc func sendMenuOpen() {
121
+ // NO-OP (should be overriden by parent)
122
+ }
123
+
112
124
  required init?(coder: NSCoder) {
113
125
  fatalError("init(coder:) has not been implemented")
114
126
  }
@@ -36,30 +36,45 @@ public class MenuViewImplementation: UIButton {
36
36
  }
37
37
  }
38
38
 
39
- @objc var shouldOpenOnLongPress: Bool = false {
39
+ @objc public var shouldOpenOnLongPress: Bool = false {
40
40
  didSet {
41
41
  self.setup()
42
42
  }
43
43
  }
44
44
 
45
45
  private var _themeVariant: String?
46
- @objc var themeVariant: NSString? {
46
+ @objc public var themeVariant: NSString? {
47
47
  didSet {
48
48
  self._themeVariant = themeVariant as? String
49
49
  self.setup()
50
50
  }
51
51
  }
52
52
 
53
- @objc var hitSlop: UIEdgeInsets = .zero
53
+ @objc public var hitSlop: UIEdgeInsets = .zero
54
54
 
55
55
  override init(frame: CGRect) {
56
- super.init(frame: frame)
57
- self.setup()
56
+ super.init(frame: frame)
57
+ let interaction = UIContextMenuInteraction(delegate: self)
58
+ self.addInteraction(interaction)
59
+ self.setup()
60
+ }
61
+
62
+ public override func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
63
+ sendMenuOpen()
64
+ return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { [weak self] _ in
65
+ guard let self = self else { return nil }
66
+ return self.menu
67
+ }
68
+ }
69
+
70
+ public override func contextMenuInteraction(_ interaction: UIContextMenuInteraction, willEndFor configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionAnimating?) {
71
+ sendMenuClose()
58
72
  }
59
-
60
73
 
61
74
  func setup () {
62
- let menu = UIMenu(title:_title, identifier: nil, children: self._actions)
75
+ let menu = UIMenu(title: _title,
76
+ identifier: nil,
77
+ children: self._actions)
63
78
 
64
79
  if self._themeVariant != nil {
65
80
  if self._themeVariant == "dark" {
@@ -76,15 +91,14 @@ public class MenuViewImplementation: UIButton {
76
91
  }
77
92
 
78
93
  public override func reactSetFrame(_ frame: CGRect) {
79
- super.reactSetFrame(frame);
80
- };
94
+ super.reactSetFrame(frame);
95
+ }
81
96
 
82
97
  public override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
83
98
  if hitSlop == .zero || !self.isEnabled || self.isHidden {
84
99
  return super.point(inside: point, with: event)
85
100
  }
86
101
 
87
- // Create a larger hit frame that extends beyond the view's bounds
88
102
  let largerFrame = CGRect(
89
103
  x: self.bounds.origin.x - hitSlop.left,
90
104
  y: self.bounds.origin.y - hitSlop.top,
@@ -92,16 +106,22 @@ public class MenuViewImplementation: UIButton {
92
106
  height: self.bounds.size.height + hitSlop.top + hitSlop.bottom
93
107
  )
94
108
 
95
- // Check if the point is within the larger frame
96
109
  return largerFrame.contains(point)
97
110
  }
98
111
 
99
-
100
- required init?(coder aDecoder: NSCoder) {
101
- fatalError("init(coder:) has not been implemented")
102
- }
112
+ required init?(coder aDecoder: NSCoder) {
113
+ fatalError("init(coder:) has not been implemented")
114
+ }
103
115
 
104
116
  @objc func sendButtonAction(_ action: UIAction) {
105
117
  // NO-OP (should be overriden by parent)
106
118
  }
119
+
120
+ @objc func sendMenuClose() {
121
+ // NO-OP (should be overriden by parent)
122
+ }
123
+
124
+ @objc func sendMenuOpen() {
125
+ // NO-OP (should be overriden by parent)
126
+ }
107
127
  }
@@ -14,5 +14,5 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
14
14
  OR with extending types in an interface, so for now we'll just keep some duplicate
15
15
  types here, to avoid issues while `pod install` takes place.
16
16
  */
17
- var _default = exports.default = (0, _codegenNativeComponent.default)('MenuView');
17
+ var _default = exports.default = (0, _codegenNativeComponent.default)("MenuView");
18
18
  //# sourceMappingURL=UIMenuNativeComponent.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_codegenNativeComponent","_interopRequireDefault","require","e","__esModule","default","_default","exports","codegenNativeComponent"],"sourceRoot":"../../../src","sources":["NativeModuleSpecs/UIMenuNativeComponent.ts"],"mappings":";;;;;;AAKA,IAAAA,uBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA6F,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAC7F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAPA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GA8Ce,IAAAG,+BAAsB,EACnC,UACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_codegenNativeComponent","_interopRequireDefault","require","e","__esModule","default","_default","exports","codegenNativeComponent"],"sourceRoot":"../../../src","sources":["NativeModuleSpecs/UIMenuNativeComponent.ts"],"mappings":";;;;;;AAKA,IAAAA,uBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA6F,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAC7F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAPA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GAyDe,IAAAG,+BAAsB,EACpC,UACD,CAAC","ignoreList":[]}