@momo-kits/foundation 0.168.1-rn862.1 → 0.169.2
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/Application/BottomSheet.hooks.ts +195 -0
- package/Application/BottomSheet.parts.tsx +147 -0
- package/Application/BottomSheet.styles.ts +43 -0
- package/Application/BottomSheet.tsx +76 -279
- package/Application/BottomTab/ActiveIndicator.tsx +90 -0
- package/Application/BottomTab/BottomTabBar.styles.ts +65 -0
- package/Application/BottomTab/BottomTabBar.tsx +229 -276
- package/Application/BottomTab/BottomTabInset.tsx +14 -0
- package/Application/BottomTab/CurvedContainer.tsx +153 -0
- package/Application/BottomTab/CustomBottomTabItem.tsx +132 -108
- package/Application/BottomTab/DuoBarCompression.tsx +4 -12
- package/Application/BottomTab/DuoRailTabBar.tsx +227 -0
- package/Application/BottomTab/DuoTabBar.styles.ts +81 -0
- package/Application/BottomTab/DuoTabBar.tsx +29 -495
- package/Application/BottomTab/TabBarIcon.tsx +160 -72
- package/Application/BottomTab/TabScreen.tsx +164 -0
- package/Application/BottomTab/index.tsx +84 -351
- package/Application/BottomTab/metrics.ts +164 -0
- package/Application/BottomTab/tabItems.ts +46 -0
- package/Application/BottomTab/usePressLift.ts +32 -0
- package/Application/Components/DuoGlassBackground.tsx +7 -9
- package/Application/Components/HeaderAnimated.tsx +1 -1
- package/Application/Components/HeaderBackground.tsx +1 -1
- package/Application/Components/HeaderExtendHeader.tsx +17 -11
- package/Application/Components/HeaderRight.styles.ts +144 -0
- package/Application/Components/HeaderRight.tsx +6 -528
- package/Application/Components/HeaderTitle.shared.ts +43 -0
- package/Application/Components/HeaderTitle.styles.ts +125 -0
- package/Application/Components/HeaderTitle.tsx +12 -576
- package/Application/Components/HeaderToolkitAction.tsx +208 -0
- package/Application/Components/NavigationButton.tsx +9 -6
- package/Application/Components/SearchHeader.tsx +1 -1
- package/Application/Components/SwipeBackHaptic.tsx +95 -0
- package/Application/Components/TitleJourney.tsx +110 -0
- package/Application/Components/TitleLocation.tsx +73 -0
- package/Application/Components/TitleUser.tsx +304 -0
- package/Application/Components/useToolkitActions.tsx +233 -0
- package/Application/ModalIconButton.tsx +66 -0
- package/Application/ModalScreen.tsx +39 -18
- package/Application/Navigation.ts +1 -1
- package/Application/NavigationContainer.tsx +7 -8
- package/Application/StackScreen.tracking.ts +158 -0
- package/Application/StackScreen.tsx +10 -137
- package/Application/WidgetContainer.tsx +10 -3
- package/Application/__tests__/modalLayout.test.ts +128 -0
- package/Application/hooks.ts +137 -0
- package/Application/index.ts +13 -1
- package/Application/modalLayout.ts +177 -0
- package/Application/navigationOptions.tsx +217 -0
- package/Application/types.header.ts +116 -0
- package/Application/types.tabs.ts +48 -0
- package/Application/types.theme.ts +87 -0
- package/Application/types.ts +12 -244
- package/Application/utils.ts +107 -0
- package/Badge/BadgeRibbon.tsx +3 -3
- package/Badge/styles.ts +2 -0
- package/Button/index.tsx +16 -136
- package/Button/styles.ts +1 -1
- package/Button/utils.ts +139 -0
- package/CheckBox/index.tsx +1 -6
- package/Divider/DashDivider.tsx +10 -11
- package/Divider/index.tsx +18 -8
- package/Image/index.tsx +1 -46
- package/Input/Input.tsx +7 -8
- package/Input/InputDropDown.tsx +3 -4
- package/Input/InputMoney.tsx +38 -164
- package/Input/InputMoneyView.tsx +187 -0
- package/Input/InputOTP.tsx +1 -1
- package/Input/InputPhoneNumber.tsx +5 -1
- package/Input/InputSearch.tsx +2 -108
- package/Input/InputTextArea.tsx +1 -5
- package/Input/SearchTextTyping.tsx +104 -0
- package/Input/common.tsx +4 -4
- package/Input/moneyUtils.ts +17 -0
- package/Input/styles.ts +26 -2
- package/Layout/FloatingButton.tsx +22 -21
- package/Layout/ReservedRegions.tsx +21 -4
- package/Layout/Screen.tsx +74 -670
- package/Layout/Section.tsx +1 -2
- package/Layout/index.ts +10 -4
- package/Layout/layoutMetrics.ts +58 -0
- package/Layout/layoutTypes.ts +86 -0
- package/Layout/screenContent.tsx +90 -0
- package/Layout/screenFooter.tsx +53 -0
- package/Layout/screenHeader.tsx +315 -0
- package/Layout/screenQuickReturn.tsx +67 -0
- package/Layout/screenScroll.ts +110 -0
- package/Layout/screenTypes.ts +134 -0
- package/Layout/styles.ts +2 -0
- package/Layout/utils.ts +10 -144
- package/Loader/DotLoader.tsx +7 -3
- package/Loader/ProgressBar.tsx +2 -6
- package/Loader/Spinner.tsx +7 -3
- package/Loader/styles.ts +4 -0
- package/Popup/PopupNotify.tsx +70 -64
- package/Popup/PopupPromotion.tsx +5 -4
- package/Popup/types.ts +7 -0
- package/Popup/utils.ts +46 -24
- package/Radio/index.tsx +2 -10
- package/Radio/styles.ts +6 -0
- package/Skeleton/index.tsx +1 -9
- package/Skeleton/styles.ts +1 -0
- package/Tag/index.tsx +3 -3
- package/Text/index.tsx +11 -2
- package/Title/index.tsx +2 -9
- package/Title/styles.ts +6 -0
- package/package.json +21 -22
- package/Application/device.ts +0 -29
- package/Application/utils.tsx +0 -497
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { TouchableOpacity, View } from 'react-native';
|
|
3
|
+
import { ApplicationContext } from '../../Context';
|
|
4
|
+
import { Text } from '../../Text';
|
|
5
|
+
import { Colors, Spacing, Styles } from '../../Consts';
|
|
6
|
+
import { TitleUserProps } from '../types';
|
|
7
|
+
import { Image } from '../../Image';
|
|
8
|
+
import { Skeleton } from '../../Skeleton';
|
|
9
|
+
import { styles } from './HeaderTitle.styles';
|
|
10
|
+
import { useHeaderFontFamily, useTitleMaxWidth } from './HeaderTitle.shared';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Header user title
|
|
14
|
+
* @constructor
|
|
15
|
+
*/
|
|
16
|
+
const TitleUser: React.FC<TitleUserProps> = ({
|
|
17
|
+
title,
|
|
18
|
+
subTitle,
|
|
19
|
+
image: image,
|
|
20
|
+
tintColor,
|
|
21
|
+
dotColor,
|
|
22
|
+
onPress,
|
|
23
|
+
verify,
|
|
24
|
+
icons,
|
|
25
|
+
isLoading,
|
|
26
|
+
}) => {
|
|
27
|
+
const { theme } = useContext(ApplicationContext);
|
|
28
|
+
const headerFontFamily = useHeaderFontFamily();
|
|
29
|
+
const maxWidth = useTitleMaxWidth();
|
|
30
|
+
const getShortName = (name: string) => {
|
|
31
|
+
const words = name.split(' ');
|
|
32
|
+
const lastTwoWords = words.slice(-2);
|
|
33
|
+
return lastTwoWords.map(word => word.charAt(0).toUpperCase()).join('');
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const renderImage = () => {
|
|
37
|
+
const avatarWidth = Spacing.XXL;
|
|
38
|
+
if (Array.isArray(image) && image.length > 0) {
|
|
39
|
+
switch (image.length) {
|
|
40
|
+
case 1: {
|
|
41
|
+
return image.map((i: string) => (
|
|
42
|
+
<Image
|
|
43
|
+
key={`avatar-${i}`}
|
|
44
|
+
source={{ uri: i }}
|
|
45
|
+
style={styles.circle}
|
|
46
|
+
/>
|
|
47
|
+
));
|
|
48
|
+
}
|
|
49
|
+
case 2: {
|
|
50
|
+
return (
|
|
51
|
+
<View style={[Styles.flex, styles.groupAvtContainer]}>
|
|
52
|
+
<Image
|
|
53
|
+
source={{ uri: image[0] }}
|
|
54
|
+
style={[
|
|
55
|
+
styles.circleMedium,
|
|
56
|
+
styles.avatarEdgeTopRight,
|
|
57
|
+
styles.layer0,
|
|
58
|
+
]}
|
|
59
|
+
/>
|
|
60
|
+
<Image
|
|
61
|
+
source={{ uri: image[1] }}
|
|
62
|
+
style={[
|
|
63
|
+
styles.circleMedium,
|
|
64
|
+
styles.avatarEdgeBottomLeft,
|
|
65
|
+
styles.layer1,
|
|
66
|
+
]}
|
|
67
|
+
/>
|
|
68
|
+
</View>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
case 3: {
|
|
72
|
+
return (
|
|
73
|
+
<View style={[Styles.flex, styles.groupAvtContainer]}>
|
|
74
|
+
<Image
|
|
75
|
+
source={{ uri: image[0] }}
|
|
76
|
+
style={[
|
|
77
|
+
styles.circleSmall,
|
|
78
|
+
styles.avatarBottomRight,
|
|
79
|
+
styles.layer0,
|
|
80
|
+
]}
|
|
81
|
+
/>
|
|
82
|
+
<Image
|
|
83
|
+
source={{ uri: image[1] }}
|
|
84
|
+
style={[
|
|
85
|
+
styles.circleSmall,
|
|
86
|
+
styles.avatarTop,
|
|
87
|
+
{ left: avatarWidth / 2 - 16 / 2 },
|
|
88
|
+
styles.layer1,
|
|
89
|
+
]}
|
|
90
|
+
/>
|
|
91
|
+
<Image
|
|
92
|
+
source={{ uri: image[2] }}
|
|
93
|
+
style={[
|
|
94
|
+
styles.circleSmall,
|
|
95
|
+
styles.avatarBottomLeft,
|
|
96
|
+
styles.layer2,
|
|
97
|
+
]}
|
|
98
|
+
/>
|
|
99
|
+
</View>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
case 4: {
|
|
103
|
+
return (
|
|
104
|
+
<View style={[Styles.flex, styles.groupAvtContainer]}>
|
|
105
|
+
<Image
|
|
106
|
+
source={{ uri: image[0] }}
|
|
107
|
+
style={[
|
|
108
|
+
styles.circleSmall,
|
|
109
|
+
styles.avatarBottomLeft,
|
|
110
|
+
styles.layer0,
|
|
111
|
+
]}
|
|
112
|
+
/>
|
|
113
|
+
<Image
|
|
114
|
+
source={{ uri: image[1] }}
|
|
115
|
+
style={[
|
|
116
|
+
styles.circleSmall,
|
|
117
|
+
styles.avatarBottomRight,
|
|
118
|
+
styles.layer1,
|
|
119
|
+
]}
|
|
120
|
+
/>
|
|
121
|
+
<Image
|
|
122
|
+
source={{ uri: image[2] }}
|
|
123
|
+
style={[
|
|
124
|
+
styles.circleSmall,
|
|
125
|
+
styles.avatarTopRight,
|
|
126
|
+
styles.layer2,
|
|
127
|
+
]}
|
|
128
|
+
/>
|
|
129
|
+
<Image
|
|
130
|
+
source={{ uri: image[2] }}
|
|
131
|
+
style={[
|
|
132
|
+
styles.circleSmall,
|
|
133
|
+
styles.avatarTopLeft,
|
|
134
|
+
styles.layer3,
|
|
135
|
+
]}
|
|
136
|
+
/>
|
|
137
|
+
</View>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
default: {
|
|
141
|
+
return (
|
|
142
|
+
<View style={[Styles.flex, styles.groupAvtContainer]}>
|
|
143
|
+
<Image
|
|
144
|
+
source={{ uri: image[0] }}
|
|
145
|
+
style={[
|
|
146
|
+
styles.circleSmall,
|
|
147
|
+
styles.avatarBottomLeft,
|
|
148
|
+
styles.layer0,
|
|
149
|
+
]}
|
|
150
|
+
/>
|
|
151
|
+
<Image
|
|
152
|
+
source={{ uri: image[1] }}
|
|
153
|
+
style={[
|
|
154
|
+
styles.circleSmall,
|
|
155
|
+
styles.avatarTopRight,
|
|
156
|
+
styles.layer2,
|
|
157
|
+
]}
|
|
158
|
+
/>
|
|
159
|
+
<Image
|
|
160
|
+
source={{ uri: image[2] }}
|
|
161
|
+
style={[
|
|
162
|
+
styles.circleSmall,
|
|
163
|
+
styles.avatarTopLeft,
|
|
164
|
+
styles.layer3,
|
|
165
|
+
]}
|
|
166
|
+
/>
|
|
167
|
+
<View
|
|
168
|
+
style={[
|
|
169
|
+
styles.circleSmall,
|
|
170
|
+
styles.avatarBottomRight,
|
|
171
|
+
styles.layer1,
|
|
172
|
+
styles.avatarMore,
|
|
173
|
+
]}
|
|
174
|
+
>
|
|
175
|
+
<Text
|
|
176
|
+
color={Colors.pink_03}
|
|
177
|
+
typography={'description_xs_regular'}
|
|
178
|
+
>
|
|
179
|
+
{`+${image.length - 3}`}
|
|
180
|
+
</Text>
|
|
181
|
+
</View>
|
|
182
|
+
</View>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (typeof image === 'string' && image) {
|
|
189
|
+
return <Image source={{ uri: image }} style={styles.circle} />;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<View
|
|
194
|
+
style={[
|
|
195
|
+
styles.imageContainer,
|
|
196
|
+
{ borderColor: theme.colors.border.default },
|
|
197
|
+
]}
|
|
198
|
+
>
|
|
199
|
+
<Text color={Colors.pink_03} typography={'description_xs_regular'}>
|
|
200
|
+
{getShortName(title)}
|
|
201
|
+
</Text>
|
|
202
|
+
</View>
|
|
203
|
+
);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const renderVerifyIcon = () => {
|
|
207
|
+
if (icons && icons.length > 0) {
|
|
208
|
+
return (
|
|
209
|
+
<View style={[Styles.row]}>
|
|
210
|
+
{icons.map(icon => (
|
|
211
|
+
<Image
|
|
212
|
+
key={`verified-icon-${icon}`}
|
|
213
|
+
source={{
|
|
214
|
+
uri: icon,
|
|
215
|
+
}}
|
|
216
|
+
style={styles.verifiedIcon}
|
|
217
|
+
/>
|
|
218
|
+
))}
|
|
219
|
+
</View>
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const renderShimmer = () => {
|
|
225
|
+
return (
|
|
226
|
+
<View style={Styles.row}>
|
|
227
|
+
<View
|
|
228
|
+
style={[
|
|
229
|
+
styles.imageContainer,
|
|
230
|
+
{
|
|
231
|
+
borderColor: theme.colors.border.default,
|
|
232
|
+
marginRight: Spacing.M / 2,
|
|
233
|
+
},
|
|
234
|
+
]}
|
|
235
|
+
>
|
|
236
|
+
<Skeleton />
|
|
237
|
+
</View>
|
|
238
|
+
<View style={Styles.flex}>
|
|
239
|
+
<View style={styles.shimmerTitle}>
|
|
240
|
+
<Skeleton />
|
|
241
|
+
</View>
|
|
242
|
+
<View style={{ height: Spacing.XXS }} />
|
|
243
|
+
<View style={styles.shimmerDescription}>
|
|
244
|
+
<Skeleton />
|
|
245
|
+
</View>
|
|
246
|
+
</View>
|
|
247
|
+
</View>
|
|
248
|
+
);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
if (verify) {
|
|
252
|
+
console.warn(`Warning: The verify value "${verify}" is deprecated.`);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (isLoading) {
|
|
256
|
+
return renderShimmer();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return (
|
|
260
|
+
<TouchableOpacity
|
|
261
|
+
style={[
|
|
262
|
+
styles.centerContent,
|
|
263
|
+
{ maxWidth: maxWidth - (icons?.length ?? 0) * 16 },
|
|
264
|
+
]}
|
|
265
|
+
onPress={onPress}
|
|
266
|
+
disabled={onPress === undefined}
|
|
267
|
+
>
|
|
268
|
+
<View
|
|
269
|
+
style={[Styles.row, { maxWidth: maxWidth - (icons?.length ?? 0) * 16 }]}
|
|
270
|
+
>
|
|
271
|
+
<View>
|
|
272
|
+
{renderImage()}
|
|
273
|
+
{!!dotColor && (
|
|
274
|
+
<View style={[styles.dotAvatar, { backgroundColor: dotColor }]} />
|
|
275
|
+
)}
|
|
276
|
+
</View>
|
|
277
|
+
<View style={styles.titleInfo}>
|
|
278
|
+
<View style={Styles.row}>
|
|
279
|
+
<Text
|
|
280
|
+
typography="action_xs_bold"
|
|
281
|
+
fontFamily={headerFontFamily}
|
|
282
|
+
color={tintColor}
|
|
283
|
+
numberOfLines={1}
|
|
284
|
+
>
|
|
285
|
+
{title}
|
|
286
|
+
</Text>
|
|
287
|
+
{renderVerifyIcon()}
|
|
288
|
+
</View>
|
|
289
|
+
{!!subTitle && (
|
|
290
|
+
<Text
|
|
291
|
+
typography="description_xs_regular"
|
|
292
|
+
color={tintColor}
|
|
293
|
+
numberOfLines={1}
|
|
294
|
+
>
|
|
295
|
+
{subTitle}
|
|
296
|
+
</Text>
|
|
297
|
+
)}
|
|
298
|
+
</View>
|
|
299
|
+
</View>
|
|
300
|
+
</TouchableOpacity>
|
|
301
|
+
);
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
export { TitleUser };
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { useCallback, useContext, useEffect, useState } from 'react';
|
|
2
|
+
import { ApplicationContext, MiniAppContext } from '../../Context';
|
|
3
|
+
import { PopupNotify } from '../../Popup';
|
|
4
|
+
import { Tool, ToolGroup } from '../types';
|
|
5
|
+
|
|
6
|
+
const DID_SYNC_NEW_HOME = 'did_sync_new_home';
|
|
7
|
+
|
|
8
|
+
type ToolkitActionsParams = {
|
|
9
|
+
preventClose?: any;
|
|
10
|
+
useSystemTools: boolean;
|
|
11
|
+
useShortcut: boolean;
|
|
12
|
+
useMore: boolean;
|
|
13
|
+
tools: any[];
|
|
14
|
+
useCloseIcon: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* state and handlers behind the header toolkit buttons
|
|
19
|
+
*/
|
|
20
|
+
const useToolkitActions = ({
|
|
21
|
+
preventClose,
|
|
22
|
+
useSystemTools,
|
|
23
|
+
useShortcut,
|
|
24
|
+
useMore,
|
|
25
|
+
tools,
|
|
26
|
+
useCloseIcon,
|
|
27
|
+
}: ToolkitActionsParams) => {
|
|
28
|
+
const { navigator } = useContext(ApplicationContext);
|
|
29
|
+
const context = useContext<any>(MiniAppContext);
|
|
30
|
+
|
|
31
|
+
const [isFavorite, setIsFavorite] = useState<boolean>(false);
|
|
32
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* check app is favorite
|
|
36
|
+
*/
|
|
37
|
+
const checkAppIsFavorite = useCallback(
|
|
38
|
+
() =>
|
|
39
|
+
navigator?.maxApi?.dispatchFunction?.(
|
|
40
|
+
'isFavoriteApp',
|
|
41
|
+
{ code: context?.code },
|
|
42
|
+
(result: boolean) => {
|
|
43
|
+
setIsFavorite(result);
|
|
44
|
+
},
|
|
45
|
+
),
|
|
46
|
+
[context?.code, navigator?.maxApi],
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (useShortcut) {
|
|
51
|
+
checkAppIsFavorite();
|
|
52
|
+
|
|
53
|
+
const favoriteObserver = navigator?.maxApi?.observer?.(
|
|
54
|
+
DID_SYNC_NEW_HOME,
|
|
55
|
+
(updatedData: any) => {
|
|
56
|
+
const status = updatedData?.items?.includes(context?.code);
|
|
57
|
+
setIsFavorite(status);
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
return () => {
|
|
61
|
+
favoriteObserver?.remove?.();
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}, [useShortcut, context, checkAppIsFavorite, navigator?.maxApi]);
|
|
65
|
+
|
|
66
|
+
const onDismiss = () => {
|
|
67
|
+
if (useCloseIcon) {
|
|
68
|
+
navigator?.maxApi?.dispatchFunction?.(
|
|
69
|
+
'dismiss',
|
|
70
|
+
navigator?.dismissData,
|
|
71
|
+
undefined,
|
|
72
|
+
);
|
|
73
|
+
} else {
|
|
74
|
+
navigator?.maxApi?.dispatchFunction?.('dismissAll');
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* close navigation container
|
|
80
|
+
*/
|
|
81
|
+
const onClose = () => {
|
|
82
|
+
const currentRoute = navigator?.ref?.current?.getCurrentRoute?.();
|
|
83
|
+
context?.autoTracking?.({
|
|
84
|
+
...context,
|
|
85
|
+
componentName: 'IconButton',
|
|
86
|
+
componentId: 'navigation_close',
|
|
87
|
+
screenName: currentRoute?.params?.screen?.name ?? currentRoute?.name,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
if (preventClose) {
|
|
91
|
+
navigator?.showModal({
|
|
92
|
+
screen: () => (
|
|
93
|
+
<PopupNotify
|
|
94
|
+
{...preventClose}
|
|
95
|
+
primary={{
|
|
96
|
+
title: preventClose.primary.title,
|
|
97
|
+
onPress: () => {
|
|
98
|
+
preventClose?.primary.onPress();
|
|
99
|
+
onDismiss();
|
|
100
|
+
},
|
|
101
|
+
}}
|
|
102
|
+
/>
|
|
103
|
+
),
|
|
104
|
+
});
|
|
105
|
+
} else {
|
|
106
|
+
onDismiss();
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* on press shortcut
|
|
112
|
+
*/
|
|
113
|
+
const onPressShortcut = () => {
|
|
114
|
+
const currentRoute = navigator?.ref?.current?.getCurrentRoute?.();
|
|
115
|
+
const expected = !isFavorite;
|
|
116
|
+
context?.autoTracking?.({
|
|
117
|
+
...context,
|
|
118
|
+
componentName: 'IconButton',
|
|
119
|
+
componentId: `${expected ? 'pin' : 'unpin'}_shortcut`,
|
|
120
|
+
screenName: currentRoute?.params?.screen?.name ?? currentRoute?.name,
|
|
121
|
+
});
|
|
122
|
+
setIsLoading(true);
|
|
123
|
+
navigator?.maxApi?.dispatchFunction?.(
|
|
124
|
+
'onToolAction',
|
|
125
|
+
{
|
|
126
|
+
item: {
|
|
127
|
+
key: 'onFavorite',
|
|
128
|
+
},
|
|
129
|
+
context,
|
|
130
|
+
},
|
|
131
|
+
({ success }: { success: boolean }) => {
|
|
132
|
+
if (success) {
|
|
133
|
+
setIsFavorite(expected);
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
);
|
|
137
|
+
setTimeout(() => {
|
|
138
|
+
setIsLoading(false);
|
|
139
|
+
}, 1000);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* on press help center
|
|
144
|
+
*/
|
|
145
|
+
const onPressHelpCenter = () => {
|
|
146
|
+
const currentRoute = navigator?.ref?.current?.getCurrentRoute?.();
|
|
147
|
+
context?.autoTracking?.({
|
|
148
|
+
...context,
|
|
149
|
+
componentName: 'IconButton',
|
|
150
|
+
componentId: 'navigation_helpcenter',
|
|
151
|
+
screenName: currentRoute?.params?.screen?.name ?? currentRoute?.name,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
navigator?.maxApi?.dispatchFunction?.('showHelpCenter', context);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* on press icon more
|
|
159
|
+
*/
|
|
160
|
+
const onPressIconMore = () => {
|
|
161
|
+
const currentRoute = navigator?.ref?.current?.getCurrentRoute?.();
|
|
162
|
+
context?.autoTracking?.({
|
|
163
|
+
...context,
|
|
164
|
+
componentName: 'IconButton',
|
|
165
|
+
componentId: 'navigation_more',
|
|
166
|
+
screenName: currentRoute?.params?.screen?.name ?? currentRoute?.name,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
navigator?.maxApi?.dispatchFunction?.(
|
|
170
|
+
'showTools',
|
|
171
|
+
{
|
|
172
|
+
useSystemTools,
|
|
173
|
+
tools,
|
|
174
|
+
context,
|
|
175
|
+
},
|
|
176
|
+
(key: string) => {
|
|
177
|
+
for (const group of tools) {
|
|
178
|
+
const pressedTool = group?.items?.find?.(
|
|
179
|
+
(tool: Tool) => tool?.key === key,
|
|
180
|
+
);
|
|
181
|
+
if (pressedTool) {
|
|
182
|
+
pressedTool?.onPress();
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
let iconShortcut = isFavorite ? 'pin_star_checked' : 'pin_star';
|
|
191
|
+
let shortcutOnPress = onPressShortcut;
|
|
192
|
+
const totalTools = tools.reduce(
|
|
193
|
+
(count: number, group: ToolGroup) => count + group?.items?.length,
|
|
194
|
+
0,
|
|
195
|
+
);
|
|
196
|
+
const showIconMore = tools && totalTools > 1;
|
|
197
|
+
const isHaveOneTool = tools && totalTools === 1;
|
|
198
|
+
|
|
199
|
+
if (showIconMore || useMore) {
|
|
200
|
+
iconShortcut = 'navigation_more_icon';
|
|
201
|
+
shortcutOnPress = onPressIconMore;
|
|
202
|
+
} else if (isHaveOneTool) {
|
|
203
|
+
const singleTool = tools.find(
|
|
204
|
+
(group: ToolGroup) => group?.items?.length === 1,
|
|
205
|
+
)?.items[0];
|
|
206
|
+
iconShortcut = singleTool?.icon;
|
|
207
|
+
shortcutOnPress = () => {
|
|
208
|
+
singleTool?.onPress?.();
|
|
209
|
+
const currentRoute = navigator?.ref?.current?.getCurrentRoute?.();
|
|
210
|
+
context?.autoTracking?.({
|
|
211
|
+
...context,
|
|
212
|
+
componentName: 'IconButton',
|
|
213
|
+
componentId: 'navigation_shortcut',
|
|
214
|
+
screenName: currentRoute?.params?.screen?.name ?? currentRoute?.name,
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const showBadge = tools.some((group: ToolGroup) =>
|
|
220
|
+
group?.items?.some?.(tool => tool?.showBadge),
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
return {
|
|
224
|
+
isLoading,
|
|
225
|
+
iconShortcut,
|
|
226
|
+
shortcutOnPress,
|
|
227
|
+
showBadge,
|
|
228
|
+
onPressHelpCenter,
|
|
229
|
+
onClose,
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
export { useToolkitActions };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
StyleProp,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
TouchableOpacity,
|
|
6
|
+
ViewStyle,
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
import { ApplicationContext } from '../Context';
|
|
9
|
+
import { Radius, Spacing } from '../Consts';
|
|
10
|
+
import { Icon } from '../Icon';
|
|
11
|
+
|
|
12
|
+
// modal spec: icon button 32, icon 20, shared with the Compose / SwiftUI kits
|
|
13
|
+
const MODAL_ICON_BUTTON_SIZE = Spacing.XXL;
|
|
14
|
+
const MODAL_ICON_SIZE = 20;
|
|
15
|
+
|
|
16
|
+
type ModalIconButtonProps = {
|
|
17
|
+
icon: string;
|
|
18
|
+
onPress: () => void;
|
|
19
|
+
accessibilityLabel?: string;
|
|
20
|
+
style?: StyleProp<ViewStyle>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Close / back button of popups and bottom sheet headers
|
|
25
|
+
*/
|
|
26
|
+
const ModalIconButton: React.FC<ModalIconButtonProps> = ({
|
|
27
|
+
icon,
|
|
28
|
+
onPress,
|
|
29
|
+
accessibilityLabel,
|
|
30
|
+
style,
|
|
31
|
+
}) => {
|
|
32
|
+
const { theme } = useContext(ApplicationContext);
|
|
33
|
+
return (
|
|
34
|
+
<TouchableOpacity
|
|
35
|
+
accessibilityLabel={accessibilityLabel}
|
|
36
|
+
onPress={onPress}
|
|
37
|
+
style={[
|
|
38
|
+
styles.button,
|
|
39
|
+
{
|
|
40
|
+
backgroundColor: theme.colors.background.surface,
|
|
41
|
+
borderColor: theme.colors.border.default,
|
|
42
|
+
},
|
|
43
|
+
style,
|
|
44
|
+
]}
|
|
45
|
+
>
|
|
46
|
+
<Icon
|
|
47
|
+
source={icon}
|
|
48
|
+
color={theme.colors.text.default}
|
|
49
|
+
size={MODAL_ICON_SIZE}
|
|
50
|
+
/>
|
|
51
|
+
</TouchableOpacity>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const styles = StyleSheet.create({
|
|
56
|
+
button: {
|
|
57
|
+
width: MODAL_ICON_BUTTON_SIZE,
|
|
58
|
+
height: MODAL_ICON_BUTTON_SIZE,
|
|
59
|
+
borderRadius: Radius.L,
|
|
60
|
+
borderWidth: 1,
|
|
61
|
+
alignItems: 'center',
|
|
62
|
+
justifyContent: 'center',
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
export { ModalIconButton, MODAL_ICON_BUTTON_SIZE };
|