@momo-kits/foundation 0.169.12 → 0.169.13

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.
@@ -0,0 +1,230 @@
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;
@@ -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 './Legacy';
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 BottomTab: React.FC<BottomTabProps> = ({
62
+ const FloatingBottomTab: React.FC<BottomTabProps> = ({
62
63
  nested,
63
64
  tabs,
64
65
  listeners,
@@ -190,4 +191,17 @@ 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
+ // legacy unless told otherwise: the redesigned bar is not rolled out yet
201
+ if ((props.useLegacy ?? true) && !isIPhoneDuo) {
202
+ return <LegacyBottomTab {...props} />;
203
+ }
204
+ return <FloatingBottomTab {...props} />;
205
+ };
206
+
193
207
  export default BottomTab;
@@ -33,9 +33,17 @@ 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.
39
+ * Defaults to true until the redesign rolls out; pass false for the floating bar.
40
+ */
41
+ useLegacy?: boolean;
36
42
  };
37
43
 
38
44
  export type FloatingButtonProps = {
45
+ /** Legacy bar only (`useLegacy`): custom background drawn behind the bar, e.g. a curved cutout */
46
+ container?: React.ReactNode;
39
47
  icon: string | React.ReactNode;
40
48
  label: string;
41
49
  onPress: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.169.12",
3
+ "version": "0.169.13",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},