@momo-kits/foundation 0.89.5 → 0.89.6-rc.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.tsx +216 -0
- package/Application/BottomTab/BottomTabBar.tsx +278 -0
- package/Application/{BottomTab.tsx → BottomTab/index.tsx} +42 -18
- package/Application/Components.tsx +350 -86
- package/Application/Localize.ts +44 -0
- package/Application/ModalScreen.tsx +14 -185
- package/Application/Navigation.ts +5 -19
- package/Application/NavigationContainer.tsx +62 -72
- package/Application/Navigator.ts +53 -35
- package/Application/StackScreen.tsx +289 -32
- package/Application/index.ts +13 -15
- package/Application/types.ts +64 -35
- package/Application/utils.tsx +76 -30
- package/Assets/icon_bank.json +1 -1
- package/Badge/Badge.tsx +1 -1
- package/Badge/BadgeDotAnimation.tsx +95 -0
- package/Badge/index.tsx +2 -1
- package/Badge/styles.ts +50 -6
- package/Button/index.tsx +44 -26
- package/CheckBox/index.tsx +37 -26
- package/CheckBox/types.ts +5 -3
- package/Consts/colors+spacing+radius.ts +14 -0
- package/Icon/index.tsx +9 -8
- package/Icon/types.ts +2 -2
- package/IconButton/index.tsx +24 -14
- package/Image/index.tsx +23 -8
- package/Image/types.ts +2 -0
- package/Input/Input.tsx +116 -26
- package/Input/InputDropDown.tsx +66 -51
- package/Input/InputMoney.tsx +106 -15
- package/Input/InputOTP.tsx +49 -26
- package/Input/InputSearch.tsx +252 -99
- package/Input/InputTextArea.tsx +26 -6
- package/Input/TextTyping.tsx +113 -0
- package/Input/common.tsx +48 -22
- package/Input/index.tsx +112 -77
- package/Input/styles.ts +48 -11
- package/Input/utils.ts +1 -1
- package/Layout/Card.tsx +4 -3
- package/Layout/FloatingButton.tsx +168 -0
- package/Layout/GridSystem.tsx +1 -1
- package/Layout/ItemList.tsx +3 -2
- package/Layout/Screen.tsx +242 -121
- package/Layout/Section.tsx +4 -3
- package/Layout/styles.ts +11 -13
- package/Layout/types.ts +1 -1
- package/Layout/utils.ts +4 -4
- package/Loader/index.tsx +2 -0
- package/Pagination/PaginationScroll.tsx +2 -2
- package/Pagination/styles.ts +1 -1
- package/Popup/PopupNotify.tsx +56 -45
- package/Popup/PopupPromotion.tsx +5 -7
- package/Popup/types.ts +1 -7
- package/Radio/index.tsx +35 -20
- package/Radio/types.ts +5 -3
- package/Switch/index.tsx +32 -18
- package/Switch/types.ts +5 -3
- package/Tag/index.tsx +9 -2
- package/Tag/styles.ts +3 -2
- package/Tag/types.ts +12 -0
- package/Text/index.tsx +24 -5
- package/Text/styles.ts +8 -8
- package/Text/types.ts +19 -1
- package/Title/index.tsx +170 -103
- package/Title/styles.ts +36 -9
- package/Title/types.ts +16 -48
- package/code-scanner.js +125 -16
- package/index.ts +7 -0
- package/migrate_typo.js +56 -0
- package/package.json +11 -10
- package/publish.sh +16 -21
- package/tsconfig.json +1 -1
- package/verify.js +37 -40
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import React, {useRef, useEffect, useCallback, useContext} from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Animated,
|
|
4
|
+
Dimensions,
|
|
5
|
+
KeyboardAvoidingView,
|
|
6
|
+
PanResponder,
|
|
7
|
+
Platform,
|
|
8
|
+
StyleSheet,
|
|
9
|
+
TouchableOpacity,
|
|
10
|
+
View,
|
|
11
|
+
Modal,
|
|
12
|
+
} from 'react-native';
|
|
13
|
+
import {useSafeAreaInsets} from 'react-native-safe-area-context';
|
|
14
|
+
import {ApplicationContext} from './index';
|
|
15
|
+
import {BottomSheetParams} from './types';
|
|
16
|
+
import {Colors, Radius, Spacing, Styles} from '../Consts';
|
|
17
|
+
import {Text} from '../Text';
|
|
18
|
+
import {Icon} from '../Icon';
|
|
19
|
+
|
|
20
|
+
const BottomSheet: React.FC<BottomSheetParams> = props => {
|
|
21
|
+
const {theme, navigator} = useContext(ApplicationContext);
|
|
22
|
+
const heightDevice = Dimensions.get('screen').height;
|
|
23
|
+
const insets = useSafeAreaInsets();
|
|
24
|
+
const {
|
|
25
|
+
screen: Screen,
|
|
26
|
+
options,
|
|
27
|
+
useNativeModal = false,
|
|
28
|
+
surface,
|
|
29
|
+
barrierDismissible = false,
|
|
30
|
+
draggable = true,
|
|
31
|
+
useBottomInset = true,
|
|
32
|
+
keyboardVerticalOffset,
|
|
33
|
+
}: BottomSheetParams = props.route.params;
|
|
34
|
+
const pan = useRef(
|
|
35
|
+
new Animated.ValueXY({
|
|
36
|
+
y: heightDevice,
|
|
37
|
+
x: 0,
|
|
38
|
+
})
|
|
39
|
+
).current;
|
|
40
|
+
|
|
41
|
+
const panResponder = useRef(
|
|
42
|
+
PanResponder.create({
|
|
43
|
+
onStartShouldSetPanResponder: () => draggable,
|
|
44
|
+
onMoveShouldSetPanResponder: (_, gestureState) => {
|
|
45
|
+
return draggable && gestureState.dy > 0;
|
|
46
|
+
},
|
|
47
|
+
onPanResponderMove: (e, gestureState) => {
|
|
48
|
+
gestureState.dy > 0 &&
|
|
49
|
+
Animated.event([null, {dy: pan.y}], {useNativeDriver: false})(
|
|
50
|
+
e,
|
|
51
|
+
gestureState
|
|
52
|
+
);
|
|
53
|
+
},
|
|
54
|
+
onPanResponderRelease: (_, gestureState) => {
|
|
55
|
+
if (gestureState.dy > 100) {
|
|
56
|
+
onDismiss();
|
|
57
|
+
} else {
|
|
58
|
+
Animated.spring(pan, {
|
|
59
|
+
toValue: {x: 0, y: 0},
|
|
60
|
+
useNativeDriver: false,
|
|
61
|
+
}).start();
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
})
|
|
65
|
+
).current;
|
|
66
|
+
let Container: any = View;
|
|
67
|
+
if (useNativeModal) {
|
|
68
|
+
Container = Modal;
|
|
69
|
+
}
|
|
70
|
+
let backgroundColor = theme.colors.background.default;
|
|
71
|
+
if (surface) {
|
|
72
|
+
backgroundColor = theme.colors.background.surface;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* emit dismiss event
|
|
77
|
+
*/
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
Animated.timing(pan, {
|
|
80
|
+
toValue: {x: 0, y: 0},
|
|
81
|
+
useNativeDriver: false,
|
|
82
|
+
duration: 150,
|
|
83
|
+
}).start();
|
|
84
|
+
return () => {
|
|
85
|
+
props.route.params?.onDismiss?.();
|
|
86
|
+
};
|
|
87
|
+
}, []);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* handler dismiss
|
|
91
|
+
*/
|
|
92
|
+
const onDismiss = (force = false, callback?: () => void) => {
|
|
93
|
+
if (barrierDismissible && !force) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
setTimeout(() => {
|
|
97
|
+
callback?.();
|
|
98
|
+
}, 300);
|
|
99
|
+
Animated.timing(pan, {
|
|
100
|
+
toValue: {x: 0, y: heightDevice},
|
|
101
|
+
useNativeDriver: false,
|
|
102
|
+
duration: 200,
|
|
103
|
+
}).start(() => {
|
|
104
|
+
navigator?.pop();
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* on request close
|
|
110
|
+
*/
|
|
111
|
+
const onRequestClose = useCallback((callback?: () => void) => {
|
|
112
|
+
onDismiss(true, callback);
|
|
113
|
+
}, []);
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* render header
|
|
117
|
+
*/
|
|
118
|
+
const renderHeader = useCallback(() => {
|
|
119
|
+
return (
|
|
120
|
+
<View
|
|
121
|
+
style={{
|
|
122
|
+
backgroundColor,
|
|
123
|
+
borderTopLeftRadius: Radius.M,
|
|
124
|
+
borderTopRightRadius: Radius.M,
|
|
125
|
+
}}
|
|
126
|
+
{...panResponder.panHandlers}>
|
|
127
|
+
<View style={{height: 16}}>
|
|
128
|
+
<View style={styles.indicator} />
|
|
129
|
+
</View>
|
|
130
|
+
<View
|
|
131
|
+
style={[
|
|
132
|
+
styles.header,
|
|
133
|
+
surface && {
|
|
134
|
+
borderBottomColor: theme.colors.border.default,
|
|
135
|
+
borderBottomWidth: 1,
|
|
136
|
+
},
|
|
137
|
+
]}>
|
|
138
|
+
<View style={styles.iconButton} />
|
|
139
|
+
<Text
|
|
140
|
+
style={[Styles.flex, {textAlign: 'center'}]}
|
|
141
|
+
numberOfLines={1}
|
|
142
|
+
typography="header_default_bold">
|
|
143
|
+
{options.title ?? ''}
|
|
144
|
+
</Text>
|
|
145
|
+
<TouchableOpacity
|
|
146
|
+
style={styles.iconButton}
|
|
147
|
+
onPress={() => onDismiss(true)}>
|
|
148
|
+
<Icon source="navigation_close" />
|
|
149
|
+
</TouchableOpacity>
|
|
150
|
+
</View>
|
|
151
|
+
</View>
|
|
152
|
+
);
|
|
153
|
+
}, []);
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<Container
|
|
157
|
+
transparent
|
|
158
|
+
visible={true}
|
|
159
|
+
onRequestClose={() => onDismiss()}
|
|
160
|
+
style={styles.overlay}>
|
|
161
|
+
<KeyboardAvoidingView
|
|
162
|
+
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
|
|
163
|
+
keyboardVerticalOffset={keyboardVerticalOffset ?? -20}
|
|
164
|
+
style={[Styles.flex, {justifyContent: 'flex-end'}]}>
|
|
165
|
+
<TouchableOpacity
|
|
166
|
+
style={Styles.flex}
|
|
167
|
+
activeOpacity={1}
|
|
168
|
+
onPress={() => onDismiss()}
|
|
169
|
+
/>
|
|
170
|
+
<Animated.View style={{transform: pan.getTranslateTransform()}}>
|
|
171
|
+
{renderHeader()}
|
|
172
|
+
<View style={{backgroundColor: backgroundColor}}>
|
|
173
|
+
<Screen
|
|
174
|
+
{...props}
|
|
175
|
+
{...props.route.params}
|
|
176
|
+
onRequestClose={onRequestClose}
|
|
177
|
+
/>
|
|
178
|
+
{useBottomInset && (
|
|
179
|
+
<View style={{height: Math.min(insets.bottom, 21)}} />
|
|
180
|
+
)}
|
|
181
|
+
</View>
|
|
182
|
+
</Animated.View>
|
|
183
|
+
</KeyboardAvoidingView>
|
|
184
|
+
</Container>
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const styles = StyleSheet.create({
|
|
189
|
+
overlay: {
|
|
190
|
+
...StyleSheet.absoluteFillObject,
|
|
191
|
+
justifyContent: 'flex-end',
|
|
192
|
+
},
|
|
193
|
+
indicator: {
|
|
194
|
+
width: 40,
|
|
195
|
+
height: 4,
|
|
196
|
+
borderRadius: Radius.S,
|
|
197
|
+
backgroundColor: Colors.black_06,
|
|
198
|
+
position: 'absolute',
|
|
199
|
+
alignSelf: 'center',
|
|
200
|
+
top: Spacing.S,
|
|
201
|
+
},
|
|
202
|
+
header: {
|
|
203
|
+
height: 56,
|
|
204
|
+
flexDirection: 'row',
|
|
205
|
+
alignItems: 'center',
|
|
206
|
+
},
|
|
207
|
+
iconButton: {
|
|
208
|
+
width: 24,
|
|
209
|
+
height: 24,
|
|
210
|
+
alignItems: 'center',
|
|
211
|
+
justifyContent: 'center',
|
|
212
|
+
marginHorizontal: Spacing.M,
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
export default BottomSheet;
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import {BottomTabBarProps} from '@react-navigation/bottom-tabs';
|
|
2
|
+
import BottomTabBarItem from '@react-navigation/bottom-tabs/src/views/BottomTabItem';
|
|
3
|
+
import {
|
|
4
|
+
CommonActions,
|
|
5
|
+
NavigationContext,
|
|
6
|
+
NavigationRouteContext,
|
|
7
|
+
useLinkBuilder,
|
|
8
|
+
} from '@react-navigation/native';
|
|
9
|
+
import React, {useCallback, useContext} from 'react';
|
|
10
|
+
import {
|
|
11
|
+
Animated,
|
|
12
|
+
Platform,
|
|
13
|
+
StyleSheet,
|
|
14
|
+
TouchableOpacity,
|
|
15
|
+
useWindowDimensions,
|
|
16
|
+
View,
|
|
17
|
+
} from 'react-native';
|
|
18
|
+
import {EdgeInsets, useSafeAreaInsets} from 'react-native-safe-area-context';
|
|
19
|
+
import {Radius} from '../../Consts';
|
|
20
|
+
import {Icon} from '../../Icon';
|
|
21
|
+
import {Text} from '../../Text';
|
|
22
|
+
import {FloatingButtonProps} from '../types';
|
|
23
|
+
import {ApplicationContext} from '../index';
|
|
24
|
+
|
|
25
|
+
type Props = BottomTabBarProps & {
|
|
26
|
+
activeTintColor?: string;
|
|
27
|
+
inactiveTintColor?: string;
|
|
28
|
+
floatingButton?: FloatingButtonProps;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const getPaddingBottom = (insets: EdgeInsets) => {
|
|
32
|
+
return Math.max(insets.bottom - Platform.select({ios: 4, default: 0}), 0);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default function BottomTabBar({
|
|
36
|
+
state,
|
|
37
|
+
navigation,
|
|
38
|
+
descriptors,
|
|
39
|
+
activeBackgroundColor,
|
|
40
|
+
activeTintColor,
|
|
41
|
+
allowFontScaling,
|
|
42
|
+
inactiveBackgroundColor,
|
|
43
|
+
inactiveTintColor,
|
|
44
|
+
labelStyle,
|
|
45
|
+
iconStyle,
|
|
46
|
+
showLabel,
|
|
47
|
+
style,
|
|
48
|
+
tabStyle,
|
|
49
|
+
floatingButton,
|
|
50
|
+
}: Props) {
|
|
51
|
+
const {theme} = useContext(ApplicationContext);
|
|
52
|
+
const {routes} = state;
|
|
53
|
+
const widthDevice = useWindowDimensions()?.width;
|
|
54
|
+
const useFloating = floatingButton && state.routes.length % 2 === 0;
|
|
55
|
+
const itemWidth = widthDevice / (state.routes.length + (useFloating ? 1 : 0));
|
|
56
|
+
const buildLink = useLinkBuilder();
|
|
57
|
+
const indicatorAnimated = React.useRef(new Animated.Value(0)).current;
|
|
58
|
+
const insets = useSafeAreaInsets();
|
|
59
|
+
const paddingBottom = getPaddingBottom(insets);
|
|
60
|
+
const focusedTab = state?.routes[state.index]?.name || routes[0]?.params;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* render tab item
|
|
64
|
+
*/
|
|
65
|
+
const renderTabItem = useCallback(
|
|
66
|
+
(data: any[]) => {
|
|
67
|
+
return data?.map((route, _) => {
|
|
68
|
+
const focused = route.params.name === focusedTab;
|
|
69
|
+
const {options} = descriptors[route?.key] as any;
|
|
70
|
+
const onPress = () => {
|
|
71
|
+
const event = navigation.emit({
|
|
72
|
+
type: 'tabPress',
|
|
73
|
+
target: route.key,
|
|
74
|
+
canPreventDefault: true,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (!focused && !event.defaultPrevented) {
|
|
78
|
+
navigation.dispatch({
|
|
79
|
+
...CommonActions.navigate(route.name),
|
|
80
|
+
target: state.key,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const onLongPress = () => {
|
|
86
|
+
navigation.emit({
|
|
87
|
+
type: 'tabLongPress',
|
|
88
|
+
target: route.key,
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const label = options.tabBarLabel || options.title || route.name;
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<NavigationContext.Provider
|
|
96
|
+
key={route.key}
|
|
97
|
+
value={(descriptors as any)[route.key].navigation}>
|
|
98
|
+
<NavigationRouteContext.Provider value={route}>
|
|
99
|
+
<BottomTabBarItem
|
|
100
|
+
route={route}
|
|
101
|
+
focused={focused}
|
|
102
|
+
horizontal={false}
|
|
103
|
+
onPress={onPress}
|
|
104
|
+
onLongPress={onLongPress}
|
|
105
|
+
accessibilityLabel={`tab_item_${route.name}`}
|
|
106
|
+
to={buildLink(route.name, route.params)}
|
|
107
|
+
testID={options.tabBarTestID}
|
|
108
|
+
allowFontScaling={allowFontScaling}
|
|
109
|
+
activeTintColor={activeTintColor}
|
|
110
|
+
inactiveTintColor={inactiveTintColor}
|
|
111
|
+
activeBackgroundColor={activeBackgroundColor}
|
|
112
|
+
inactiveBackgroundColor={inactiveBackgroundColor}
|
|
113
|
+
button={options.tabBarButton}
|
|
114
|
+
icon={options.tabBarIcon}
|
|
115
|
+
badge={options.tabBarBadge}
|
|
116
|
+
badgeStyle={options.tabBarBadgeStyle}
|
|
117
|
+
label={label}
|
|
118
|
+
showLabel={showLabel}
|
|
119
|
+
labelStyle={labelStyle}
|
|
120
|
+
iconStyle={iconStyle}
|
|
121
|
+
style={tabStyle}
|
|
122
|
+
/>
|
|
123
|
+
</NavigationRouteContext.Provider>
|
|
124
|
+
</NavigationContext.Provider>
|
|
125
|
+
);
|
|
126
|
+
});
|
|
127
|
+
},
|
|
128
|
+
[JSON.stringify(routes), state, descriptors, focusedTab]
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* render floating button
|
|
133
|
+
*/
|
|
134
|
+
const renderFloatingButton = useCallback(() => {
|
|
135
|
+
const renderFloatingButton = () => {
|
|
136
|
+
if (typeof floatingButton?.icon === 'string') {
|
|
137
|
+
return <Icon source={floatingButton?.icon} size={32} color={'white'} />;
|
|
138
|
+
}
|
|
139
|
+
return floatingButton?.icon;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<View style={{flex: 1}}>
|
|
144
|
+
<TouchableOpacity
|
|
145
|
+
onPress={floatingButton?.onPress}
|
|
146
|
+
style={styles.floatingContainer}>
|
|
147
|
+
<View
|
|
148
|
+
style={{
|
|
149
|
+
...styles.floatingContent,
|
|
150
|
+
backgroundColor: activeTintColor ?? theme.colors.primary,
|
|
151
|
+
}}>
|
|
152
|
+
{renderFloatingButton()}
|
|
153
|
+
</View>
|
|
154
|
+
<View
|
|
155
|
+
style={{
|
|
156
|
+
top: -4,
|
|
157
|
+
backgroundColor: activeTintColor ?? theme.colors.primary,
|
|
158
|
+
borderRadius: Radius.XL,
|
|
159
|
+
paddingHorizontal: 6,
|
|
160
|
+
}}>
|
|
161
|
+
<Text
|
|
162
|
+
numberOfLines={1}
|
|
163
|
+
typography={'description_xs_regular'}
|
|
164
|
+
color={'white'}>
|
|
165
|
+
{floatingButton?.label}
|
|
166
|
+
</Text>
|
|
167
|
+
</View>
|
|
168
|
+
</TouchableOpacity>
|
|
169
|
+
</View>
|
|
170
|
+
);
|
|
171
|
+
}, [useFloating]);
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* animated indicator
|
|
175
|
+
*/
|
|
176
|
+
React.useEffect(() => {
|
|
177
|
+
let index = state.index;
|
|
178
|
+
if (useFloating && index > (state.routes.length - 1) / 2) {
|
|
179
|
+
index += 1;
|
|
180
|
+
}
|
|
181
|
+
Animated.timing(indicatorAnimated, {
|
|
182
|
+
toValue: itemWidth * index,
|
|
183
|
+
useNativeDriver: true,
|
|
184
|
+
duration: 200,
|
|
185
|
+
}).start();
|
|
186
|
+
}, [state.index, itemWidth, indicatorAnimated, useFloating]);
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* render tab bar
|
|
190
|
+
*/
|
|
191
|
+
const renderTabBar = () => {
|
|
192
|
+
if (useFloating) {
|
|
193
|
+
const middleIndex = routes.length / 2;
|
|
194
|
+
const leftArr = routes.slice(0, middleIndex);
|
|
195
|
+
const rightArr = routes.slice(middleIndex);
|
|
196
|
+
return (
|
|
197
|
+
<>
|
|
198
|
+
{renderTabItem(leftArr)}
|
|
199
|
+
{renderFloatingButton()}
|
|
200
|
+
{renderTabItem(rightArr)}
|
|
201
|
+
</>
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
return renderTabItem(routes);
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<Animated.View
|
|
209
|
+
style={[
|
|
210
|
+
styles.tabBar,
|
|
211
|
+
{
|
|
212
|
+
backgroundColor: theme.colors.background.surface,
|
|
213
|
+
borderTopColor: theme.colors.border.default,
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
paddingBottom: paddingBottom,
|
|
217
|
+
paddingHorizontal: Math.max(insets.left, insets.right),
|
|
218
|
+
},
|
|
219
|
+
style,
|
|
220
|
+
]}
|
|
221
|
+
pointerEvents={'auto'}>
|
|
222
|
+
<View style={styles.content} accessibilityLabel={'bottom_tab_bar'}>
|
|
223
|
+
{useFloating && floatingButton?.container}
|
|
224
|
+
<Animated.View
|
|
225
|
+
style={{
|
|
226
|
+
width: itemWidth,
|
|
227
|
+
position: 'absolute',
|
|
228
|
+
top: 0,
|
|
229
|
+
transform: [{translateX: indicatorAnimated}],
|
|
230
|
+
}}>
|
|
231
|
+
<View
|
|
232
|
+
style={[
|
|
233
|
+
styles.indicator,
|
|
234
|
+
{backgroundColor: activeTintColor ?? theme.colors.primary},
|
|
235
|
+
]}
|
|
236
|
+
/>
|
|
237
|
+
</Animated.View>
|
|
238
|
+
{renderTabBar()}
|
|
239
|
+
</View>
|
|
240
|
+
</Animated.View>
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const styles = StyleSheet.create({
|
|
245
|
+
content: {
|
|
246
|
+
flex: 1,
|
|
247
|
+
flexDirection: 'row',
|
|
248
|
+
},
|
|
249
|
+
tabBar: {
|
|
250
|
+
left: 0,
|
|
251
|
+
right: 0,
|
|
252
|
+
bottom: 0,
|
|
253
|
+
borderTopWidth: StyleSheet.hairlineWidth,
|
|
254
|
+
elevation: 8,
|
|
255
|
+
},
|
|
256
|
+
floatingContainer: {
|
|
257
|
+
position: 'absolute',
|
|
258
|
+
alignItems: 'center',
|
|
259
|
+
left: 0,
|
|
260
|
+
right: 0,
|
|
261
|
+
bottom: Platform.OS === 'ios' ? -6 : 0,
|
|
262
|
+
},
|
|
263
|
+
floatingContent: {
|
|
264
|
+
alignItems: 'center',
|
|
265
|
+
justifyContent: 'center',
|
|
266
|
+
height: 48,
|
|
267
|
+
width: 48,
|
|
268
|
+
borderRadius: 24,
|
|
269
|
+
top: -10,
|
|
270
|
+
},
|
|
271
|
+
indicator: {
|
|
272
|
+
height: 2,
|
|
273
|
+
width: 44,
|
|
274
|
+
alignSelf: 'center',
|
|
275
|
+
borderBottomLeftRadius: 1,
|
|
276
|
+
borderBottomRightRadius: 1,
|
|
277
|
+
},
|
|
278
|
+
});
|
|
@@ -1,28 +1,39 @@
|
|
|
1
|
-
import React, {useContext, useEffect} from 'react';
|
|
2
|
-
import {Platform} from 'react-native';
|
|
3
|
-
import {BottomTabProps, NavigationScreenProps} from './types';
|
|
4
1
|
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
|
|
2
|
+
import {NavigationContainer} from '@react-navigation/native';
|
|
5
3
|
import {createStackNavigator} from '@react-navigation/stack';
|
|
4
|
+
import React, {useContext, useEffect} from 'react';
|
|
5
|
+
import {Platform} from 'react-native';
|
|
6
6
|
import {useSafeAreaInsets} from 'react-native-safe-area-context';
|
|
7
|
-
import {
|
|
8
|
-
import {Icon} from '
|
|
9
|
-
import {Text} from '
|
|
10
|
-
import {ApplicationContext} from '
|
|
11
|
-
import
|
|
12
|
-
import
|
|
7
|
+
import {Colors} from '../../Consts';
|
|
8
|
+
import {Icon} from '../../Icon';
|
|
9
|
+
import {Text} from '../../Text';
|
|
10
|
+
import {ApplicationContext} from '../index';
|
|
11
|
+
import StackScreen from '../StackScreen';
|
|
12
|
+
import {BottomTabProps, NavigationScreenProps} from '../types';
|
|
13
|
+
import {getOptions, getStackOptions} from '../utils';
|
|
14
|
+
import BottomTabBar from './BottomTabBar';
|
|
13
15
|
|
|
14
16
|
const Tab = createBottomTabNavigator();
|
|
15
17
|
const Stack = createStackNavigator();
|
|
16
18
|
|
|
17
19
|
const TabScreen: React.FC<NavigationScreenProps> = ({route}) => {
|
|
20
|
+
let options = {};
|
|
21
|
+
if (route.params?.options) {
|
|
22
|
+
options = getOptions(route.params?.options);
|
|
23
|
+
}
|
|
24
|
+
|
|
18
25
|
if (route.params?.nested) {
|
|
19
26
|
return (
|
|
20
27
|
<Stack.Navigator>
|
|
21
28
|
<Stack.Screen
|
|
22
29
|
name="Stack"
|
|
23
30
|
component={StackScreen}
|
|
24
|
-
initialParams={{
|
|
25
|
-
|
|
31
|
+
initialParams={{
|
|
32
|
+
screen: route.params?.screen,
|
|
33
|
+
options,
|
|
34
|
+
initialParams: route.params?.initialParams,
|
|
35
|
+
}}
|
|
36
|
+
options={{...getStackOptions()}}
|
|
26
37
|
/>
|
|
27
38
|
</Stack.Navigator>
|
|
28
39
|
);
|
|
@@ -33,19 +44,25 @@ const TabScreen: React.FC<NavigationScreenProps> = ({route}) => {
|
|
|
33
44
|
<Stack.Screen
|
|
34
45
|
name="Stack"
|
|
35
46
|
component={StackScreen}
|
|
36
|
-
initialParams={{
|
|
47
|
+
initialParams={{
|
|
48
|
+
screen: route.params?.screen,
|
|
49
|
+
options,
|
|
50
|
+
initialParams: route.params?.initialParams,
|
|
51
|
+
}}
|
|
37
52
|
options={{...getStackOptions(), ...route.params?.options}}
|
|
38
53
|
/>
|
|
39
54
|
</Stack.Navigator>
|
|
40
55
|
</NavigationContainer>
|
|
41
56
|
);
|
|
42
57
|
};
|
|
58
|
+
|
|
43
59
|
const BottomTab: React.FC<BottomTabProps> = ({
|
|
44
60
|
nested,
|
|
45
61
|
tabs,
|
|
46
62
|
listeners,
|
|
47
63
|
navigation,
|
|
48
64
|
initialRouteName,
|
|
65
|
+
floatingButton,
|
|
49
66
|
}) => {
|
|
50
67
|
const {theme} = useContext(ApplicationContext);
|
|
51
68
|
const insets = useSafeAreaInsets();
|
|
@@ -62,23 +79,28 @@ const BottomTab: React.FC<BottomTabProps> = ({
|
|
|
62
79
|
<Tab.Navigator
|
|
63
80
|
initialRouteName={initialRouteName}
|
|
64
81
|
backBehavior={'firstRoute'}
|
|
82
|
+
tabBar={props => (
|
|
83
|
+
<BottomTabBar {...props} floatingButton={floatingButton} />
|
|
84
|
+
)}
|
|
65
85
|
tabBarOptions={{
|
|
66
86
|
style: {
|
|
67
|
-
height:
|
|
87
|
+
height: 64 + Math.min(insets.bottom, 21),
|
|
68
88
|
},
|
|
69
89
|
tabStyle: {
|
|
70
90
|
height: 68,
|
|
71
|
-
paddingVertical:
|
|
91
|
+
paddingVertical: 10,
|
|
72
92
|
},
|
|
73
93
|
}}>
|
|
74
94
|
{tabs.map(item => {
|
|
95
|
+
const isNum = !isNaN(parseInt(`${item?.badgeLabel}`));
|
|
96
|
+
const isDot = typeof item?.badgeLabel === 'string' && !item?.badgeLabel;
|
|
75
97
|
return (
|
|
76
98
|
<Tab.Screen
|
|
77
99
|
key={item.name}
|
|
78
100
|
name={item.name}
|
|
79
101
|
component={TabScreen}
|
|
80
102
|
initialParams={{...item, nested}}
|
|
81
|
-
listeners={listeners}
|
|
103
|
+
listeners={item.listeners ?? listeners}
|
|
82
104
|
options={{
|
|
83
105
|
tabBarLabel: ({color, focused}) => {
|
|
84
106
|
return (
|
|
@@ -87,7 +109,8 @@ const BottomTab: React.FC<BottomTabProps> = ({
|
|
|
87
109
|
typography={
|
|
88
110
|
focused ? 'label_xs_medium' : 'description_xs_regular'
|
|
89
111
|
}
|
|
90
|
-
color={color}
|
|
112
|
+
color={color}
|
|
113
|
+
style={{width: '90%', textAlign: 'center'}}>
|
|
91
114
|
{item.label}
|
|
92
115
|
</Text>
|
|
93
116
|
);
|
|
@@ -101,8 +124,9 @@ const BottomTab: React.FC<BottomTabProps> = ({
|
|
|
101
124
|
fontWeight: 'bold',
|
|
102
125
|
alignSelf: 'center',
|
|
103
126
|
fontFamily: `${theme.font}-Bold`,
|
|
104
|
-
left:
|
|
105
|
-
top:
|
|
127
|
+
left: isDot ? 8 : 4,
|
|
128
|
+
top: isDot ? -2 : -6,
|
|
129
|
+
backgroundColor: isNum ? Colors.red_03 : Colors.orange_03,
|
|
106
130
|
},
|
|
107
131
|
tabBarIcon: ({color}) => (
|
|
108
132
|
<Icon source={item.icon} color={color} size={28} />
|