@momo-kits/foundation 0.169.12-beta.2 → 0.169.12-beta.3
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/LegacyBottomTab.tsx +194 -0
- package/Application/BottomTab/LegacyBottomTabBar.styles.ts +62 -0
- package/Application/BottomTab/LegacyBottomTabBar.tsx +208 -0
- package/Application/BottomTab/LegacyBottomTabItem.tsx +109 -0
- package/Application/BottomTab/LegacyTabBarIcon.tsx +96 -0
- package/Application/BottomTab/TabBarIcon.tsx +7 -2
- package/Application/BottomTab/index.tsx +14 -1
- package/Application/types.tabs.ts +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import React, { useContext, useLayoutEffect } from 'react';
|
|
2
|
+
import { NativeModules, Platform, StatusBar, StyleSheet } from 'react-native';
|
|
3
|
+
import {
|
|
4
|
+
type BottomTabBarProps,
|
|
5
|
+
createBottomTabNavigator,
|
|
6
|
+
} from '@react-navigation/bottom-tabs';
|
|
7
|
+
import { useFocusEffect } from '@react-navigation/native';
|
|
8
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
9
|
+
import { Colors, Spacing } from '../../Consts';
|
|
10
|
+
import { Icon } from '../../Icon';
|
|
11
|
+
import { exportFontFamily, Text } from '../../Text';
|
|
12
|
+
import { ApplicationContext } from '../../Context';
|
|
13
|
+
import { type BottomTabProps } from '../types';
|
|
14
|
+
import { LegacyBottomTabBar } from './LegacyBottomTabBar';
|
|
15
|
+
import TabScreen from './TabScreen';
|
|
16
|
+
|
|
17
|
+
const BAR_HEIGHT = 64;
|
|
18
|
+
const IOS_MAX_BOTTOM_INSET = 21;
|
|
19
|
+
const TAB_ICON_SIZE = 28;
|
|
20
|
+
const BADGE_FONT_SIZE = 10;
|
|
21
|
+
const BADGE_LINE_HEIGHT = 14;
|
|
22
|
+
const BADGE_BORDER_WIDTH = 2;
|
|
23
|
+
const DOT_SIZE = 12;
|
|
24
|
+
|
|
25
|
+
const Tab = createBottomTabNavigator();
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Old badge rules: 0 hides it, '' is an orange dot, numbers are red, any other
|
|
29
|
+
* text is orange and shown in full.
|
|
30
|
+
*/
|
|
31
|
+
const getLegacyBadgeProps = (label?: string | number) => {
|
|
32
|
+
const isNum = !isNaN(parseInt(`${label}`, 10));
|
|
33
|
+
const isDot = typeof label === 'string' && !label;
|
|
34
|
+
const badgeLabel = isNum && Number(label) === 0 ? undefined : label;
|
|
35
|
+
|
|
36
|
+
if (isDot) {
|
|
37
|
+
const badgeStyle = {
|
|
38
|
+
marginRight: -2,
|
|
39
|
+
top: -2,
|
|
40
|
+
backgroundColor: Colors.orange_03,
|
|
41
|
+
width: DOT_SIZE,
|
|
42
|
+
};
|
|
43
|
+
return { badgeLabel, badgeStyle };
|
|
44
|
+
}
|
|
45
|
+
const badgeStyle = {
|
|
46
|
+
marginRight: isNum ? -4 : -8,
|
|
47
|
+
top: -4,
|
|
48
|
+
backgroundColor: isNum ? Colors.red_03 : Colors.orange_03,
|
|
49
|
+
};
|
|
50
|
+
return { badgeLabel, badgeStyle };
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Pre-redesign tab navigator (`useLegacy`): docked full-width bar that the tab
|
|
55
|
+
* content sits above, no tab slide. `showDot` and `compressionBehavior` are
|
|
56
|
+
* ignored; phone only, iPhone Duo keeps the current bars.
|
|
57
|
+
*/
|
|
58
|
+
const LegacyBottomTab = ({
|
|
59
|
+
nested,
|
|
60
|
+
tabs,
|
|
61
|
+
listeners,
|
|
62
|
+
navigation,
|
|
63
|
+
initialRouteName,
|
|
64
|
+
floatingButton,
|
|
65
|
+
}: BottomTabProps) => {
|
|
66
|
+
const { theme, navigator } = useContext(ApplicationContext);
|
|
67
|
+
const insets = useSafeAreaInsets();
|
|
68
|
+
const initialIndex = tabs.findIndex(i => i.name === initialRouteName);
|
|
69
|
+
const activeIndex = React.useRef(initialIndex > 0 ? initialIndex : 0);
|
|
70
|
+
const isIOS = Platform.OS === 'ios';
|
|
71
|
+
const bottomInset = isIOS
|
|
72
|
+
? Math.min(insets.bottom, IOS_MAX_BOTTOM_INSET)
|
|
73
|
+
: insets.bottom;
|
|
74
|
+
|
|
75
|
+
useLayoutEffect(() => {
|
|
76
|
+
navigation?.setOptions({
|
|
77
|
+
headerShown: false,
|
|
78
|
+
headerTransparent: true,
|
|
79
|
+
headerBackground: undefined,
|
|
80
|
+
});
|
|
81
|
+
}, [navigation]);
|
|
82
|
+
|
|
83
|
+
useFocusEffect(
|
|
84
|
+
React.useCallback(() => {
|
|
85
|
+
NativeModules?.MiniAppModule?.setShouldUseFloatingArrowBack?.(
|
|
86
|
+
activeIndex.current !== 0,
|
|
87
|
+
);
|
|
88
|
+
return () => {
|
|
89
|
+
NativeModules?.MiniAppModule?.setShouldUseFloatingArrowBack?.(false);
|
|
90
|
+
};
|
|
91
|
+
}, []),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const handleFocus = (e: any) => {
|
|
95
|
+
activeIndex.current = tabs.findIndex(i => e.target.includes(i.name));
|
|
96
|
+
const isGestureEnabled = isIOS && activeIndex.current === 0;
|
|
97
|
+
navigation?.setOptions({ gestureEnabled: isGestureEnabled });
|
|
98
|
+
NativeModules?.MiniAppModule?.setShouldUseFloatingArrowBack?.(
|
|
99
|
+
!isGestureEnabled,
|
|
100
|
+
);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const handler = {
|
|
104
|
+
tabPress: (e: any) => {
|
|
105
|
+
navigator?.maxApi?.triggerEventVibration?.('light');
|
|
106
|
+
listeners?.tabPress?.(e);
|
|
107
|
+
},
|
|
108
|
+
focus: (e: any) => {
|
|
109
|
+
handleFocus(e);
|
|
110
|
+
StatusBar.setBarStyle('dark-content', true);
|
|
111
|
+
listeners?.focus?.(e);
|
|
112
|
+
},
|
|
113
|
+
blur: (e: any) => {
|
|
114
|
+
listeners?.blur?.(e);
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const renderTabBar = (props: BottomTabBarProps) => {
|
|
119
|
+
return (
|
|
120
|
+
<LegacyBottomTabBar
|
|
121
|
+
{...props}
|
|
122
|
+
floatingButton={floatingButton}
|
|
123
|
+
inactiveTintColor={theme.colors.text.hint}
|
|
124
|
+
activeTintColor={theme.colors.primary}
|
|
125
|
+
style={{ height: BAR_HEIGHT + bottomInset }}
|
|
126
|
+
/>
|
|
127
|
+
);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<Tab.Navigator
|
|
132
|
+
screenOptions={{
|
|
133
|
+
headerShown: false,
|
|
134
|
+
headerTransparent: true,
|
|
135
|
+
headerBackground: undefined,
|
|
136
|
+
tabBarLabelPosition: 'below-icon',
|
|
137
|
+
}}
|
|
138
|
+
tabBar={renderTabBar}
|
|
139
|
+
initialRouteName={initialRouteName}
|
|
140
|
+
>
|
|
141
|
+
{tabs.map((item, index) => {
|
|
142
|
+
const { badgeLabel, badgeStyle } = getLegacyBadgeProps(item.badgeLabel);
|
|
143
|
+
return (
|
|
144
|
+
<Tab.Screen
|
|
145
|
+
key={`BottomTab-${item.name}`}
|
|
146
|
+
name={item.name}
|
|
147
|
+
component={TabScreen}
|
|
148
|
+
initialParams={{ ...item, nested, index }}
|
|
149
|
+
listeners={handler}
|
|
150
|
+
options={{
|
|
151
|
+
tabBarLabel: ({ focused, color }) => (
|
|
152
|
+
<Text
|
|
153
|
+
numberOfLines={1}
|
|
154
|
+
typography={
|
|
155
|
+
focused ? 'label_xs_medium' : 'description_xs_regular'
|
|
156
|
+
}
|
|
157
|
+
color={color}
|
|
158
|
+
>
|
|
159
|
+
{item.label}
|
|
160
|
+
</Text>
|
|
161
|
+
),
|
|
162
|
+
title: item.label,
|
|
163
|
+
tabBarStyle: styles.tab,
|
|
164
|
+
tabBarBadge: badgeLabel,
|
|
165
|
+
tabBarBadgeStyle: [styles.badge, badgeStyle],
|
|
166
|
+
tabBarIcon: ({ color }) => (
|
|
167
|
+
<Icon source={item.icon} color={color} size={TAB_ICON_SIZE} />
|
|
168
|
+
),
|
|
169
|
+
...item,
|
|
170
|
+
}}
|
|
171
|
+
/>
|
|
172
|
+
);
|
|
173
|
+
})}
|
|
174
|
+
</Tab.Navigator>
|
|
175
|
+
);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const styles = StyleSheet.create({
|
|
179
|
+
tab: {
|
|
180
|
+
height: BAR_HEIGHT,
|
|
181
|
+
paddingVertical: Spacing.XS,
|
|
182
|
+
},
|
|
183
|
+
badge: {
|
|
184
|
+
borderColor: Colors.black_01,
|
|
185
|
+
borderWidth: BADGE_BORDER_WIDTH,
|
|
186
|
+
fontSize: BADGE_FONT_SIZE,
|
|
187
|
+
lineHeight: BADGE_LINE_HEIGHT,
|
|
188
|
+
fontWeight: 'bold',
|
|
189
|
+
alignSelf: 'center',
|
|
190
|
+
fontFamily: exportFontFamily('bold'),
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
export { LegacyBottomTab };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Platform, StyleSheet } from 'react-native';
|
|
2
|
+
import { Colors, Radius } from '../../Consts';
|
|
3
|
+
|
|
4
|
+
const styles = StyleSheet.create({
|
|
5
|
+
content: {
|
|
6
|
+
flex: 1,
|
|
7
|
+
flexDirection: 'row',
|
|
8
|
+
},
|
|
9
|
+
tabBar: {
|
|
10
|
+
left: 0,
|
|
11
|
+
right: 0,
|
|
12
|
+
bottom: 0,
|
|
13
|
+
borderTopWidth: StyleSheet.hairlineWidth,
|
|
14
|
+
elevation: 8,
|
|
15
|
+
},
|
|
16
|
+
tabBarFloatingButton: {
|
|
17
|
+
left: 0,
|
|
18
|
+
right: 0,
|
|
19
|
+
bottom: 0,
|
|
20
|
+
zIndex: 1,
|
|
21
|
+
shadowColor: Colors.black_20,
|
|
22
|
+
shadowOffset: { width: 0, height: -2 },
|
|
23
|
+
shadowOpacity: 0.05,
|
|
24
|
+
shadowRadius: 3,
|
|
25
|
+
elevation: 8,
|
|
26
|
+
},
|
|
27
|
+
floatingContainer: {
|
|
28
|
+
position: 'absolute',
|
|
29
|
+
alignItems: 'center',
|
|
30
|
+
left: 0,
|
|
31
|
+
right: 0,
|
|
32
|
+
top: -2,
|
|
33
|
+
bottom: Platform.OS === 'ios' ? -6 : 4,
|
|
34
|
+
},
|
|
35
|
+
floatingContent: {
|
|
36
|
+
alignItems: 'center',
|
|
37
|
+
justifyContent: 'center',
|
|
38
|
+
height: 48,
|
|
39
|
+
width: 48,
|
|
40
|
+
borderRadius: 24,
|
|
41
|
+
top: -10,
|
|
42
|
+
},
|
|
43
|
+
floatingLabel: {
|
|
44
|
+
top: -4,
|
|
45
|
+
borderRadius: Radius.XL,
|
|
46
|
+
paddingHorizontal: 6,
|
|
47
|
+
},
|
|
48
|
+
indicatorContainer: {
|
|
49
|
+
position: 'absolute',
|
|
50
|
+
top: 0,
|
|
51
|
+
},
|
|
52
|
+
indicator: {
|
|
53
|
+
height: 2,
|
|
54
|
+
width: 44,
|
|
55
|
+
alignSelf: 'center',
|
|
56
|
+
borderBottomLeftRadius: 1,
|
|
57
|
+
borderBottomRightRadius: 1,
|
|
58
|
+
},
|
|
59
|
+
debugBaseLine: { borderWidth: 1, borderColor: Colors.green_06 },
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export { styles };
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import React, { useContext, useEffect } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Platform,
|
|
4
|
+
type StyleProp,
|
|
5
|
+
StyleSheet,
|
|
6
|
+
TouchableOpacity,
|
|
7
|
+
useWindowDimensions,
|
|
8
|
+
View,
|
|
9
|
+
type ViewStyle,
|
|
10
|
+
} from 'react-native';
|
|
11
|
+
import { type BottomTabBarProps } from '@react-navigation/bottom-tabs';
|
|
12
|
+
import { CommonActions, type Route } from '@react-navigation/native';
|
|
13
|
+
import Animated, {
|
|
14
|
+
useAnimatedStyle,
|
|
15
|
+
useSharedValue,
|
|
16
|
+
withTiming,
|
|
17
|
+
} from 'react-native-reanimated';
|
|
18
|
+
import {
|
|
19
|
+
type EdgeInsets,
|
|
20
|
+
useSafeAreaInsets,
|
|
21
|
+
} from 'react-native-safe-area-context';
|
|
22
|
+
import { Colors, Styles } from '../../Consts';
|
|
23
|
+
import { Icon } from '../../Icon';
|
|
24
|
+
import { Text } from '../../Text';
|
|
25
|
+
import { ApplicationContext, MiniAppContext } from '../../Context';
|
|
26
|
+
import { type FloatingButtonProps } from '../types';
|
|
27
|
+
import { LegacyBottomTabItem } from './LegacyBottomTabItem';
|
|
28
|
+
import { styles } from './LegacyBottomTabBar.styles';
|
|
29
|
+
|
|
30
|
+
const INDICATOR_DURATION = 200;
|
|
31
|
+
const FLOATING_ICON_SIZE = 32;
|
|
32
|
+
const IOS_BOTTOM_INSET_TRIM = 4;
|
|
33
|
+
|
|
34
|
+
type Props = BottomTabBarProps & {
|
|
35
|
+
activeTintColor?: string;
|
|
36
|
+
inactiveTintColor?: string;
|
|
37
|
+
floatingButton?: FloatingButtonProps;
|
|
38
|
+
style?: StyleProp<ViewStyle>;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Bottom padding of the docked bar: the home indicator inset, trimmed on iOS.
|
|
43
|
+
*/
|
|
44
|
+
const getPaddingBottom = (insets: EdgeInsets) => {
|
|
45
|
+
const trim = Platform.select({ ios: IOS_BOTTOM_INSET_TRIM, default: 0 });
|
|
46
|
+
return Math.max(insets.bottom - trim, 0);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Pre-redesign phone tab bar: full-width docked bar with a 44x2 sliding top
|
|
51
|
+
* indicator and the round floating button in the middle (even tab counts only).
|
|
52
|
+
* `floatingButton.labelContent` has no legacy meaning and is ignored.
|
|
53
|
+
*/
|
|
54
|
+
const LegacyBottomTabBar = ({
|
|
55
|
+
state,
|
|
56
|
+
navigation,
|
|
57
|
+
descriptors,
|
|
58
|
+
activeTintColor,
|
|
59
|
+
inactiveTintColor,
|
|
60
|
+
style,
|
|
61
|
+
floatingButton,
|
|
62
|
+
}: Props) => {
|
|
63
|
+
const { theme } = useContext(ApplicationContext);
|
|
64
|
+
const context = useContext<any>(MiniAppContext);
|
|
65
|
+
const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false;
|
|
66
|
+
const { routes } = state;
|
|
67
|
+
const widthDevice = useWindowDimensions().width;
|
|
68
|
+
const insets = useSafeAreaInsets();
|
|
69
|
+
const hasFloating = !!floatingButton && routes.length % 2 === 0;
|
|
70
|
+
const slotCount = routes.length + (hasFloating ? 1 : 0);
|
|
71
|
+
const itemWidth = (widthDevice - insets.left - insets.right) / slotCount;
|
|
72
|
+
const activeTint = activeTintColor ?? theme.colors.primary;
|
|
73
|
+
const indicatorAnimated = useSharedValue(0);
|
|
74
|
+
|
|
75
|
+
const indicatorStyle = useAnimatedStyle(() => ({
|
|
76
|
+
width: itemWidth,
|
|
77
|
+
transform: [{ translateX: indicatorAnimated.value }],
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
let slot = state.index;
|
|
82
|
+
if (hasFloating && slot > (routes.length - 1) / 2) {
|
|
83
|
+
slot += 1;
|
|
84
|
+
}
|
|
85
|
+
indicatorAnimated.value = withTiming(itemWidth * slot, {
|
|
86
|
+
duration: INDICATOR_DURATION,
|
|
87
|
+
});
|
|
88
|
+
}, [state.index, itemWidth, indicatorAnimated, hasFloating, routes.length]);
|
|
89
|
+
|
|
90
|
+
const renderTabItems = (data: Route<string>[]) => {
|
|
91
|
+
return data.map(route => {
|
|
92
|
+
const focused = state.routes[state.index]?.key === route.key;
|
|
93
|
+
const { options } = descriptors[route.key];
|
|
94
|
+
|
|
95
|
+
const handlePress = () => {
|
|
96
|
+
const event = navigation.emit({
|
|
97
|
+
type: 'tabPress',
|
|
98
|
+
target: route.key,
|
|
99
|
+
canPreventDefault: true,
|
|
100
|
+
});
|
|
101
|
+
if (!focused && !event.defaultPrevented) {
|
|
102
|
+
navigation.dispatch({
|
|
103
|
+
...CommonActions.navigate(route.name),
|
|
104
|
+
target: state.key,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const handleLongPress = () => {
|
|
110
|
+
navigation.emit({ type: 'tabLongPress', target: route.key });
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<LegacyBottomTabItem
|
|
115
|
+
key={route.key}
|
|
116
|
+
route={route}
|
|
117
|
+
label={options.tabBarLabel || options.title || route.name}
|
|
118
|
+
focused={focused}
|
|
119
|
+
onPress={handlePress}
|
|
120
|
+
onLongPress={handleLongPress}
|
|
121
|
+
activeTintColor={activeTint}
|
|
122
|
+
inactiveTintColor={inactiveTintColor ?? theme.colors.text.default}
|
|
123
|
+
icon={options.tabBarIcon}
|
|
124
|
+
badge={options.tabBarBadge}
|
|
125
|
+
style={options.tabBarStyle as StyleProp<ViewStyle>}
|
|
126
|
+
badgeStyle={StyleSheet.flatten(options.tabBarBadgeStyle) as ViewStyle}
|
|
127
|
+
/>
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const renderFloatingButton = () => {
|
|
133
|
+
const icon =
|
|
134
|
+
typeof floatingButton?.icon === 'string' ? (
|
|
135
|
+
<Icon
|
|
136
|
+
source={floatingButton.icon}
|
|
137
|
+
size={FLOATING_ICON_SIZE}
|
|
138
|
+
color={Colors.black_01}
|
|
139
|
+
/>
|
|
140
|
+
) : (
|
|
141
|
+
floatingButton?.icon
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<View style={[Styles.flex, showBaseLineDebug && styles.debugBaseLine]}>
|
|
146
|
+
<TouchableOpacity
|
|
147
|
+
onPress={floatingButton?.onPress}
|
|
148
|
+
style={styles.floatingContainer}
|
|
149
|
+
>
|
|
150
|
+
<View
|
|
151
|
+
style={[styles.floatingContent, { backgroundColor: activeTint }]}
|
|
152
|
+
>
|
|
153
|
+
{icon}
|
|
154
|
+
</View>
|
|
155
|
+
<View style={[styles.floatingLabel, { backgroundColor: activeTint }]}>
|
|
156
|
+
<Text
|
|
157
|
+
numberOfLines={1}
|
|
158
|
+
typography={'description_xs_regular'}
|
|
159
|
+
color={Colors.black_01}
|
|
160
|
+
>
|
|
161
|
+
{floatingButton?.label}
|
|
162
|
+
</Text>
|
|
163
|
+
</View>
|
|
164
|
+
</TouchableOpacity>
|
|
165
|
+
</View>
|
|
166
|
+
);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
const renderTabs = () => {
|
|
170
|
+
if (!hasFloating) {
|
|
171
|
+
return renderTabItems(routes);
|
|
172
|
+
}
|
|
173
|
+
const middle = routes.length / 2;
|
|
174
|
+
return (
|
|
175
|
+
<>
|
|
176
|
+
{renderTabItems(routes.slice(0, middle))}
|
|
177
|
+
{renderFloatingButton()}
|
|
178
|
+
{renderTabItems(routes.slice(middle))}
|
|
179
|
+
</>
|
|
180
|
+
);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<View
|
|
185
|
+
style={[
|
|
186
|
+
floatingButton ? styles.tabBarFloatingButton : styles.tabBar,
|
|
187
|
+
{
|
|
188
|
+
backgroundColor: theme.colors.background.surface,
|
|
189
|
+
borderTopColor: theme.colors.border.default,
|
|
190
|
+
paddingBottom: getPaddingBottom(insets),
|
|
191
|
+
paddingLeft: insets.left,
|
|
192
|
+
paddingRight: insets.right,
|
|
193
|
+
},
|
|
194
|
+
style,
|
|
195
|
+
]}
|
|
196
|
+
pointerEvents={'auto'}
|
|
197
|
+
>
|
|
198
|
+
<View style={styles.content} accessibilityLabel={'bottom_tab_bar'}>
|
|
199
|
+
<Animated.View style={[styles.indicatorContainer, indicatorStyle]}>
|
|
200
|
+
<View style={[styles.indicator, { backgroundColor: activeTint }]} />
|
|
201
|
+
</Animated.View>
|
|
202
|
+
{renderTabs()}
|
|
203
|
+
</View>
|
|
204
|
+
</View>
|
|
205
|
+
);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
export { LegacyBottomTabBar };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
type StyleProp,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
TouchableOpacity,
|
|
6
|
+
type ViewStyle,
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
import { type BottomTabNavigationOptions } from '@react-navigation/bottom-tabs';
|
|
9
|
+
import { type Route } from '@react-navigation/native';
|
|
10
|
+
import { Text } from '../../Text';
|
|
11
|
+
import { MiniAppContext } from '../../Context';
|
|
12
|
+
import { Colors, Spacing } from '../../Consts';
|
|
13
|
+
import { LegacyTabBarIcon } from './LegacyTabBarIcon';
|
|
14
|
+
|
|
15
|
+
type LabelType = NonNullable<BottomTabNavigationOptions['tabBarLabel']>;
|
|
16
|
+
|
|
17
|
+
type Props = {
|
|
18
|
+
route: Route<string>;
|
|
19
|
+
focused: boolean;
|
|
20
|
+
label: LabelType;
|
|
21
|
+
onPress: () => void;
|
|
22
|
+
onLongPress: () => void;
|
|
23
|
+
activeTintColor: string;
|
|
24
|
+
inactiveTintColor: string;
|
|
25
|
+
icon: BottomTabNavigationOptions['tabBarIcon'];
|
|
26
|
+
badge?: string | number;
|
|
27
|
+
style?: StyleProp<ViewStyle>;
|
|
28
|
+
badgeStyle?: ViewStyle;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Pre-redesign tab button: icon with badge over a one-line label, filling an
|
|
33
|
+
* equal share of the docked bar.
|
|
34
|
+
*/
|
|
35
|
+
const LegacyBottomTabItem = ({
|
|
36
|
+
route,
|
|
37
|
+
focused,
|
|
38
|
+
label,
|
|
39
|
+
onPress,
|
|
40
|
+
onLongPress,
|
|
41
|
+
activeTintColor,
|
|
42
|
+
inactiveTintColor,
|
|
43
|
+
icon,
|
|
44
|
+
badge,
|
|
45
|
+
style,
|
|
46
|
+
badgeStyle,
|
|
47
|
+
}: Props) => {
|
|
48
|
+
const context = useContext<any>(MiniAppContext);
|
|
49
|
+
const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false;
|
|
50
|
+
const color = focused ? activeTintColor : inactiveTintColor;
|
|
51
|
+
|
|
52
|
+
const renderLabel = () => {
|
|
53
|
+
if (typeof label === 'string') {
|
|
54
|
+
return (
|
|
55
|
+
<Text
|
|
56
|
+
numberOfLines={1}
|
|
57
|
+
color={color}
|
|
58
|
+
typography={focused ? 'label_xs_medium' : 'description_xs_regular'}
|
|
59
|
+
>
|
|
60
|
+
{label}
|
|
61
|
+
</Text>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
return label({
|
|
65
|
+
focused,
|
|
66
|
+
color,
|
|
67
|
+
children: route.name,
|
|
68
|
+
position: 'below-icon',
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<TouchableOpacity
|
|
74
|
+
onPress={onPress}
|
|
75
|
+
onLongPress={onLongPress}
|
|
76
|
+
style={[
|
|
77
|
+
styles.container,
|
|
78
|
+
style,
|
|
79
|
+
showBaseLineDebug && styles.debugBaseLine,
|
|
80
|
+
]}
|
|
81
|
+
>
|
|
82
|
+
{icon && (
|
|
83
|
+
<LegacyTabBarIcon
|
|
84
|
+
badge={badge}
|
|
85
|
+
badgeStyle={badgeStyle}
|
|
86
|
+
activeOpacity={focused ? 1 : 0}
|
|
87
|
+
inactiveOpacity={focused ? 0 : 1}
|
|
88
|
+
activeTintColor={activeTintColor}
|
|
89
|
+
inactiveTintColor={inactiveTintColor}
|
|
90
|
+
renderIcon={icon}
|
|
91
|
+
/>
|
|
92
|
+
)}
|
|
93
|
+
{renderLabel()}
|
|
94
|
+
</TouchableOpacity>
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const styles = StyleSheet.create({
|
|
99
|
+
container: {
|
|
100
|
+
flex: 1,
|
|
101
|
+
alignItems: 'center',
|
|
102
|
+
justifyContent: 'center',
|
|
103
|
+
paddingVertical: Spacing.S,
|
|
104
|
+
bottom: -2,
|
|
105
|
+
},
|
|
106
|
+
debugBaseLine: { borderWidth: 1, borderColor: Colors.green_06 },
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
export { LegacyBottomTabItem };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type StyleProp, StyleSheet, View, type ViewStyle } from 'react-native';
|
|
3
|
+
import { Colors } from '../../Consts';
|
|
4
|
+
import { Badge, BadgeDot } from '../../Badge';
|
|
5
|
+
|
|
6
|
+
const ICON_SIZE = 25;
|
|
7
|
+
const ICON_WRAPPER_SIZE = 35;
|
|
8
|
+
const BADGE_OFFSET = -3;
|
|
9
|
+
|
|
10
|
+
type Props = {
|
|
11
|
+
badge?: string | number;
|
|
12
|
+
badgeStyle?: ViewStyle;
|
|
13
|
+
activeOpacity: number;
|
|
14
|
+
inactiveOpacity: number;
|
|
15
|
+
activeTintColor?: string;
|
|
16
|
+
inactiveTintColor?: string;
|
|
17
|
+
renderIcon: (props: {
|
|
18
|
+
focused: boolean;
|
|
19
|
+
color: string;
|
|
20
|
+
size: number;
|
|
21
|
+
}) => React.ReactNode;
|
|
22
|
+
style?: StyleProp<ViewStyle>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Pre-redesign tab icon: active and inactive icons stacked and faded by
|
|
27
|
+
* opacity, with the old corner Badge ('' renders a dot).
|
|
28
|
+
*/
|
|
29
|
+
const LegacyTabBarIcon = ({
|
|
30
|
+
badge,
|
|
31
|
+
badgeStyle,
|
|
32
|
+
activeOpacity,
|
|
33
|
+
inactiveOpacity,
|
|
34
|
+
activeTintColor,
|
|
35
|
+
inactiveTintColor,
|
|
36
|
+
renderIcon,
|
|
37
|
+
style,
|
|
38
|
+
}: Props) => {
|
|
39
|
+
const renderBadge = () => {
|
|
40
|
+
if (badge == null) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (badge === '') {
|
|
44
|
+
return (
|
|
45
|
+
<BadgeDot size={'small'} style={{ ...styles.badge, ...badgeStyle }} />
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return (
|
|
49
|
+
<Badge style={{ ...styles.badge, ...badgeStyle }} label={`${badge}`} />
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<View style={[styles.wrapper, style]}>
|
|
55
|
+
<View
|
|
56
|
+
style={[styles.icon, { opacity: activeOpacity, minWidth: ICON_SIZE }]}
|
|
57
|
+
>
|
|
58
|
+
{renderIcon({
|
|
59
|
+
focused: true,
|
|
60
|
+
size: ICON_SIZE,
|
|
61
|
+
color: activeTintColor ?? Colors.black_20,
|
|
62
|
+
})}
|
|
63
|
+
</View>
|
|
64
|
+
<View style={[styles.icon, { opacity: inactiveOpacity }]}>
|
|
65
|
+
{renderIcon({
|
|
66
|
+
focused: false,
|
|
67
|
+
size: ICON_SIZE,
|
|
68
|
+
color: inactiveTintColor ?? Colors.black_04,
|
|
69
|
+
})}
|
|
70
|
+
</View>
|
|
71
|
+
{renderBadge()}
|
|
72
|
+
</View>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const styles = StyleSheet.create({
|
|
77
|
+
icon: {
|
|
78
|
+
position: 'absolute',
|
|
79
|
+
alignSelf: 'center',
|
|
80
|
+
alignItems: 'center',
|
|
81
|
+
justifyContent: 'center',
|
|
82
|
+
height: '100%',
|
|
83
|
+
width: '100%',
|
|
84
|
+
},
|
|
85
|
+
wrapper: {
|
|
86
|
+
width: ICON_WRAPPER_SIZE,
|
|
87
|
+
height: ICON_WRAPPER_SIZE,
|
|
88
|
+
},
|
|
89
|
+
badge: {
|
|
90
|
+
position: 'absolute',
|
|
91
|
+
end: BADGE_OFFSET,
|
|
92
|
+
top: BADGE_OFFSET,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
export { LegacyTabBarIcon };
|
|
@@ -13,6 +13,9 @@ import { Text } from '../../Text';
|
|
|
13
13
|
import ScaleSizeProvider from '../ScaleSizeProvider';
|
|
14
14
|
import { TabBarMetrics, TabBarMotion } from './metrics';
|
|
15
15
|
|
|
16
|
+
// text badges keep 5 characters, then "..." ("Khám phá" -> "Khám...")
|
|
17
|
+
const BADGE_MAX_CHARS = 5;
|
|
18
|
+
|
|
16
19
|
type Props = {
|
|
17
20
|
focused: boolean;
|
|
18
21
|
// '' shows a dot, anything else a label badge
|
|
@@ -30,7 +33,7 @@ type Props = {
|
|
|
30
33
|
|
|
31
34
|
/**
|
|
32
35
|
* Badge value of a tab: undefined hides it, '' is a dot (also 0 when `showDot`), numbers
|
|
33
|
-
* cap at 99
|
|
36
|
+
* cap at 99+, text keeps its first 5 characters.
|
|
34
37
|
*/
|
|
35
38
|
export const getTabBadge = (
|
|
36
39
|
badgeLabel?: string | number,
|
|
@@ -50,7 +53,9 @@ export const getTabBadge = (
|
|
|
50
53
|
}
|
|
51
54
|
return value > 99 ? '99+' : text;
|
|
52
55
|
}
|
|
53
|
-
return text
|
|
56
|
+
return text.length > BADGE_MAX_CHARS
|
|
57
|
+
? `${text.slice(0, BADGE_MAX_CHARS).trimEnd()}...`
|
|
58
|
+
: text;
|
|
54
59
|
};
|
|
55
60
|
|
|
56
61
|
/**
|
|
@@ -21,6 +21,7 @@ import { getTabBadge } from './TabBarIcon';
|
|
|
21
21
|
import { DuoTabBar, useDuoTabBarInset } from './DuoTabBar';
|
|
22
22
|
import { BottomTabInsetContext } from './BottomTabInset';
|
|
23
23
|
import { DuoBarCompressionProvider } from './DuoBarCompression';
|
|
24
|
+
import { LegacyBottomTab } from './LegacyBottomTab';
|
|
24
25
|
import TabScreen from './TabScreen';
|
|
25
26
|
import { ApplicationContext } from '../../Context';
|
|
26
27
|
import { useScreenLayout } from '../../Layout';
|
|
@@ -58,7 +59,7 @@ const getTabSlide = (width: number): SceneInterpolator => {
|
|
|
58
59
|
* App tab navigator: the floating bar on phones, the rail or floating bar on
|
|
59
60
|
* iPhone Duo, tabs sliding in index order. Shares the bar inset with its tabs.
|
|
60
61
|
*/
|
|
61
|
-
const
|
|
62
|
+
const FloatingBottomTab: React.FC<BottomTabProps> = ({
|
|
62
63
|
nested,
|
|
63
64
|
tabs,
|
|
64
65
|
listeners,
|
|
@@ -190,4 +191,16 @@ const BottomTab: React.FC<BottomTabProps> = ({
|
|
|
190
191
|
);
|
|
191
192
|
};
|
|
192
193
|
|
|
194
|
+
/**
|
|
195
|
+
* App tab navigator. `useLegacy` renders the pre-redesign docked bar on phones;
|
|
196
|
+
* iPhone Duo always uses the current rail or floating bar.
|
|
197
|
+
*/
|
|
198
|
+
const BottomTab: React.FC<BottomTabProps> = props => {
|
|
199
|
+
const { isIPhoneDuo } = useScreenLayout();
|
|
200
|
+
if (props.useLegacy && !isIPhoneDuo) {
|
|
201
|
+
return <LegacyBottomTab {...props} />;
|
|
202
|
+
}
|
|
203
|
+
return <FloatingBottomTab {...props} />;
|
|
204
|
+
};
|
|
205
|
+
|
|
193
206
|
export default BottomTab;
|
|
@@ -33,6 +33,11 @@ export type BottomTabProps = {
|
|
|
33
33
|
* tapping the compressed one swaps them. Defaults to 'toolbar'
|
|
34
34
|
*/
|
|
35
35
|
compressionBehavior?: 'toolbar' | 'tabBar';
|
|
36
|
+
/**
|
|
37
|
+
* Renders the pre-redesign docked phone bar instead of the floating one. Ignores
|
|
38
|
+
* `showDot`, `floatingButton.labelContent` and `compressionBehavior`; not on iPhone Duo. Defaults to false.
|
|
39
|
+
*/
|
|
40
|
+
useLegacy?: boolean;
|
|
36
41
|
};
|
|
37
42
|
|
|
38
43
|
export type FloatingButtonProps = {
|