@react-native-menu/menu 1.1.7 → 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.
- package/README.md +34 -0
- package/android/src/main/java/com/reactnativemenu/MenuOnCloseEvent.kt +13 -0
- package/android/src/main/java/com/reactnativemenu/MenuOnOpenEvent.kt +13 -0
- package/android/src/main/java/com/reactnativemenu/MenuView.kt +6 -0
- package/android/src/main/java/com/reactnativemenu/MenuViewManagerBase.kt +78 -23
- package/ios/MenuViewManager.mm +8 -0
- package/ios/NewArch/FabricActionSheetView.swift +14 -2
- package/ios/NewArch/FabricMenuViewImplementation.swift +15 -1
- package/ios/NewArch/FabricViewImplementationProtocol.swift +2 -0
- package/ios/NewArch/MenuView.mm +19 -0
- package/ios/OldArch/LegacyActionSheetView.swift +17 -2
- package/ios/OldArch/LegacyMenuViewImplementation.swift +14 -0
- package/ios/Shared/ActionSheetView.swift +13 -1
- package/ios/Shared/MenuViewImplementation.swift +32 -12
- package/lib/commonjs/NativeModuleSpecs/UIMenuNativeComponent.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/NativeModuleSpecs/UIMenuNativeComponent.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeModuleSpecs/UIMenuNativeComponent.d.ts +6 -0
- package/lib/typescript/src/NativeModuleSpecs/UIMenuNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +2 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +10 -0
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/NativeModuleSpecs/UIMenuNativeComponent.ts +4 -1
- package/src/index.tsx +32 -32
- package/src/types.ts +10 -0
package/README.md
CHANGED
|
@@ -291,6 +291,40 @@ It will contain id of the given action.
|
|
|
291
291
|
|-------------------------|----------|
|
|
292
292
|
| ({nativeEvent}) => void | No |
|
|
293
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
|
+
```
|
|
294
328
|
## Testing with Jest
|
|
295
329
|
|
|
296
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
|
+
}
|
|
@@ -261,8 +261,14 @@ class MenuView(private val mContext: ReactContext) : ReactViewGroup(mContext) {
|
|
|
261
261
|
}
|
|
262
262
|
mPopupMenu.setOnDismissListener {
|
|
263
263
|
mIsMenuDisplayed = false
|
|
264
|
+
val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(mContext, id)
|
|
265
|
+
val surfaceId: Int = UIManagerHelper.getSurfaceId(this)
|
|
266
|
+
dispatcher?.dispatchEvent(MenuOnCloseEvent(surfaceId, id, id))
|
|
264
267
|
}
|
|
265
268
|
mIsMenuDisplayed = true
|
|
269
|
+
val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(mContext, id)
|
|
270
|
+
val surfaceId: Int = UIManagerHelper.getSurfaceId(this)
|
|
271
|
+
dispatcher?.dispatchEvent(MenuOnOpenEvent(surfaceId, id, id))
|
|
266
272
|
mPopupMenu.show()
|
|
267
273
|
}
|
|
268
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
|
-
|
|
41
|
-
|
|
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(
|
|
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(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
165
|
+
view: ReactViewGroup,
|
|
166
|
+
needsOffscreenAlphaCompositing: Boolean
|
|
167
|
+
) {
|
|
135
168
|
view.setNeedsOffscreenAlphaCompositing(needsOffscreenAlphaCompositing)
|
|
136
169
|
}
|
|
137
170
|
|
|
138
|
-
@ReactPropGroup(
|
|
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(
|
|
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)
|
|
@@ -181,14 +235,15 @@ abstract class MenuViewManagerBase: ReactClippingViewManager<MenuView>() {
|
|
|
181
235
|
|
|
182
236
|
companion object {
|
|
183
237
|
val COMMAND_SHOW = 1
|
|
184
|
-
val SPACING_TYPES =
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
+
)
|
|
193
248
|
}
|
|
194
249
|
}
|
package/ios/MenuViewManager.mm
CHANGED
|
@@ -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
|
}
|
package/ios/NewArch/MenuView.mm
CHANGED
|
@@ -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
|
*/
|
|
@@ -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
|
}
|
|
@@ -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:
|
|
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
|
}
|
|
@@ -53,13 +53,28 @@ public class MenuViewImplementation: UIButton {
|
|
|
53
53
|
@objc public var hitSlop: UIEdgeInsets = .zero
|
|
54
54
|
|
|
55
55
|
override init(frame: CGRect) {
|
|
56
|
-
|
|
57
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
101
|
-
|
|
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
|
}
|
|
@@ -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,
|
|
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":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_reactNative","_UIMenuView","_interopRequireDefault","_utils","_jsxRuntime","e","__esModule","default","processAction","action","imageColor","processColor","titleColor","subactions","map","subAction","defaultHitslop","top","left","bottom","right","MenuView","exports","forwardRef","actions","hitSlop","props","ref","processedActions","hash","useMemo","objectHash","jsx","actionsHash"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,WAAA,GAAAC,sBAAA,CAAAH,OAAA;AAQA,IAAAI,MAAA,GAAAJ,OAAA;AAAqC,IAAAK,WAAA,GAAAL,OAAA;AAAA,SAAAG,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAErC,SAASG,aAAaA,CAACC,MAAkB,EAAuB;
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","_UIMenuView","_interopRequireDefault","_utils","_jsxRuntime","e","__esModule","default","processAction","action","imageColor","processColor","titleColor","subactions","map","subAction","defaultHitslop","top","left","bottom","right","MenuView","exports","forwardRef","actions","hitSlop","props","ref","processedActions","hash","useMemo","objectHash","jsx","actionsHash"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,WAAA,GAAAC,sBAAA,CAAAH,OAAA;AAQA,IAAAI,MAAA,GAAAJ,OAAA;AAAqC,IAAAK,WAAA,GAAAL,OAAA;AAAA,SAAAG,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"names":["codegenNativeComponent"],"sourceRoot":"../../../src","sources":["NativeModuleSpecs/UIMenuNativeComponent.ts"],"mappings":";;AAKA,OAAOA,sBAAsB,MAAM,yDAAyD;AAC5F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;
|
|
1
|
+
{"version":3,"names":["codegenNativeComponent"],"sourceRoot":"../../../src","sources":["NativeModuleSpecs/UIMenuNativeComponent.ts"],"mappings":";;AAKA,OAAOA,sBAAsB,MAAM,yDAAyD;AAC5F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAkDA,eAAeA,sBAAsB,CACpC,UACD,CAAC","ignoreList":[]}
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["forwardRef","useMemo","processColor","UIMenuView","objectHash","jsx","_jsx","processAction","action","imageColor","titleColor","subactions","map","subAction","defaultHitslop","top","left","bottom","right","MenuView","actions","hitSlop","props","ref","processedActions","hash","actionsHash"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,UAAU,EAAEC,OAAO,QAAQ,OAAO;AAC3C,SAASC,YAAY,QAAQ,cAAc;AAE3C,OAAOC,UAAU,MAAM,cAAc;AAQrC,SAASC,UAAU,QAAQ,SAAS;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAErC,SAASC,aAAaA,CAACC,MAAkB,EAAuB;
|
|
1
|
+
{"version":3,"names":["forwardRef","useMemo","processColor","UIMenuView","objectHash","jsx","_jsx","processAction","action","imageColor","titleColor","subactions","map","subAction","defaultHitslop","top","left","bottom","right","MenuView","actions","hitSlop","props","ref","processedActions","hash","actionsHash"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,UAAU,EAAEC,OAAO,QAAQ,OAAO;AAC3C,SAASC,YAAY,QAAQ,cAAc;AAE3C,OAAOC,UAAU,MAAM,cAAc;AAQrC,SAASC,UAAU,QAAQ,SAAS;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAErC,SAASC,aAAaA,CAACC,MAAkB,EAAuB;EAC/D,OAAO;IACN,GAAGA,MAAM;IACTC,UAAU,EAAEP,YAAY,CAACM,MAAM,CAACC,UAAU,CAAC;IAC3CC,UAAU,EAAER,YAAY,CAACM,MAAM,CAACE,UAAU,CAAC;IAC3CC,UAAU,EAAEH,MAAM,CAACG,UAAU,EAAEC,GAAG,CAAEC,SAAS,IAAKN,aAAa,CAACM,SAAS,CAAC;EAC3E,CAAC;AACF;AAEA,MAAMC,cAAc,GAAG;EAAEC,GAAG,EAAE,CAAC;EAAEC,IAAI,EAAE,CAAC;EAAEC,MAAM,EAAE,CAAC;EAAEC,KAAK,EAAE;AAAE,CAAC;AAE/D,MAAMC,QAAQ,gBAAGnB,UAAU,CAC1B,CAAC;EAAEoB,OAAO;EAAEC,OAAO,GAAGP,cAAc;EAAE,GAAGQ;AAAM,CAAC,EAAEC,GAAG,KAAK;EACzD,MAAMC,gBAAgB,GAAGJ,OAAO,CAACR,GAAG,CAAuBJ,MAAM,IAChED,aAAa,CAACC,MAAM,CACrB,CAAC;EACD,MAAMiB,IAAI,GAAGxB,OAAO,CAAC,MAAM;IAC1B,OAAOG,UAAU,CAACoB,gBAAgB,CAAC;EACpC,CAAC,EAAE,CAACA,gBAAgB,CAAC,CAAC;EAEtB,oBACClB,IAAA,CAACH,UAAU;IAAA,GACNmB,KAAK;IACTD,OAAO,EAAEA,OAAQ;IACjBD,OAAO,EAAEI,gBAAiB;IAC1BE,WAAW,EAAED,IAAK;IAClBF,GAAG,EAAEA;EAAI,CACT,CAAC;AAEJ,CACD,CAAC;AAED,SAASJ,QAAQ","ignoreList":[]}
|
|
@@ -35,6 +35,12 @@ export interface NativeProps extends ViewProps {
|
|
|
35
35
|
onPressAction?: DirectEventHandler<{
|
|
36
36
|
event: string;
|
|
37
37
|
}>;
|
|
38
|
+
onCloseMenu?: DirectEventHandler<{
|
|
39
|
+
event: string;
|
|
40
|
+
}>;
|
|
41
|
+
onOpenMenu?: DirectEventHandler<{
|
|
42
|
+
event: string;
|
|
43
|
+
}>;
|
|
38
44
|
actions: Array<MenuAction>;
|
|
39
45
|
actionsHash: string;
|
|
40
46
|
title?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UIMenuNativeComponent.d.ts","sourceRoot":"","sources":["../../../../src/NativeModuleSpecs/UIMenuNativeComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,kBAAkB,EAClB,KAAK,EACL,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"UIMenuNativeComponent.d.ts","sourceRoot":"","sources":["../../../../src/NativeModuleSpecs/UIMenuNativeComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,kBAAkB,EAClB,KAAK,EACL,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAW7D,KAAK,SAAS,GAAG;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,CAAC,EAAE;QACZ,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,MAAM,CAAC,EAAE,OAAO,CAAC;KACjB,CAAC;CACF,CAAC;AACF,KAAK,UAAU,GAAG;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,CAAC,EAAE;QACZ,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,MAAM,CAAC,EAAE,OAAO,CAAC;KACjB,CAAC;IACF,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;CAC9B,CAAC;AACF,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC7C,aAAa,CAAC,EAAE,kBAAkB,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACtD,WAAW,CAAC,EAAE,kBAAkB,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACpD,UAAU,CAAC,EAAE,kBAAkB,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnD,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,OAAO,EAAE;QACR,GAAG,EAAE,KAAK,CAAC;QACX,MAAM,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,KAAK,CAAC;QACZ,KAAK,EAAE,KAAK,CAAC;KACb,CAAC;CACF;wBAII,aAAa,CAAC,WAAW,CAAC;AAF/B,wBAEgC"}
|
|
@@ -2,6 +2,8 @@ import type { MenuComponentProps, MenuAction, NativeActionEvent, MenuComponentRe
|
|
|
2
2
|
declare const MenuView: import("react").ForwardRefExoticComponent<{
|
|
3
3
|
style?: import("react-native").StyleProp<import("react-native").ViewStyle>;
|
|
4
4
|
onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;
|
|
5
|
+
onCloseMenu?: () => void;
|
|
6
|
+
onOpenMenu?: () => void;
|
|
5
7
|
actions: MenuAction[];
|
|
6
8
|
title?: string;
|
|
7
9
|
isAnchoredToRight?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACX,kBAAkB,EAClB,UAAU,EAEV,iBAAiB,EACjB,gBAAgB,EAChB,MAAM,SAAS,CAAC;AAcjB,QAAA,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;oDAmBb,CAAC;AAEF,OAAO,EAAE,QAAQ,EAAE,CAAC;AACpB,YAAY,EACX,kBAAkB,EAClB,gBAAgB,EAChB,UAAU,EACV,iBAAiB,GACjB,CAAC"}
|
|
@@ -105,6 +105,14 @@ type MenuComponentPropsBase = {
|
|
|
105
105
|
* It will contain id of the given action.
|
|
106
106
|
*/
|
|
107
107
|
onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;
|
|
108
|
+
/**
|
|
109
|
+
* Callback function that will be called when the menu closes.
|
|
110
|
+
*/
|
|
111
|
+
onCloseMenu?: () => void;
|
|
112
|
+
/**
|
|
113
|
+
* Callback function that will be called when the menu opens.
|
|
114
|
+
*/
|
|
115
|
+
onOpenMenu?: () => void;
|
|
108
116
|
/**
|
|
109
117
|
* Actions to be displayed in the menu.
|
|
110
118
|
*/
|
|
@@ -160,6 +168,8 @@ export type ProcessedMenuAction = Omit<MenuAction, "imageColor" | "titleColor" |
|
|
|
160
168
|
export type NativeMenuComponentProps = {
|
|
161
169
|
style?: StyleProp<ViewStyle>;
|
|
162
170
|
onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;
|
|
171
|
+
onCloseMenu?: () => void;
|
|
172
|
+
onOpenMenu?: () => void;
|
|
163
173
|
actions: ProcessedMenuAction[];
|
|
164
174
|
actionsHash: string;
|
|
165
175
|
title?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,UAAU,EACV,YAAY,EACZ,SAAS,EACT,SAAS,EACT,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAEpC,MAAM,MAAM,iBAAiB,GAAG;IAC/B,WAAW,EAAE;QACZ,KAAK,EAAE,MAAM,CAAC;KACd,CAAC;CACF,CAAC;AAEF,KAAK,cAAc,GAAG;IACrB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF;;;;;GAKG;AACH,KAAK,SAAS,GAAG,KAAK,GAAG,IAAI,GAAG,OAAO,CAAC;AAExC,MAAM,MAAM,UAAU,GAAG;IACxB;;;OAGG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IACjC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B;;;;OAIG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB;;;;;;;;;;OAUG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IACjC;;;;OAIG;IACH,UAAU,CAA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IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAC7B,KAAK,CAAC,iBAAiB,CAAC,sBAAsB,CAAC,CAAC;AAEjD,MAAM,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,MAAM,IAAI,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,IAAI,CACrC,UAAU,EACV,YAAY,GAAG,YAAY,GAAG,YAAY,CAC1C,GAAG;IACH,UAAU,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;IAC5C,UAAU,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;IAC5C,UAAU,CAAC,EAAE,mBAAmB,EAAE,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACtC,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,aAAa,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC7D,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,OAAO,EAAE,mBAAmB,EAAE,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;CAC3C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-menu/menu",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "UIMenu component for react-native",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"pod-install": "^0.3.2",
|
|
59
59
|
"react": "18.2.0",
|
|
60
60
|
"react-native": "^0.73.0",
|
|
61
|
-
"react-native-builder-bob": "^0.
|
|
61
|
+
"react-native-builder-bob": "^0.35.2",
|
|
62
62
|
"react-native-test-app": "^4.0.4",
|
|
63
63
|
"release-it": "^17.2.0",
|
|
64
64
|
"typescript": "5.7.2"
|
|
@@ -12,6 +12,7 @@ import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNati
|
|
|
12
12
|
OR with extending types in an interface, so for now we'll just keep some duplicate
|
|
13
13
|
types here, to avoid issues while `pod install` takes place.
|
|
14
14
|
*/
|
|
15
|
+
|
|
15
16
|
type SubAction = {
|
|
16
17
|
id?: string;
|
|
17
18
|
title: string;
|
|
@@ -45,6 +46,8 @@ type MenuAction = {
|
|
|
45
46
|
};
|
|
46
47
|
export interface NativeProps extends ViewProps {
|
|
47
48
|
onPressAction?: DirectEventHandler<{ event: string }>;
|
|
49
|
+
onCloseMenu?: DirectEventHandler<{ event: string }>;
|
|
50
|
+
onOpenMenu?: DirectEventHandler<{ event: string }>;
|
|
48
51
|
actions: Array<MenuAction>;
|
|
49
52
|
actionsHash: string; // just a workaround to make sure we don't have to manually compare MenuActions manually in C++ (since it's a struct and that's a pain)
|
|
50
53
|
title?: string;
|
|
@@ -55,7 +58,7 @@ export interface NativeProps extends ViewProps {
|
|
|
55
58
|
bottom: Int32;
|
|
56
59
|
left: Int32;
|
|
57
60
|
right: Int32;
|
|
58
|
-
}
|
|
61
|
+
};
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
export default codegenNativeComponent<NativeProps>(
|
package/src/index.tsx
CHANGED
|
@@ -3,50 +3,50 @@ import { processColor } from "react-native";
|
|
|
3
3
|
|
|
4
4
|
import UIMenuView from "./UIMenuView";
|
|
5
5
|
import type {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
MenuComponentProps,
|
|
7
|
+
MenuAction,
|
|
8
|
+
ProcessedMenuAction,
|
|
9
|
+
NativeActionEvent,
|
|
10
|
+
MenuComponentRef,
|
|
11
11
|
} from "./types";
|
|
12
12
|
import { objectHash } from "./utils";
|
|
13
13
|
|
|
14
14
|
function processAction(action: MenuAction): ProcessedMenuAction {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
return {
|
|
16
|
+
...action,
|
|
17
|
+
imageColor: processColor(action.imageColor),
|
|
18
|
+
titleColor: processColor(action.titleColor),
|
|
19
|
+
subactions: action.subactions?.map((subAction) => processAction(subAction)),
|
|
20
|
+
};
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const defaultHitslop = { top: 0, left: 0, bottom: 0, right: 0 };
|
|
24
24
|
|
|
25
25
|
const MenuView = forwardRef<MenuComponentRef, MenuComponentProps>(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
({ actions, hitSlop = defaultHitslop, ...props }, ref) => {
|
|
27
|
+
const processedActions = actions.map<ProcessedMenuAction>((action) =>
|
|
28
|
+
processAction(action),
|
|
29
|
+
);
|
|
30
|
+
const hash = useMemo(() => {
|
|
31
|
+
return objectHash(processedActions);
|
|
32
|
+
}, [processedActions]);
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
return (
|
|
35
|
+
<UIMenuView
|
|
36
|
+
{...props}
|
|
37
|
+
hitSlop={hitSlop}
|
|
38
|
+
actions={processedActions}
|
|
39
|
+
actionsHash={hash}
|
|
40
|
+
ref={ref}
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
},
|
|
44
44
|
);
|
|
45
45
|
|
|
46
46
|
export { MenuView };
|
|
47
47
|
export type {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
MenuComponentProps,
|
|
49
|
+
MenuComponentRef,
|
|
50
|
+
MenuAction,
|
|
51
|
+
NativeActionEvent,
|
|
52
52
|
};
|
package/src/types.ts
CHANGED
|
@@ -115,6 +115,14 @@ type MenuComponentPropsBase = {
|
|
|
115
115
|
* It will contain id of the given action.
|
|
116
116
|
*/
|
|
117
117
|
onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;
|
|
118
|
+
/**
|
|
119
|
+
* Callback function that will be called when the menu closes.
|
|
120
|
+
*/
|
|
121
|
+
onCloseMenu?: () => void;
|
|
122
|
+
/**
|
|
123
|
+
* Callback function that will be called when the menu opens.
|
|
124
|
+
*/
|
|
125
|
+
onOpenMenu?: () => void;
|
|
118
126
|
/**
|
|
119
127
|
* Actions to be displayed in the menu.
|
|
120
128
|
*/
|
|
@@ -179,6 +187,8 @@ export type ProcessedMenuAction = Omit<
|
|
|
179
187
|
export type NativeMenuComponentProps = {
|
|
180
188
|
style?: StyleProp<ViewStyle>;
|
|
181
189
|
onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;
|
|
190
|
+
onCloseMenu?: () => void;
|
|
191
|
+
onOpenMenu?: () => void;
|
|
182
192
|
actions: ProcessedMenuAction[];
|
|
183
193
|
actionsHash: string;
|
|
184
194
|
title?: string;
|