@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.
- package/README.md +49 -1
- 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 +10 -0
- package/android/src/main/java/com/reactnativemenu/MenuViewManagerBase.kt +89 -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 +5 -0
- package/ios/NewArch/MenuView.mm +39 -0
- package/ios/OldArch/LegacyActionSheetView.swift +17 -2
- package/ios/OldArch/LegacyMenuViewImplementation.swift +14 -0
- package/ios/Shared/ActionSheetView.swift +15 -3
- package/ios/Shared/MenuViewImplementation.swift +35 -15
- package/lib/commonjs/NativeModuleSpecs/UIMenuNativeComponent.js +1 -1
- package/lib/commonjs/NativeModuleSpecs/UIMenuNativeComponent.js.map +1 -1
- package/lib/commonjs/UIMenuView.android.js +19 -1
- package/lib/commonjs/UIMenuView.android.js.map +1 -1
- package/lib/commonjs/UIMenuView.js +0 -3
- package/lib/commonjs/UIMenuView.js.map +1 -1
- package/lib/commonjs/index.js +6 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils.js +1 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/module/NativeModuleSpecs/UIMenuNativeComponent.js +2 -2
- package/lib/module/NativeModuleSpecs/UIMenuNativeComponent.js.map +1 -1
- package/lib/module/UIMenuView.android.js +20 -2
- package/lib/module/UIMenuView.android.js.map +1 -1
- package/lib/module/UIMenuView.ios.js +1 -1
- package/lib/module/UIMenuView.js +1 -2
- package/lib/module/UIMenuView.js.map +1 -1
- package/lib/module/index.js +9 -8
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils.js +1 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/typescript/src/NativeModuleSpecs/UIMenuNativeComponent.d.ts +16 -2
- package/lib/typescript/src/NativeModuleSpecs/UIMenuNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/UIMenuView.android.d.ts +2 -3
- package/lib/typescript/src/UIMenuView.android.d.ts.map +1 -1
- package/lib/typescript/src/UIMenuView.d.ts +2 -2
- package/lib/typescript/src/UIMenuView.d.ts.map +1 -1
- package/lib/typescript/src/UIMenuView.ios.d.ts +1 -1
- package/lib/typescript/src/index.d.ts +22 -4
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +20 -6
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts +1 -1
- package/lib/typescript/src/utils.d.ts.map +1 -1
- package/package.json +10 -44
- package/src/NativeModuleSpecs/UIMenuNativeComponent.ts +48 -37
- package/src/UIMenuView.android.tsx +34 -4
- package/src/UIMenuView.ios.tsx +1 -1
- package/src/UIMenuView.tsx +11 -11
- package/src/index.tsx +42 -36
- package/src/types.ts +168 -153
- package/src/utils.ts +17 -17
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from
|
|
5
|
-
import type { HostComponent, ViewProps } from
|
|
6
|
-
import codegenNativeComponent from
|
|
2
|
+
DirectEventHandler,
|
|
3
|
+
Int32,
|
|
4
|
+
} from "react-native/Libraries/Types/CodegenTypes";
|
|
5
|
+
import type { HostComponent, ViewProps } from "react-native";
|
|
6
|
+
import codegenNativeComponent from "react-native/Libraries/Utilities/codegenNativeComponent";
|
|
7
7
|
/*
|
|
8
8
|
Caution, those below are not just typescript types.
|
|
9
9
|
Codegen is using them to create the corresponding C++ data types.
|
|
@@ -12,44 +12,55 @@ 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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
id?: string;
|
|
18
|
+
title: string;
|
|
19
|
+
titleColor?: Int32;
|
|
20
|
+
subtitle?: string;
|
|
21
|
+
state?: string;
|
|
22
|
+
image?: string;
|
|
23
|
+
imageColor?: Int32;
|
|
24
|
+
displayInline?: boolean;
|
|
25
|
+
attributes?: {
|
|
26
|
+
destructive?: boolean;
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
hidden?: boolean;
|
|
29
|
+
};
|
|
29
30
|
};
|
|
30
31
|
type MenuAction = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
id?: string;
|
|
33
|
+
title: string;
|
|
34
|
+
titleColor?: Int32;
|
|
35
|
+
subtitle?: string;
|
|
36
|
+
state?: string;
|
|
37
|
+
image?: string;
|
|
38
|
+
imageColor?: Int32;
|
|
39
|
+
displayInline?: boolean;
|
|
40
|
+
attributes?: {
|
|
41
|
+
destructive?: boolean;
|
|
42
|
+
disabled?: boolean;
|
|
43
|
+
hidden?: boolean;
|
|
44
|
+
};
|
|
45
|
+
subactions?: Array<SubAction>;
|
|
45
46
|
};
|
|
46
47
|
export interface NativeProps extends ViewProps {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
onPressAction?: DirectEventHandler<{ event: string }>;
|
|
49
|
+
onCloseMenu?: DirectEventHandler<{ event: string }>;
|
|
50
|
+
onOpenMenu?: DirectEventHandler<{ event: string }>;
|
|
51
|
+
actions: Array<MenuAction>;
|
|
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)
|
|
53
|
+
title?: string;
|
|
54
|
+
themeVariant?: string;
|
|
55
|
+
shouldOpenOnLongPress?: boolean;
|
|
56
|
+
hitSlop: {
|
|
57
|
+
top: Int32;
|
|
58
|
+
bottom: Int32;
|
|
59
|
+
left: Int32;
|
|
60
|
+
right: Int32;
|
|
61
|
+
};
|
|
51
62
|
}
|
|
52
63
|
|
|
53
64
|
export default codegenNativeComponent<NativeProps>(
|
|
54
|
-
|
|
65
|
+
"MenuView",
|
|
55
66
|
) as HostComponent<NativeProps>;
|
|
@@ -1,8 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
findNodeHandle,
|
|
3
|
+
type HostComponent,
|
|
4
|
+
requireNativeComponent,
|
|
5
|
+
UIManager,
|
|
6
|
+
} from "react-native";
|
|
7
|
+
import type { MenuComponentRef, NativeMenuComponentProps } from "./types";
|
|
8
|
+
import { forwardRef, useImperativeHandle, useRef } from "react";
|
|
3
9
|
|
|
4
|
-
const
|
|
5
|
-
|
|
10
|
+
const NativeMenuComponent = requireNativeComponent(
|
|
11
|
+
"MenuView",
|
|
6
12
|
) as HostComponent<NativeMenuComponentProps>;
|
|
7
13
|
|
|
14
|
+
const MenuComponent = forwardRef<MenuComponentRef, NativeMenuComponentProps>(
|
|
15
|
+
(props, ref) => {
|
|
16
|
+
const nativeRef = useRef(null);
|
|
17
|
+
|
|
18
|
+
useImperativeHandle(
|
|
19
|
+
ref,
|
|
20
|
+
() => ({
|
|
21
|
+
show: () => {
|
|
22
|
+
if (nativeRef.current) {
|
|
23
|
+
const node = findNodeHandle(nativeRef.current);
|
|
24
|
+
const command =
|
|
25
|
+
UIManager.getViewManagerConfig("MenuView").Commands.show;
|
|
26
|
+
|
|
27
|
+
UIManager.dispatchViewManagerCommand(node, command, undefined);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
}),
|
|
31
|
+
[],
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return <NativeMenuComponent {...props} ref={nativeRef} />;
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
|
|
8
38
|
export default MenuComponent;
|
package/src/UIMenuView.ios.tsx
CHANGED
package/src/UIMenuView.tsx
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import { View } from
|
|
3
|
-
import type { NativeMenuComponentProps } from
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
import type { NativeMenuComponentProps } from "./types";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* TODO: implement for Web
|
|
7
7
|
*/
|
|
8
8
|
const MenuView: React.FC<React.PropsWithChildren<NativeMenuComponentProps>> = ({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
style,
|
|
10
|
+
children,
|
|
11
|
+
testID,
|
|
12
12
|
}) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
return (
|
|
14
|
+
<View style={style} testID={testID}>
|
|
15
|
+
{children}
|
|
16
|
+
</View>
|
|
17
|
+
);
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
export default MenuView;
|
package/src/index.tsx
CHANGED
|
@@ -1,46 +1,52 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { processColor } from
|
|
1
|
+
import { forwardRef, useMemo } from "react";
|
|
2
|
+
import { processColor } from "react-native";
|
|
3
3
|
|
|
4
|
-
import UIMenuView from
|
|
4
|
+
import UIMenuView from "./UIMenuView";
|
|
5
5
|
import type {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
MenuComponentProps,
|
|
7
|
+
MenuAction,
|
|
8
|
+
ProcessedMenuAction,
|
|
9
|
+
NativeActionEvent,
|
|
10
|
+
MenuComponentRef,
|
|
11
|
+
} from "./types";
|
|
12
|
+
import { objectHash } from "./utils";
|
|
12
13
|
|
|
13
14
|
function processAction(action: MenuAction): ProcessedMenuAction {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
return {
|
|
16
|
+
...action,
|
|
17
|
+
imageColor: processColor(action.imageColor),
|
|
18
|
+
titleColor: processColor(action.titleColor),
|
|
19
|
+
subactions: action.subactions?.map((subAction) => processAction(subAction)),
|
|
20
|
+
};
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
const defaultHitslop = { top: 0, left: 0, bottom: 0, right: 0 };
|
|
23
24
|
|
|
24
|
-
const MenuView
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
25
|
+
const MenuView = forwardRef<MenuComponentRef, MenuComponentProps>(
|
|
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
|
+
|
|
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
|
export { MenuView };
|
|
46
|
-
export type {
|
|
47
|
+
export type {
|
|
48
|
+
MenuComponentProps,
|
|
49
|
+
MenuComponentRef,
|
|
50
|
+
MenuAction,
|
|
51
|
+
NativeActionEvent,
|
|
52
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from
|
|
7
|
-
import type * as React from
|
|
2
|
+
ColorValue,
|
|
3
|
+
processColor,
|
|
4
|
+
StyleProp,
|
|
5
|
+
ViewStyle,
|
|
6
|
+
} from "react-native";
|
|
7
|
+
import type * as React from "react";
|
|
8
8
|
|
|
9
9
|
export type NativeActionEvent = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
nativeEvent: {
|
|
11
|
+
event: string;
|
|
12
|
+
};
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
type MenuAttributes = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
/**
|
|
17
|
+
* An attribute indicating the destructive style.
|
|
18
|
+
*/
|
|
19
|
+
destructive?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* An attribute indicating the disabled style.
|
|
22
|
+
*/
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* An attribute indicating the hidden style.
|
|
26
|
+
*/
|
|
27
|
+
hidden?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* (iOS16+ only)
|
|
30
|
+
* @platform iOS
|
|
31
|
+
* An attribute indicating that the menu should remain presented after firing.
|
|
32
|
+
*/
|
|
33
|
+
keepsMenuPresented?: boolean;
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
/**
|
|
@@ -39,145 +39,160 @@ type MenuAttributes = {
|
|
|
39
39
|
* - on: A constant indicating the menu element is in the “on” state.
|
|
40
40
|
* - mixed: A constant indicating the menu element is in the “mixed” state.
|
|
41
41
|
*/
|
|
42
|
-
type MenuState =
|
|
42
|
+
type MenuState = "off" | "on" | "mixed";
|
|
43
43
|
|
|
44
44
|
export type MenuAction = {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Identifier of the menu action.
|
|
47
|
+
* The value set in this id will be returned when menu is selected.
|
|
48
|
+
*/
|
|
49
|
+
id?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The action's title.
|
|
52
|
+
*/
|
|
53
|
+
title: string;
|
|
54
|
+
/**
|
|
55
|
+
* (Android only)
|
|
56
|
+
* The action's title color.
|
|
57
|
+
* @platform Android
|
|
58
|
+
*/
|
|
59
|
+
titleColor?: number | ColorValue;
|
|
60
|
+
/**
|
|
61
|
+
* (iOS14+ only)
|
|
62
|
+
* An elaborated title that explains the purpose of the action.
|
|
63
|
+
* @platform iOS
|
|
64
|
+
*/
|
|
65
|
+
subtitle?: string;
|
|
66
|
+
/**
|
|
67
|
+
* The attributes indicating the style of the action.
|
|
68
|
+
*/
|
|
69
|
+
attributes?: MenuAttributes;
|
|
70
|
+
/**
|
|
71
|
+
* (iOS14+ only)
|
|
72
|
+
* The state of the action.
|
|
73
|
+
* @platform iOS
|
|
74
|
+
*/
|
|
75
|
+
state?: MenuState;
|
|
76
|
+
/**
|
|
77
|
+
* (Android and iOS13+ only)
|
|
78
|
+
* - The action's image.
|
|
79
|
+
* - Allows icon name included in project or system (Android) resources drawables and
|
|
80
|
+
* in SF Symbol (iOS)
|
|
81
|
+
* @example // (iOS)
|
|
82
|
+
* image="plus"
|
|
83
|
+
* @example // (Android)
|
|
84
|
+
* image="ic_menu_add"
|
|
85
|
+
* - TODO: Allow images other than those included in SF Symbol and resources drawables
|
|
86
|
+
*/
|
|
87
|
+
image?: string;
|
|
88
|
+
/**
|
|
89
|
+
* (Android and iOS13+ only)
|
|
90
|
+
* - The action's image color.
|
|
91
|
+
*/
|
|
92
|
+
imageColor?: number | ColorValue;
|
|
93
|
+
/**
|
|
94
|
+
* (Android and iOS14+ only)
|
|
95
|
+
* - Actions to be displayed in the sub menu
|
|
96
|
+
* - On Android it does not support nesting next sub menus in sub menu item
|
|
97
|
+
*/
|
|
98
|
+
subactions?: MenuAction[];
|
|
99
|
+
/**
|
|
100
|
+
* Whether subactions should be inline (separated by divider) or nested (sub menu)
|
|
101
|
+
*/
|
|
102
|
+
displayInline?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* (iOS 16+ only)
|
|
105
|
+
* The preferred size of this menu's child elements.
|
|
106
|
+
* @platform iOS
|
|
107
|
+
*/
|
|
108
|
+
preferredElementSize?: "small" | "medium" | "large";
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
type MenuComponentPropsBase = {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
112
|
+
style?: StyleProp<ViewStyle>;
|
|
113
|
+
/**
|
|
114
|
+
* Callback function that will be called when selecting a menu item.
|
|
115
|
+
* It will contain id of the given action.
|
|
116
|
+
*/
|
|
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;
|
|
126
|
+
/**
|
|
127
|
+
* Actions to be displayed in the menu.
|
|
128
|
+
*/
|
|
129
|
+
actions: MenuAction[];
|
|
130
|
+
/**
|
|
131
|
+
* The title of the menu.
|
|
132
|
+
*/
|
|
133
|
+
title?: string;
|
|
126
134
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
135
|
+
/**
|
|
136
|
+
* (Android API 23+)
|
|
137
|
+
* Boolean value determines whether popup menu should be anchored
|
|
138
|
+
* to right corner of parent view - default value is `false`
|
|
139
|
+
* @platform Android
|
|
140
|
+
*/
|
|
141
|
+
isAnchoredToRight?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Determines if menu should open after long press or on normal press
|
|
144
|
+
*
|
|
145
|
+
* @default false
|
|
146
|
+
*/
|
|
147
|
+
shouldOpenOnLongPress?: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Overrides theme variant of menu to light mode, dark mode or system theme
|
|
150
|
+
* (Only support iOS for now)
|
|
151
|
+
*
|
|
152
|
+
* @platform iOS
|
|
153
|
+
*/
|
|
154
|
+
themeVariant?: string;
|
|
155
|
+
/**
|
|
156
|
+
* Custom OpenSpace hitSlop prop. Works like touchable hitslop.
|
|
157
|
+
* @platform iOS
|
|
158
|
+
*/
|
|
159
|
+
hitSlop?: {
|
|
160
|
+
top: number;
|
|
161
|
+
bottom: number;
|
|
162
|
+
left: number;
|
|
163
|
+
right: number;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Test ID for testing purposes
|
|
167
|
+
*/
|
|
168
|
+
testID?: string;
|
|
161
169
|
};
|
|
162
170
|
|
|
163
171
|
export type MenuComponentProps =
|
|
164
|
-
|
|
172
|
+
React.PropsWithChildren<MenuComponentPropsBase>;
|
|
173
|
+
|
|
174
|
+
export type MenuComponentRef = {
|
|
175
|
+
show: () => void;
|
|
176
|
+
};
|
|
165
177
|
|
|
166
178
|
export type ProcessedMenuAction = Omit<
|
|
167
|
-
|
|
168
|
-
|
|
179
|
+
MenuAction,
|
|
180
|
+
"imageColor" | "titleColor" | "subactions"
|
|
169
181
|
> & {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
182
|
+
imageColor: ReturnType<typeof processColor>;
|
|
183
|
+
titleColor: ReturnType<typeof processColor>;
|
|
184
|
+
subactions?: ProcessedMenuAction[];
|
|
173
185
|
};
|
|
174
186
|
|
|
175
187
|
export type NativeMenuComponentProps = {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
188
|
+
style?: StyleProp<ViewStyle>;
|
|
189
|
+
onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;
|
|
190
|
+
onCloseMenu?: () => void;
|
|
191
|
+
onOpenMenu?: () => void;
|
|
192
|
+
actions: ProcessedMenuAction[];
|
|
193
|
+
actionsHash: string;
|
|
194
|
+
title?: string;
|
|
195
|
+
hitSlop?: MenuComponentProps["hitSlop"];
|
|
196
|
+
testID?: string;
|
|
197
|
+
ref?: React.ForwardedRef<MenuComponentRef>;
|
|
183
198
|
};
|
package/src/utils.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
// Function to calculate a simple hash code for a string
|
|
2
2
|
function hashCode(str: string): number {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
let hash = 0;
|
|
4
|
+
for (let i = 0; i < str.length; i++) {
|
|
5
|
+
const char = str.charCodeAt(i);
|
|
6
|
+
// eslint-disable-next-line no-bitwise
|
|
7
|
+
hash = (hash << 5) - hash + char;
|
|
8
|
+
}
|
|
9
|
+
return hash;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
// Function to create a string hash from a TypeScript object
|
|
13
|
-
export function objectHash(obj: Record<string,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
export function objectHash(obj: Record<string, unknown>[]): string {
|
|
14
|
+
if (!obj) {
|
|
15
|
+
return "";
|
|
16
|
+
}
|
|
17
|
+
// Convert the object to a JSON string
|
|
18
|
+
const jsonString = JSON.stringify(obj);
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
// Calculate the hash code of the JSON string
|
|
21
|
+
const hash = hashCode(jsonString);
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
// Convert the hash code to a string (optional)
|
|
24
|
+
return String(hash);
|
|
25
25
|
}
|