@momo-kits/foundation 0.169.12-beta.8 → 0.169.12

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.
@@ -1,230 +0,0 @@
1
- import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
2
- import { useFocusEffect } from '@react-navigation/native';
3
- import React, { useContext, useEffect, useLayoutEffect } from 'react';
4
- import { useSafeAreaInsets } from 'react-native-safe-area-context';
5
- import {
6
- NativeModules,
7
- Platform,
8
- StatusBar,
9
- useWindowDimensions,
10
- View,
11
- } from 'react-native';
12
- import Animated, {
13
- useAnimatedStyle,
14
- useSharedValue,
15
- withTiming,
16
- } from 'react-native-reanimated';
17
- import { Icon } from '../../../Icon';
18
- import { exportFontFamily, Text } from '../../../Text';
19
- import { BottomTabProps } from '../../types';
20
- import BottomTabBar from './BottomTabBar';
21
- import { DuoTabBar } from './DuoTabBar';
22
- import { DuoBarCompressionProvider } from './DuoBarCompression';
23
- import { ApplicationContext } from '../../../Context';
24
- import { useScreenLayout } from '../../../Layout';
25
- import TabScreen from './TabScreen';
26
- import { getBadgeProps } from './badge';
27
- import { styles } from './index.styles';
28
-
29
- const Tab = createBottomTabNavigator();
30
-
31
- const BottomTab: React.FC<BottomTabProps> = ({
32
- nested,
33
- tabs,
34
- listeners,
35
- navigation,
36
- initialRouteName,
37
- floatingButton,
38
- compressionBehavior,
39
- }) => {
40
- const { theme, navigator } = useContext(ApplicationContext);
41
- const { isIPhoneDuo } = useScreenLayout();
42
- const dimensions = useWindowDimensions();
43
- const insets = useSafeAreaInsets();
44
- const initialIndex = tabs.findIndex(i => i.name === initialRouteName);
45
- const indicatorAnimated = useSharedValue(0);
46
- const activeIndex = React.useRef(initialIndex > 0 ? initialIndex : 0);
47
- const itemWidth = dimensions.width / tabs.length;
48
-
49
- const indicatorStyle = useAnimatedStyle(() => ({
50
- width: itemWidth,
51
- transform: [{ translateX: indicatorAnimated.value }],
52
- }));
53
-
54
- useLayoutEffect(() => {
55
- navigation?.setOptions({
56
- headerShown: false,
57
- headerTransparent: true,
58
- headerBackground: undefined,
59
- });
60
- }, [navigation]);
61
-
62
- useEffect(() => {
63
- indicatorAnimated.value = withTiming(itemWidth * activeIndex.current, {
64
- duration: 200,
65
- });
66
- }, [itemWidth, indicatorAnimated]);
67
-
68
- // Focus, not mount: pushing a screen from a tab leaves BottomTab mounted but blurred, and
69
- // onFocus only fires on tab changes.
70
- useFocusEffect(
71
- React.useCallback(() => {
72
- NativeModules?.MiniAppModule?.setShouldUseFloatingArrowBack?.(
73
- activeIndex.current !== 0,
74
- );
75
- return () =>
76
- NativeModules?.MiniAppModule?.setShouldUseFloatingArrowBack?.(false);
77
- }, []),
78
- );
79
-
80
- const onFocus = (e: any) => {
81
- activeIndex.current = tabs.findIndex(i => e.target.includes(i.name));
82
- indicatorAnimated.value = withTiming(itemWidth * activeIndex.current, {
83
- duration: 200,
84
- });
85
-
86
- const isFirstTab = activeIndex.current === 0;
87
- const gestureEnabled = Platform.OS === 'ios' && isFirstTab;
88
- navigation?.setOptions({
89
- gestureEnabled: gestureEnabled,
90
- });
91
- NativeModules?.MiniAppModule?.setShouldUseFloatingArrowBack?.(
92
- !gestureEnabled,
93
- );
94
- };
95
-
96
- const handler: {
97
- tabPress?: (e: any) => void;
98
- focus?: (e: any) => void;
99
- blur?: (e: any) => void;
100
- state?: (e: any) => void;
101
- } = {
102
- tabPress: e => {
103
- navigator?.maxApi?.triggerEventVibration?.('light');
104
- listeners?.tabPress?.(e);
105
- },
106
- focus: e => {
107
- onFocus(e);
108
- StatusBar.setBarStyle('dark-content', true);
109
- listeners?.focus?.(e);
110
- },
111
- blur: e => {
112
- listeners?.blur?.(e);
113
- },
114
- };
115
-
116
- const isIOS = Platform.OS === 'ios';
117
- const bottomInset = isIOS ? Math.min(insets.bottom, 21) : insets.bottom;
118
-
119
- return (
120
- <DuoBarCompressionProvider
121
- behavior={compressionBehavior}
122
- tabCount={tabs.length}
123
- hasQr={!!floatingButton}
124
- >
125
- <Tab.Navigator
126
- screenOptions={{
127
- headerShown: false,
128
- headerTransparent: true,
129
- headerBackground: undefined,
130
- tabBarLabelPosition: 'below-icon',
131
- tabBarBackground: () => (
132
- <View
133
- style={[
134
- styles.container,
135
- {
136
- backgroundColor: theme.colors.background.surface,
137
- },
138
- ]}
139
- >
140
- <Animated.View
141
- style={[styles.indicatorContainer, indicatorStyle]}
142
- >
143
- <View
144
- style={[
145
- styles.indicator,
146
- { backgroundColor: theme.colors.primary },
147
- ]}
148
- />
149
- </Animated.View>
150
- </View>
151
- ),
152
- }}
153
- tabBar={props =>
154
- isIPhoneDuo ? (
155
- <DuoTabBar
156
- {...props}
157
- floatingButton={floatingButton}
158
- inactiveTintColor={theme.colors.text.hint}
159
- activeTintColor={theme.colors.primary}
160
- />
161
- ) : (
162
- <BottomTabBar
163
- {...props}
164
- floatingButton={floatingButton}
165
- inactiveTintColor={theme.colors.text.hint}
166
- activeTintColor={theme.colors.primary}
167
- style={[{ height: 64 + bottomInset }]}
168
- />
169
- )
170
- }
171
- initialRouteName={initialRouteName}
172
- >
173
- {tabs.map((item, index) => {
174
- const { badgeLabel, badgeStyle } = getBadgeProps(item?.badgeLabel);
175
-
176
- return (
177
- <Tab.Screen
178
- key={`BottomTab-${item.name}`}
179
- name={item.name}
180
- component={TabScreen}
181
- initialParams={{ ...item, nested, index }}
182
- listeners={handler}
183
- options={{
184
- tabBarLabel: ({ focused, color }) => {
185
- return (
186
- <Text
187
- numberOfLines={1}
188
- typography={
189
- focused ? 'label_xs_medium' : 'description_xs_regular'
190
- }
191
- color={color}
192
- >
193
- {item.label}
194
- </Text>
195
- );
196
- },
197
- title: item.label,
198
- tabBarStyle: [
199
- {
200
- height: 64,
201
- },
202
- styles.tabStyle,
203
- ],
204
- tabBarBadge: badgeLabel,
205
- tabBarBadgeStyle: [
206
- {
207
- borderColor: 'white',
208
- borderWidth: 2,
209
- fontSize: 10,
210
- lineHeight: 14,
211
- fontWeight: 'bold',
212
- alignSelf: 'center',
213
- fontFamily: exportFontFamily('bold'),
214
- },
215
- badgeStyle,
216
- ],
217
- tabBarIcon: ({ color }) => (
218
- <Icon source={item.icon} color={color} size={28} />
219
- ),
220
- ...item,
221
- }}
222
- />
223
- );
224
- })}
225
- </Tab.Navigator>
226
- </DuoBarCompressionProvider>
227
- );
228
- };
229
-
230
- export default BottomTab;