@momo-kits/foundation 0.169.17-beta.1 → 0.169.17-beta.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.
- package/Application/BottomSheet.tsx +2 -2
- package/Application/BottomTab/BottomTabBar.styles.ts +1 -1
- package/Application/BottomTab/DuoTabBar.styles.ts +1 -1
- package/Application/BottomTab/TabBarIcon.tsx +1 -1
- package/Application/BottomTab/index.tsx +1 -15
- package/Application/Components/HeaderExtendHeader.tsx +1 -3
- package/Application/Components/HeaderRight.tsx +3 -24
- package/Application/Components/SearchHeader.tsx +2 -3
- package/Application/ModalScreen.tsx +2 -2
- package/Application/StackScreen.tsx +6 -2
- package/Application/TooltipPortal.tsx +3 -3
- package/Application/headerLayout.ts +3 -7
- package/Application/hooks.ts +1 -1
- package/Application/types.tabs.ts +0 -8
- package/Button/index.tsx +2 -2
- package/Divider/DashDivider.tsx +2 -2
- package/Divider/index.tsx +3 -3
- package/FoundationList/index.tsx +1 -1
- package/Icon/types.ts +1 -2
- package/Image/index.tsx +70 -7
- package/Image/styles.ts +2 -0
- package/Image/types.ts +9 -1
- package/Input/Input.tsx +2 -2
- package/Input/InputMoney.tsx +7 -2
- package/Input/InputMoneyView.tsx +2 -2
- package/Input/InputOTP.tsx +2 -2
- package/Input/InputPhoneNumber.tsx +2 -2
- package/Input/InputSearch.tsx +2 -2
- package/Input/InputTextArea.tsx +2 -2
- package/Input/SearchTextTyping.tsx +2 -2
- package/Input/SystemTextInput.tsx +2 -1
- package/Input/TextTyping.tsx +7 -2
- package/Layout/screenHeader.tsx +41 -56
- package/Pagination/types.ts +6 -2
- package/Text/utils.ts +4 -30
- package/package.json +28 -26
- package/Application/BottomTab/Legacy/BottomTabBar.styles.ts +0 -60
- package/Application/BottomTab/Legacy/BottomTabBar.tsx +0 -270
- package/Application/BottomTab/Legacy/CustomBottomTabItem.tsx +0 -153
- package/Application/BottomTab/Legacy/DuoBarCompression.tsx +0 -135
- package/Application/BottomTab/Legacy/DuoRailTabBar.tsx +0 -149
- package/Application/BottomTab/Legacy/DuoTabBar.parts.tsx +0 -202
- package/Application/BottomTab/Legacy/DuoTabBar.styles.ts +0 -123
- package/Application/BottomTab/Legacy/DuoTabBar.tsx +0 -151
- package/Application/BottomTab/Legacy/TabBarIcon.tsx +0 -113
- package/Application/BottomTab/Legacy/TabScreen.tsx +0 -177
- package/Application/BottomTab/Legacy/badge.ts +0 -41
- package/Application/BottomTab/Legacy/hooks.ts +0 -358
- package/Application/BottomTab/Legacy/index.styles.ts +0 -30
- package/Application/BottomTab/Legacy/index.tsx +0 -230
- package/Application/Components/useHeaderRightWidth.ts +0 -46
|
@@ -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;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { useCallback, useContext, useSyncExternalStore } from 'react';
|
|
2
|
-
import { NavigationRouteContext } from '@react-navigation/native';
|
|
3
|
-
|
|
4
|
-
const widths = new Map<string, number>();
|
|
5
|
-
const listeners = new Set<() => void>();
|
|
6
|
-
|
|
7
|
-
const notify = () => {
|
|
8
|
-
listeners.forEach(listener => listener());
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const subscribe = (listener: () => void) => {
|
|
12
|
-
listeners.add(listener);
|
|
13
|
-
return () => {
|
|
14
|
-
listeners.delete(listener);
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Records the laid out width of a route's header right, side padding included;
|
|
20
|
-
* `undefined` clears it when the header right unmounts.
|
|
21
|
-
*/
|
|
22
|
-
const setHeaderRightWidth = (routeKey: string, width?: number) => {
|
|
23
|
-
if (widths.get(routeKey) === width) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (width === undefined) {
|
|
27
|
-
widths.delete(routeKey);
|
|
28
|
-
} else {
|
|
29
|
-
widths.set(routeKey, width);
|
|
30
|
-
}
|
|
31
|
-
notify();
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Measured header right width of the current route, so searches stop short of
|
|
36
|
-
* the shortcut and toolkit. `undefined` until the header right lays out.
|
|
37
|
-
*/
|
|
38
|
-
const useHeaderRightWidth = (): number | undefined => {
|
|
39
|
-
const routeKey = useContext(NavigationRouteContext)?.key;
|
|
40
|
-
const getSnapshot = useCallback(() => {
|
|
41
|
-
return routeKey ? widths.get(routeKey) : undefined;
|
|
42
|
-
}, [routeKey]);
|
|
43
|
-
return useSyncExternalStore(subscribe, getSnapshot);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export { setHeaderRightWidth, useHeaderRightWidth };
|