-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathtypes.ts
More file actions
206 lines (194 loc) · 4.72 KB
/
Copy pathtypes.ts
File metadata and controls
206 lines (194 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import type {
ColorValue,
processColor,
StyleProp,
ViewStyle,
} from "react-native";
import type * as React from "react";
export type NativeActionEvent = {
nativeEvent: {
event: string;
};
};
export type MenuThemeVariant = "light" | "dark" | "system";
export type MenuUiKit = "auto" | "material3" | "appcompat";
type MenuAttributes = {
/**
* An attribute indicating the destructive style.
*/
destructive?: boolean;
/**
* An attribute indicating the disabled style.
*/
disabled?: boolean;
/**
* An attribute indicating the hidden style.
*/
hidden?: boolean;
/**
* (iOS16+ only)
* @platform iOS
* An attribute indicating that the menu should remain presented after firing.
*/
keepsMenuPresented?: boolean;
};
/**
* The state of the action.
* - off: A constant indicating the menu element is in the “off” state.
* - on: A constant indicating the menu element is in the “on” state.
* - mixed: A constant indicating the menu element is in the “mixed” state.
*/
type MenuState = "off" | "on" | "mixed";
export type MenuAction = {
/**
* Identifier of the menu action.
* The value set in this id will be returned when menu is selected.
*/
id?: string;
/**
* The action's title.
*/
title: string;
/**
* (Android only)
* The action's title color.
* @platform Android
*/
titleColor?: number | ColorValue;
/**
* (iOS14+ only)
* An elaborated title that explains the purpose of the action.
* @platform iOS
*/
subtitle?: string;
/**
* The attributes indicating the style of the action.
*/
attributes?: MenuAttributes;
/**
* (iOS14+ only)
* The state of the action.
* @platform iOS
*/
state?: MenuState;
/**
* (Android and iOS13+ only)
* - The action's image.
* - Allows icon name included in project or system (Android) resources drawables and
* in SF Symbol (iOS)
* @example // (iOS)
* image="plus"
* @example // (Android)
* image="ic_menu_add"
* - TODO: Allow images other than those included in SF Symbol and resources drawables
*/
image?: string;
/**
* (Android and iOS13+ only)
* - The action's image color.
*/
imageColor?: number | ColorValue;
/**
* (Android and iOS14+ only)
* - Actions to be displayed in the sub menu
* - On Android it does not support nesting next sub menus in sub menu item
*/
subactions?: MenuAction[];
/**
* Whether subactions should be inline (separated by divider) or nested (sub menu)
*/
displayInline?: boolean;
/**
* (iOS 16+ only)
* The preferred size of this menu's child elements.
* @platform iOS
*/
preferredElementSize?: "small" | "medium" | "large";
};
type MenuComponentPropsBase = {
style?: StyleProp<ViewStyle>;
/**
* Callback function that will be called when selecting a menu item.
* It will contain id of the given action.
*/
onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;
/**
* Callback function that will be called when the menu closes.
*/
onCloseMenu?: () => void;
/**
* Callback function that will be called when the menu opens.
*/
onOpenMenu?: () => void;
/**
* Actions to be displayed in the menu.
*/
actions: MenuAction[];
/**
* The title of the menu.
*/
title?: string;
/**
* (Android API 23+)
* Boolean value determines whether popup menu should be anchored
* to right corner of parent view - default value is `false`
* @platform Android
*/
isAnchoredToRight?: boolean;
/**
* Determines if menu should open after long press or on normal press
*
* @default false
*/
shouldOpenOnLongPress?: boolean;
/**
* Overrides theme variant of menu to light mode, dark mode or system theme
* @default system
*/
themeVariant?: MenuThemeVariant;
/**
* Overrides UI kit of menu to auto, material3 or appcompat
* @platform Android
* @default auto
*/
uiKit?: MenuUiKit;
/**
* Custom OpenSpace hitSlop prop. Works like touchable hitslop.
* @platform iOS
*/
hitSlop?: {
top: number;
bottom: number;
left: number;
right: number;
};
/**
* Test ID for testing purposes
*/
testID?: string;
};
export type MenuComponentProps =
React.PropsWithChildren<MenuComponentPropsBase>;
export type MenuComponentRef = {
show: () => void;
};
export type ProcessedMenuAction = Omit<
MenuAction,
"imageColor" | "titleColor" | "subactions"
> & {
imageColor: ReturnType<typeof processColor>;
titleColor: ReturnType<typeof processColor>;
subactions?: ProcessedMenuAction[];
};
export type NativeMenuComponentProps = {
style?: StyleProp<ViewStyle>;
onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;
onCloseMenu?: () => void;
onOpenMenu?: () => void;
actions: ProcessedMenuAction[];
actionsHash: string;
title?: string;
hitSlop?: MenuComponentProps["hitSlop"];
testID?: string;
ref?: React.ForwardedRef<MenuComponentRef>;
};