@momo-kits/foundation 0.74.2-react-native.1
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/BottomTab.tsx +120 -0
- package/Application/Components.tsx +534 -0
- package/Application/ModalScreen.tsx +268 -0
- package/Application/Navigation.ts +50 -0
- package/Application/NavigationContainer.tsx +120 -0
- package/Application/Navigator.ts +131 -0
- package/Application/StackScreen.tsx +71 -0
- package/Application/index.ts +41 -0
- package/Application/types.ts +216 -0
- package/Application/utils.tsx +151 -0
- package/Assets/DotAnimation.json +256 -0
- package/Assets/SpinnerAnimation.json +1027 -0
- package/Assets/icon.json +4031 -0
- package/Assets/icon_bank.json +506 -0
- package/Assets/language.json +202 -0
- package/Badge/Badge.tsx +56 -0
- package/Badge/BadgeDot.tsx +11 -0
- package/Badge/BadgeRibbon.tsx +125 -0
- package/Badge/Shape.tsx +29 -0
- package/Badge/index.tsx +7 -0
- package/Badge/styles.ts +58 -0
- package/Badge/types.ts +63 -0
- package/Button/index.tsx +310 -0
- package/Button/styles.ts +60 -0
- package/CheckBox/index.tsx +65 -0
- package/CheckBox/styles.ts +15 -0
- package/CheckBox/types.ts +38 -0
- package/Consts/colors+spacing+radius.ts +218 -0
- package/Consts/index.ts +4 -0
- package/Consts/styles.ts +52 -0
- package/Consts/theme.ts +125 -0
- package/Divider/index.tsx +21 -0
- package/Icon/index.tsx +41 -0
- package/Icon/types.ts +27 -0
- package/IconButton/index.tsx +139 -0
- package/IconButton/styles.ts +19 -0
- package/Image/index.tsx +83 -0
- package/Image/styles.ts +5 -0
- package/Image/types.ts +5 -0
- package/Input/Input.tsx +192 -0
- package/Input/InputDropDown.tsx +114 -0
- package/Input/InputMoney.tsx +163 -0
- package/Input/InputOTP.tsx +235 -0
- package/Input/InputSearch.tsx +151 -0
- package/Input/InputTextArea.tsx +159 -0
- package/Input/common.tsx +129 -0
- package/Input/index.tsx +251 -0
- package/Input/styles.ts +160 -0
- package/Input/utils.ts +69 -0
- package/Layout/Card.tsx +180 -0
- package/Layout/GridSystem.tsx +136 -0
- package/Layout/Item.tsx +56 -0
- package/Layout/ItemList.tsx +55 -0
- package/Layout/ItemSectionList.tsx +39 -0
- package/Layout/Screen.tsx +355 -0
- package/Layout/Section.tsx +179 -0
- package/Layout/index.ts +29 -0
- package/Layout/styles.ts +97 -0
- package/Layout/types.ts +23 -0
- package/Layout/utils.ts +55 -0
- package/Loader/DotLoader.tsx +37 -0
- package/Loader/Loader.tsx +13 -0
- package/Loader/ProgressBar.tsx +44 -0
- package/Loader/Spinner.tsx +28 -0
- package/Loader/index.tsx +4 -0
- package/Loader/styles.ts +10 -0
- package/Loader/types.ts +35 -0
- package/Loader/utils.ts +25 -0
- package/Pagination/Dot.tsx +16 -0
- package/Pagination/PaginationDot.tsx +38 -0
- package/Pagination/PaginationNumber.tsx +24 -0
- package/Pagination/PaginationScroll.tsx +88 -0
- package/Pagination/PaginationWhiteDot.tsx +35 -0
- package/Pagination/index.tsx +25 -0
- package/Pagination/styles.ts +50 -0
- package/Pagination/types.ts +40 -0
- package/Popup/PopupNotify.tsx +266 -0
- package/Popup/PopupPromotion.tsx +120 -0
- package/Popup/index.tsx +4 -0
- package/Popup/types.ts +87 -0
- package/Radio/index.tsx +64 -0
- package/Radio/styles.ts +11 -0
- package/Radio/types.ts +38 -0
- package/Skeleton/index.tsx +72 -0
- package/Skeleton/styles.ts +5 -0
- package/Skeleton/types.ts +6 -0
- package/Switch/index.tsx +37 -0
- package/Switch/styles.ts +23 -0
- package/Switch/types.ts +26 -0
- package/Tag/index.tsx +79 -0
- package/Tag/styles.ts +24 -0
- package/Tag/types.ts +36 -0
- package/Text/index.tsx +110 -0
- package/Text/styles.ts +73 -0
- package/Text/types.ts +34 -0
- package/Text/utils.ts +14 -0
- package/Title/index.tsx +132 -0
- package/Title/styles.ts +52 -0
- package/Title/types.ts +52 -0
- package/code-scanner.js +51 -0
- package/index.ts +51 -0
- package/package.json +36 -0
- package/publish.sh +23 -0
- package/tsconfig.json +24 -0
- package/verify.js +44 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import React, {useContext, useEffect} from 'react';
|
|
2
|
+
import {Platform} from 'react-native';
|
|
3
|
+
import {BottomTabProps, NavigationScreenProps} from './types';
|
|
4
|
+
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
|
|
5
|
+
import {createStackNavigator} from '@react-navigation/stack';
|
|
6
|
+
import {useSafeAreaInsets} from 'react-native-safe-area-context';
|
|
7
|
+
import {NavigationContainer} from '@react-navigation/native';
|
|
8
|
+
import {Icon} from '../Icon';
|
|
9
|
+
import {Text} from '../Text';
|
|
10
|
+
import {ApplicationContext} from './index';
|
|
11
|
+
import {getStackOptions} from './utils';
|
|
12
|
+
import StackScreen from './StackScreen';
|
|
13
|
+
|
|
14
|
+
const Tab = createBottomTabNavigator();
|
|
15
|
+
const Stack = createStackNavigator();
|
|
16
|
+
|
|
17
|
+
const TabScreen: React.FC<NavigationScreenProps> = ({route}) => {
|
|
18
|
+
if (route.params?.nested) {
|
|
19
|
+
return (
|
|
20
|
+
<Stack.Navigator>
|
|
21
|
+
<Stack.Screen
|
|
22
|
+
name="Stack"
|
|
23
|
+
component={StackScreen}
|
|
24
|
+
initialParams={{screen: route.params?.screen}}
|
|
25
|
+
options={{...getStackOptions(), ...route.params?.options}}
|
|
26
|
+
/>
|
|
27
|
+
</Stack.Navigator>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return (
|
|
31
|
+
<NavigationContainer independent={true}>
|
|
32
|
+
<Stack.Navigator>
|
|
33
|
+
<Stack.Screen
|
|
34
|
+
name="Stack"
|
|
35
|
+
component={StackScreen}
|
|
36
|
+
initialParams={{screen: route.params?.screen}}
|
|
37
|
+
options={{...getStackOptions(), ...route.params?.options}}
|
|
38
|
+
/>
|
|
39
|
+
</Stack.Navigator>
|
|
40
|
+
</NavigationContainer>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
const BottomTab: React.FC<BottomTabProps> = ({
|
|
44
|
+
nested,
|
|
45
|
+
tabs,
|
|
46
|
+
listeners,
|
|
47
|
+
navigation,
|
|
48
|
+
initialRouteName,
|
|
49
|
+
}) => {
|
|
50
|
+
const {theme} = useContext(ApplicationContext);
|
|
51
|
+
const insets = useSafeAreaInsets();
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
navigation?.setOptions({
|
|
55
|
+
headerShown: false,
|
|
56
|
+
headerTransparent: true,
|
|
57
|
+
headerBackground: undefined,
|
|
58
|
+
});
|
|
59
|
+
}, []);
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<Tab.Navigator
|
|
63
|
+
initialRouteName={initialRouteName}
|
|
64
|
+
backBehavior={'firstRoute'}
|
|
65
|
+
screenOptions={{headerShown: false}}
|
|
66
|
+
tabBarOptions={{
|
|
67
|
+
style: {
|
|
68
|
+
height: 68 + Math.min(insets.bottom, 21),
|
|
69
|
+
borderWidth: 0,
|
|
70
|
+
},
|
|
71
|
+
tabStyle: {
|
|
72
|
+
height: 68,
|
|
73
|
+
paddingVertical: 8,
|
|
74
|
+
},
|
|
75
|
+
}}>
|
|
76
|
+
{tabs.map(item => {
|
|
77
|
+
return (
|
|
78
|
+
<Tab.Screen
|
|
79
|
+
key={item.name}
|
|
80
|
+
name={item.name}
|
|
81
|
+
component={TabScreen}
|
|
82
|
+
initialParams={{...item, nested}}
|
|
83
|
+
listeners={listeners}
|
|
84
|
+
options={{
|
|
85
|
+
tabBarLabel: ({color, focused}) => {
|
|
86
|
+
return (
|
|
87
|
+
<Text
|
|
88
|
+
numberOfLines={1}
|
|
89
|
+
typography={
|
|
90
|
+
focused ? 'label_xs_medium' : 'description_xs_regular'
|
|
91
|
+
}
|
|
92
|
+
color={color}>
|
|
93
|
+
{item.label}
|
|
94
|
+
</Text>
|
|
95
|
+
);
|
|
96
|
+
},
|
|
97
|
+
tabBarBadge: item?.badgeLabel,
|
|
98
|
+
tabBarBadgeStyle: {
|
|
99
|
+
borderColor: 'white',
|
|
100
|
+
borderWidth: 2,
|
|
101
|
+
fontSize: 10,
|
|
102
|
+
lineHeight: Platform.OS === 'android' ? 17 : 14,
|
|
103
|
+
fontWeight: 'bold',
|
|
104
|
+
alignSelf: 'center',
|
|
105
|
+
fontFamily: `${theme.font}-Bold`,
|
|
106
|
+
left: item?.showDot ? 8 : 4,
|
|
107
|
+
top: item?.showDot ? -2 : -6,
|
|
108
|
+
},
|
|
109
|
+
tabBarIcon: ({color}) => (
|
|
110
|
+
<Icon source={item.icon} color={color} size={28} />
|
|
111
|
+
),
|
|
112
|
+
}}
|
|
113
|
+
/>
|
|
114
|
+
);
|
|
115
|
+
})}
|
|
116
|
+
</Tab.Navigator>
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export default BottomTab;
|
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
Fragment,
|
|
3
|
+
useCallback,
|
|
4
|
+
useContext,
|
|
5
|
+
useEffect,
|
|
6
|
+
useState,
|
|
7
|
+
} from 'react';
|
|
8
|
+
import {
|
|
9
|
+
Animated,
|
|
10
|
+
BackHandler,
|
|
11
|
+
DeviceEventEmitter,
|
|
12
|
+
StatusBar,
|
|
13
|
+
StyleSheet,
|
|
14
|
+
TouchableOpacity,
|
|
15
|
+
View,
|
|
16
|
+
ViewStyle,
|
|
17
|
+
} from 'react-native';
|
|
18
|
+
import {ApplicationContext, MiniAppContext} from './index';
|
|
19
|
+
import {Colors, Radius, Spacing, Styles} from '../Consts';
|
|
20
|
+
import {Image} from '../Image';
|
|
21
|
+
import {
|
|
22
|
+
HeaderAnimatedProps,
|
|
23
|
+
HeaderBackgroundProps,
|
|
24
|
+
HeaderBackProps,
|
|
25
|
+
NavigationButtonProps,
|
|
26
|
+
TitleCustomProps,
|
|
27
|
+
} from './types';
|
|
28
|
+
import {scaleSize, Text} from '../Text';
|
|
29
|
+
import {Icon} from '../Icon';
|
|
30
|
+
import {PopupNotify} from '../Popup';
|
|
31
|
+
import {Badge, BadgeDot} from '../Badge';
|
|
32
|
+
|
|
33
|
+
const NavigationButton: React.FC<NavigationButtonProps> = ({
|
|
34
|
+
icon,
|
|
35
|
+
tintColor,
|
|
36
|
+
onPress,
|
|
37
|
+
useBorder = true,
|
|
38
|
+
badgeType,
|
|
39
|
+
badgeValue,
|
|
40
|
+
}) => {
|
|
41
|
+
const {theme} = useContext(ApplicationContext);
|
|
42
|
+
let buttonStyle: ViewStyle = {backgroundColor: '#00000066'};
|
|
43
|
+
if (tintColor != Colors.black_01) {
|
|
44
|
+
buttonStyle = {
|
|
45
|
+
backgroundColor: 'transparent',
|
|
46
|
+
borderColor: '#00000066',
|
|
47
|
+
borderWidth: useBorder ? 0.5 : 0,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const isNumber = (label: any) => {
|
|
52
|
+
const numberRegex = /^\d+$/;
|
|
53
|
+
return numberRegex.test(String(label));
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const renderBadge = useCallback(() => {
|
|
57
|
+
if (badgeType === 'dot') {
|
|
58
|
+
return <BadgeDot size="small" style={styles.badgeDot} />;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (isNumber(badgeValue)) {
|
|
62
|
+
return <Badge label={badgeValue} style={styles.badge} />;
|
|
63
|
+
}
|
|
64
|
+
}, [badgeType, badgeValue]);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<View style={{width: scaleSize(28)}}>
|
|
68
|
+
<TouchableOpacity
|
|
69
|
+
style={[styles.navigationButton, buttonStyle]}
|
|
70
|
+
onPress={onPress}>
|
|
71
|
+
<Icon
|
|
72
|
+
source={icon}
|
|
73
|
+
color={tintColor ?? theme.colors.text.default}
|
|
74
|
+
size={20}
|
|
75
|
+
/>
|
|
76
|
+
</TouchableOpacity>
|
|
77
|
+
{renderBadge()}
|
|
78
|
+
</View>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const HeaderTitle: React.FC<any> = props => {
|
|
83
|
+
const {theme} = useContext(ApplicationContext);
|
|
84
|
+
const opacity = props.animatedValue?.interpolate({
|
|
85
|
+
inputRange: [0, 200],
|
|
86
|
+
outputRange: [0, 1],
|
|
87
|
+
extrapolate: 'clamp',
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<Animated.Text
|
|
92
|
+
{...props}
|
|
93
|
+
style={[
|
|
94
|
+
styles.title,
|
|
95
|
+
{fontFamily: `${theme.font}-Bold`, opacity, color: props.tintColor},
|
|
96
|
+
]}
|
|
97
|
+
/>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const HeaderLeft: React.FC<HeaderBackProps> = ({
|
|
102
|
+
tintColor,
|
|
103
|
+
preventBack,
|
|
104
|
+
onPressLeftHeader,
|
|
105
|
+
useBorder,
|
|
106
|
+
}) => {
|
|
107
|
+
const context = useContext(MiniAppContext);
|
|
108
|
+
const {navigator} = useContext(ApplicationContext);
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
const backHandler = BackHandler.addEventListener(
|
|
112
|
+
'hardwareBackPress',
|
|
113
|
+
goBackSafe,
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
return () => backHandler.remove();
|
|
117
|
+
}, []);
|
|
118
|
+
|
|
119
|
+
const goBackSafe = () => {
|
|
120
|
+
const goBack = () => {
|
|
121
|
+
const canGoBack = navigator?.ref.current?.canGoBack();
|
|
122
|
+
if (!canGoBack) {
|
|
123
|
+
const currentRoute = navigator?.ref?.current.getCurrentRoute();
|
|
124
|
+
navigator?.maxApi?.trackEvent?.('service_icon_clicked', {
|
|
125
|
+
...context,
|
|
126
|
+
screen_name: currentRoute?.params?.screen?.name ?? currentRoute?.name,
|
|
127
|
+
trigger_id: '111154000000000000',
|
|
128
|
+
icon_name: 'back',
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (canGoBack) {
|
|
132
|
+
navigator?.ref.current?.goBack();
|
|
133
|
+
} else if (navigator?.maxApi) {
|
|
134
|
+
navigator?.maxApi?.dismiss(navigator.dismissData);
|
|
135
|
+
} else {
|
|
136
|
+
const currentTime = new Date().getTime();
|
|
137
|
+
const requestId = `navigationBackPress#${currentTime}`;
|
|
138
|
+
DeviceEventEmitter.emit('dismiss', {requestId});
|
|
139
|
+
}
|
|
140
|
+
onPressLeftHeader?.();
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
if (preventBack) {
|
|
144
|
+
navigator?.showModal({
|
|
145
|
+
screen: () => (
|
|
146
|
+
<PopupNotify
|
|
147
|
+
{...preventBack}
|
|
148
|
+
primary={{
|
|
149
|
+
title: preventBack.primary.title,
|
|
150
|
+
onPress: () => {
|
|
151
|
+
preventBack?.primary.onPress();
|
|
152
|
+
goBack();
|
|
153
|
+
},
|
|
154
|
+
}}
|
|
155
|
+
/>
|
|
156
|
+
),
|
|
157
|
+
});
|
|
158
|
+
} else {
|
|
159
|
+
goBack();
|
|
160
|
+
}
|
|
161
|
+
return true;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
return (
|
|
165
|
+
<View style={styles.headerLeft}>
|
|
166
|
+
<NavigationButton
|
|
167
|
+
icon="ic_back"
|
|
168
|
+
tintColor={tintColor}
|
|
169
|
+
onPress={goBackSafe}
|
|
170
|
+
useBorder={useBorder}
|
|
171
|
+
/>
|
|
172
|
+
</View>
|
|
173
|
+
);
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const HeaderBackground: React.FC<HeaderBackgroundProps> = ({
|
|
177
|
+
image,
|
|
178
|
+
backgroundColor,
|
|
179
|
+
animatedValue,
|
|
180
|
+
useBorder = false,
|
|
181
|
+
}) => {
|
|
182
|
+
const {theme} = useContext(ApplicationContext);
|
|
183
|
+
let headerImage = theme.assets?.headerBackground;
|
|
184
|
+
if (image === null) {
|
|
185
|
+
headerImage = undefined;
|
|
186
|
+
}
|
|
187
|
+
const opacity = animatedValue?.interpolate({
|
|
188
|
+
inputRange: [0, 114],
|
|
189
|
+
outputRange: [0, 1],
|
|
190
|
+
extrapolate: 'clamp',
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<Animated.View
|
|
195
|
+
style={[
|
|
196
|
+
Styles.flex,
|
|
197
|
+
{
|
|
198
|
+
backgroundColor: backgroundColor ?? theme.colors.background.default,
|
|
199
|
+
overflow: 'hidden',
|
|
200
|
+
borderBottomWidth: useBorder ? 1 : 0,
|
|
201
|
+
borderColor: theme.colors.border.default,
|
|
202
|
+
opacity,
|
|
203
|
+
},
|
|
204
|
+
]}>
|
|
205
|
+
<StatusBar
|
|
206
|
+
barStyle={headerImage || theme.dark ? 'light-content' : 'dark-content'}
|
|
207
|
+
translucent={true}
|
|
208
|
+
backgroundColor={'transparent'}
|
|
209
|
+
/>
|
|
210
|
+
{!!headerImage && (
|
|
211
|
+
<Image
|
|
212
|
+
style={styles.headerBackground}
|
|
213
|
+
source={{uri: headerImage}}
|
|
214
|
+
loading={false}
|
|
215
|
+
/>
|
|
216
|
+
)}
|
|
217
|
+
</Animated.View>
|
|
218
|
+
);
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const HeaderCustom: React.FC<TitleCustomProps> = ({
|
|
222
|
+
title,
|
|
223
|
+
subTitle,
|
|
224
|
+
image,
|
|
225
|
+
imageShape = 'circle',
|
|
226
|
+
content,
|
|
227
|
+
tintColor,
|
|
228
|
+
dotColor,
|
|
229
|
+
}) => {
|
|
230
|
+
const avatarStyle = imageShape == 'circle' ? styles.circle : styles.square;
|
|
231
|
+
const header = (
|
|
232
|
+
<View style={Styles.row}>
|
|
233
|
+
<View>
|
|
234
|
+
<Image source={{uri: image}} style={avatarStyle} />
|
|
235
|
+
{!!dotColor && (
|
|
236
|
+
<View style={[styles.dotAvatar, {backgroundColor: dotColor}]} />
|
|
237
|
+
)}
|
|
238
|
+
</View>
|
|
239
|
+
<View style={[Styles.flex, {paddingHorizontal: 8}]}>
|
|
240
|
+
<Text typography="header_default_bold" color={tintColor}>
|
|
241
|
+
{title}
|
|
242
|
+
</Text>
|
|
243
|
+
<Text typography="description_default_regular" color={tintColor}>
|
|
244
|
+
{subTitle}
|
|
245
|
+
</Text>
|
|
246
|
+
</View>
|
|
247
|
+
</View>
|
|
248
|
+
);
|
|
249
|
+
return <View style={styles.headerTitleContainer}>{content ?? header}</View>;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const HeaderRightAction: React.FC<any> = ({children, ...restProps}) => {
|
|
253
|
+
const validateType = (child: React.ReactElement) => {
|
|
254
|
+
const valid = child?.type === NavigationButton || child?.type == Fragment;
|
|
255
|
+
if (__DEV__ && !valid) {
|
|
256
|
+
console.warn(
|
|
257
|
+
'HeaderRightAction contains element type of NavigationButton, Please check again.',
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
return child;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const renderAction = () => {
|
|
264
|
+
if (Array.isArray(children)) {
|
|
265
|
+
return children.map((child, index) => {
|
|
266
|
+
return (
|
|
267
|
+
<View key={`HeaderRightAction ${index}`} style={styles.headerButton}>
|
|
268
|
+
{React.cloneElement(validateType(child), {...restProps})}
|
|
269
|
+
</View>
|
|
270
|
+
);
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return (
|
|
275
|
+
<View style={styles.headerButton}>
|
|
276
|
+
{React.cloneElement(validateType(children), {...restProps})}
|
|
277
|
+
</View>
|
|
278
|
+
);
|
|
279
|
+
};
|
|
280
|
+
return <View style={styles.headerRightButton}>{renderAction()}</View>;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const HeaderToolkitAction: React.FC<any> = ({
|
|
284
|
+
tintColor,
|
|
285
|
+
pinnedTool,
|
|
286
|
+
runtimeTools = [],
|
|
287
|
+
preventBack,
|
|
288
|
+
}) => {
|
|
289
|
+
const {theme, navigator} = useContext(ApplicationContext);
|
|
290
|
+
const [toolConfig, setToolConfig] = useState<any>();
|
|
291
|
+
const {onAction} = toolConfig ?? {};
|
|
292
|
+
|
|
293
|
+
let backgroundColor;
|
|
294
|
+
if (tintColor != Colors.black_01) {
|
|
295
|
+
backgroundColor = theme.colors.background.surface;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
useEffect(() => {
|
|
299
|
+
if (navigator?.toolkitConfig) {
|
|
300
|
+
setToolConfig(navigator?.toolkitConfig);
|
|
301
|
+
} else {
|
|
302
|
+
getToolkitConfig();
|
|
303
|
+
}
|
|
304
|
+
}, []);
|
|
305
|
+
|
|
306
|
+
const getToolkitConfig = () => {
|
|
307
|
+
navigator?.maxApi?.dispatchFunction?.(
|
|
308
|
+
'getToolsConfig',
|
|
309
|
+
[undefined],
|
|
310
|
+
(config: any) => {
|
|
311
|
+
navigator.toolkitConfig = config;
|
|
312
|
+
setToolConfig(navigator?.toolkitConfig);
|
|
313
|
+
},
|
|
314
|
+
);
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
const onMore = () => {
|
|
318
|
+
onAction?.('onMore');
|
|
319
|
+
navigator?.maxApi?.dispatchFunction?.(
|
|
320
|
+
'showTools',
|
|
321
|
+
{runtimeTools},
|
|
322
|
+
(res: {item: {action?: string; key: string}}) => {
|
|
323
|
+
const {item} = res;
|
|
324
|
+
navigator?.toolkitCallback?.(item);
|
|
325
|
+
getToolkitConfig();
|
|
326
|
+
},
|
|
327
|
+
);
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
const onClose = () => {
|
|
331
|
+
if (preventBack) {
|
|
332
|
+
navigator?.showModal({
|
|
333
|
+
screen: () => (
|
|
334
|
+
<PopupNotify
|
|
335
|
+
{...preventBack}
|
|
336
|
+
primary={{
|
|
337
|
+
title: preventBack.primary.title,
|
|
338
|
+
onPress: () => {
|
|
339
|
+
preventBack?.primary.onPress();
|
|
340
|
+
navigator?.maxApi?.dispatchFunction?.(
|
|
341
|
+
'dismiss',
|
|
342
|
+
undefined,
|
|
343
|
+
undefined,
|
|
344
|
+
);
|
|
345
|
+
},
|
|
346
|
+
}}
|
|
347
|
+
/>
|
|
348
|
+
),
|
|
349
|
+
});
|
|
350
|
+
} else {
|
|
351
|
+
navigator?.maxApi?.dispatchFunction?.('dismiss', undefined, undefined);
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
const renderPinnedTool = () => {
|
|
356
|
+
const pinKey = pinnedTool?.key || toolConfig?.pinnedTool?.key;
|
|
357
|
+
const pinTool = toolConfig?.tools?.find((i: any) => i.key === pinKey);
|
|
358
|
+
const {badgeValue, badgeType} = pinnedTool ?? {};
|
|
359
|
+
|
|
360
|
+
if (pinTool)
|
|
361
|
+
return (
|
|
362
|
+
<NavigationButton
|
|
363
|
+
icon={pinTool.icon as string}
|
|
364
|
+
tintColor={tintColor}
|
|
365
|
+
badgeValue={badgeValue}
|
|
366
|
+
badgeType={badgeType}
|
|
367
|
+
onPress={() => {
|
|
368
|
+
navigator?.maxApi?.dispatchFunction?.(
|
|
369
|
+
'onToolAction',
|
|
370
|
+
[pinTool?.key],
|
|
371
|
+
() => {
|
|
372
|
+
getToolkitConfig();
|
|
373
|
+
},
|
|
374
|
+
);
|
|
375
|
+
navigator?.toolkitCallback?.(pinTool.key);
|
|
376
|
+
}}
|
|
377
|
+
/>
|
|
378
|
+
);
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
if (toolConfig) {
|
|
382
|
+
return (
|
|
383
|
+
<View style={styles.headerRightButton}>
|
|
384
|
+
{renderPinnedTool()}
|
|
385
|
+
<View
|
|
386
|
+
style={[
|
|
387
|
+
styles.toolkitContainer,
|
|
388
|
+
{
|
|
389
|
+
backgroundColor: backgroundColor ?? '#00000066',
|
|
390
|
+
borderWidth: backgroundColor ? 0.5 : 0,
|
|
391
|
+
},
|
|
392
|
+
]}>
|
|
393
|
+
<TouchableOpacity onPress={onMore}>
|
|
394
|
+
<Icon color={tintColor} source="navigation_more_horiz" size={20} />
|
|
395
|
+
</TouchableOpacity>
|
|
396
|
+
<View style={[styles.divider, {backgroundColor: tintColor}]} />
|
|
397
|
+
<TouchableOpacity onPress={onClose}>
|
|
398
|
+
<Icon
|
|
399
|
+
color={tintColor}
|
|
400
|
+
source="16_navigation_close_circle"
|
|
401
|
+
size={20}
|
|
402
|
+
/>
|
|
403
|
+
</TouchableOpacity>
|
|
404
|
+
</View>
|
|
405
|
+
</View>
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return <View />;
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
const HeaderAnimated: React.FC<HeaderAnimatedProps> = ({
|
|
413
|
+
animatedValue,
|
|
414
|
+
image,
|
|
415
|
+
onPress,
|
|
416
|
+
}) => {
|
|
417
|
+
const scale = animatedValue.interpolate({
|
|
418
|
+
inputRange: [-300, 0, 300],
|
|
419
|
+
outputRange: [4, 1, 1],
|
|
420
|
+
extrapolate: 'clamp',
|
|
421
|
+
});
|
|
422
|
+
const opacity = animatedValue.interpolate({
|
|
423
|
+
inputRange: [0, 150, 300],
|
|
424
|
+
outputRange: [1, 0.5, 0],
|
|
425
|
+
extrapolate: 'clamp',
|
|
426
|
+
});
|
|
427
|
+
const translateY = animatedValue.interpolate({
|
|
428
|
+
inputRange: [-300, 0],
|
|
429
|
+
outputRange: [-80, -2],
|
|
430
|
+
extrapolate: 'clamp',
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
return (
|
|
434
|
+
<TouchableOpacity onPress={onPress}>
|
|
435
|
+
<Animated.View
|
|
436
|
+
style={{
|
|
437
|
+
height: 210,
|
|
438
|
+
opacity: opacity,
|
|
439
|
+
transform: [{scale}, {translateY}],
|
|
440
|
+
}}>
|
|
441
|
+
<Image
|
|
442
|
+
source={{
|
|
443
|
+
uri: image,
|
|
444
|
+
}}
|
|
445
|
+
style={{width: '100%', height: '100%'}}
|
|
446
|
+
/>
|
|
447
|
+
</Animated.View>
|
|
448
|
+
</TouchableOpacity>
|
|
449
|
+
);
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
const styles = StyleSheet.create({
|
|
453
|
+
navigationButton: {
|
|
454
|
+
height: 28,
|
|
455
|
+
width: 28,
|
|
456
|
+
borderRadius: 14,
|
|
457
|
+
justifyContent: 'center',
|
|
458
|
+
alignItems: 'center',
|
|
459
|
+
},
|
|
460
|
+
headerBackground: {
|
|
461
|
+
width: '100%',
|
|
462
|
+
height: undefined,
|
|
463
|
+
position: 'absolute',
|
|
464
|
+
aspectRatio: 375 / 154,
|
|
465
|
+
},
|
|
466
|
+
headerTitleContainer: {
|
|
467
|
+
alignItems: 'center',
|
|
468
|
+
justifyContent: 'center',
|
|
469
|
+
width: '100%',
|
|
470
|
+
},
|
|
471
|
+
circle: {width: 36, height: 36, borderRadius: 18},
|
|
472
|
+
square: {width: 36, height: 36, borderRadius: Radius.XS},
|
|
473
|
+
dotAvatar: {
|
|
474
|
+
position: 'absolute',
|
|
475
|
+
width: 12,
|
|
476
|
+
height: 12,
|
|
477
|
+
borderRadius: 6,
|
|
478
|
+
bottom: 0,
|
|
479
|
+
right: 0,
|
|
480
|
+
borderWidth: 1,
|
|
481
|
+
borderColor: Colors.black_01,
|
|
482
|
+
},
|
|
483
|
+
headerButton: {paddingHorizontal: 4},
|
|
484
|
+
headerRightButton: {
|
|
485
|
+
flexDirection: 'row',
|
|
486
|
+
justifyContent: 'center',
|
|
487
|
+
alignItems: 'center',
|
|
488
|
+
paddingRight: Spacing.S,
|
|
489
|
+
},
|
|
490
|
+
toolkitContainer: {
|
|
491
|
+
marginLeft: Spacing.S,
|
|
492
|
+
padding: Spacing.XS,
|
|
493
|
+
height: 28,
|
|
494
|
+
borderRadius: 14,
|
|
495
|
+
borderColor: '#00000066',
|
|
496
|
+
justifyContent: 'center',
|
|
497
|
+
alignItems: 'center',
|
|
498
|
+
flexDirection: 'row',
|
|
499
|
+
},
|
|
500
|
+
divider: {
|
|
501
|
+
width: 1,
|
|
502
|
+
height: 12,
|
|
503
|
+
marginHorizontal: 4,
|
|
504
|
+
},
|
|
505
|
+
headerLeft: {
|
|
506
|
+
marginLeft: 12,
|
|
507
|
+
},
|
|
508
|
+
title: {
|
|
509
|
+
fontSize: scaleSize(15),
|
|
510
|
+
lineHeight: scaleSize(22),
|
|
511
|
+
fontWeight: 'bold',
|
|
512
|
+
},
|
|
513
|
+
badge: {
|
|
514
|
+
position: 'absolute',
|
|
515
|
+
top: -Spacing.S,
|
|
516
|
+
right: -6,
|
|
517
|
+
},
|
|
518
|
+
badgeDot: {
|
|
519
|
+
position: 'absolute',
|
|
520
|
+
top: -Spacing.XS,
|
|
521
|
+
right: -Spacing.XS,
|
|
522
|
+
},
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
export {
|
|
526
|
+
NavigationButton,
|
|
527
|
+
HeaderTitle,
|
|
528
|
+
HeaderLeft,
|
|
529
|
+
HeaderBackground,
|
|
530
|
+
HeaderRightAction,
|
|
531
|
+
HeaderToolkitAction,
|
|
532
|
+
HeaderCustom,
|
|
533
|
+
HeaderAnimated,
|
|
534
|
+
};
|