@momo-kits/foundation 0.169.12-beta.7 → 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.
@@ -21,7 +21,6 @@ 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';
25
24
  import TabScreen from './TabScreen';
26
25
  import { ApplicationContext } from '../../Context';
27
26
  import { useScreenLayout } from '../../Layout';
@@ -59,7 +58,7 @@ const getTabSlide = (width: number): SceneInterpolator => {
59
58
  * App tab navigator: the floating bar on phones, the rail or floating bar on
60
59
  * iPhone Duo, tabs sliding in index order. Shares the bar inset with its tabs.
61
60
  */
62
- const FloatingBottomTab: React.FC<BottomTabProps> = ({
61
+ const BottomTab: React.FC<BottomTabProps> = ({
63
62
  nested,
64
63
  tabs,
65
64
  listeners,
@@ -191,17 +190,4 @@ const FloatingBottomTab: React.FC<BottomTabProps> = ({
191
190
  );
192
191
  };
193
192
 
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
-
207
193
  export default BottomTab;
@@ -33,17 +33,9 @@ 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;
42
36
  };
43
37
 
44
38
  export type FloatingButtonProps = {
45
- /** Legacy bar only (`useLegacy`): custom background drawn behind the bar, e.g. a curved cutout */
46
- container?: React.ReactNode;
47
39
  icon: string | React.ReactNode;
48
40
  label: string;
49
41
  onPress: () => void;
@@ -4,9 +4,9 @@ import { StackNavigationOptions } from '@react-navigation/stack';
4
4
  import type { SharedValue } from 'react-native-reanimated';
5
5
  import Navigation from '../Application/Navigation';
6
6
  import { AnimatedHeader, SearchHeaderProps } from '../Application/types';
7
- import { exportHeaderTitle } from '../Application/navigationOptions';
8
7
  import { Colors, Spacing } from '../Consts';
9
8
  import {
9
+ exportHeaderTitle,
10
10
  HeaderBackground,
11
11
  HeaderLeft,
12
12
  HeaderTitle,
@@ -63,8 +63,9 @@ const getSearchTitleOptions = (
63
63
  };
64
64
 
65
65
  /**
66
- * Applies the Screen's navigation header (plain, extended, animated banner or search) and
67
- * re-applies it when those props change. Returns the search header setter and the tint.
66
+ * Applies the Screen's navigation header (plain, extended, animated banner or search), with
67
+ * a ref search header on top, and re-applies it on prop or layout change. Returns the
68
+ * search header setter and the tint.
68
69
  */
69
70
  export const useScreenHeader = ({
70
71
  navigation,
@@ -83,6 +84,7 @@ export const useScreenHeader = ({
83
84
  }: ScreenHeaderParams) => {
84
85
  const currentTint = useRef<string | undefined>(undefined);
85
86
  const appliedHeaderMode = useRef<string | undefined>(undefined);
87
+ const searchHeaderParams = useRef<SearchHeaderProps | undefined>(undefined);
86
88
  const headerLayout = useHeaderLayout(contentLayout);
87
89
  const frameOptions = useHeaderFrameOptions(contentLayout);
88
90
 
@@ -243,45 +245,54 @@ export const useScreenHeader = ({
243
245
  }, [navigation?.instance, sharedValue, frameOptions]);
244
246
 
245
247
  // the search field spans the content (or the stretch frame), clear of the side bar
246
- // and status bar clusters
247
- const setSearchHeader = (params: SearchHeaderProps) => {
248
- let searchWidth = headerLayout.frameWidth;
249
- let searchLeft = Spacing.M;
250
- if (layout.sideBar) {
251
- searchWidth = layout.contentWidth - Spacing.M * 2;
252
- searchLeft = Spacing.M - getHeaderMargin(layout.width);
253
- }
254
- const clearance = layout.statusBarClearance;
255
- if (clearance) {
256
- searchWidth -= clearance.left + clearance.right;
257
- }
258
- const options: StackNavigationOptions = {
259
- ...frameOptions,
260
- headerRight: undefined,
261
- headerTitleContainerStyle: {
262
- width: searchWidth,
263
- maxWidth: searchWidth,
264
- marginLeft: 0,
265
- marginEnd: 0,
266
- marginStart: 0,
267
- marginHorizontal: 0,
268
- marginVertical: 0,
269
- margin: 0,
270
- left: searchLeft,
271
- },
272
- headerLeft: (props: any) => {
273
- if (params?.hiddenBack) {
274
- return null;
275
- }
276
- return <HeaderLeft {...props} floating />;
277
- },
278
- headerTitle: () => (
279
- <SearchHeader {...params} animatedValue={sharedValue} />
280
- ),
281
- };
248
+ // and status bar clusters; kept as numbers so the setter below stays stable
249
+ let searchWidth = headerLayout.frameWidth;
250
+ let searchLeft = Spacing.M;
251
+ if (layout.sideBar) {
252
+ searchWidth = layout.contentWidth - Spacing.M * 2;
253
+ searchLeft = Spacing.M - getHeaderMargin(layout.width);
254
+ }
255
+ const clearance = layout.statusBarClearance;
256
+ if (clearance) {
257
+ searchWidth -= clearance.left + clearance.right;
258
+ }
282
259
 
283
- navigation?.instance?.setOptions(options);
284
- };
260
+ /**
261
+ * Shows the search header and keeps its params: the header effect puts it back over the
262
+ * base header, so a call made before that effect, or a resize, does not lose it.
263
+ */
264
+ const setSearchHeader = useCallback(
265
+ (params: SearchHeaderProps) => {
266
+ searchHeaderParams.current = params;
267
+ const options: StackNavigationOptions = {
268
+ ...frameOptions,
269
+ headerRight: undefined,
270
+ headerTitleContainerStyle: {
271
+ width: searchWidth,
272
+ maxWidth: searchWidth,
273
+ marginLeft: 0,
274
+ marginEnd: 0,
275
+ marginStart: 0,
276
+ marginHorizontal: 0,
277
+ marginVertical: 0,
278
+ margin: 0,
279
+ left: searchLeft,
280
+ },
281
+ headerLeft: (props: any) => {
282
+ if (params?.hiddenBack) {
283
+ return null;
284
+ }
285
+ return <HeaderLeft {...props} floating />;
286
+ },
287
+ headerTitle: () => (
288
+ <SearchHeader {...params} animatedValue={sharedValue} />
289
+ ),
290
+ };
291
+
292
+ navigation?.instance?.setOptions(options);
293
+ },
294
+ [navigation?.instance, sharedValue, frameOptions, searchWidth, searchLeft],
295
+ );
285
296
 
286
297
  useEffect(() => {
287
298
  const focus = navigation?.instance?.addListener?.('focus', () => {
@@ -302,6 +313,9 @@ export const useScreenHeader = ({
302
313
  setHeaderType(headerType, appliedHeaderMode.current === headerType);
303
314
  appliedHeaderMode.current = headerType;
304
315
  }
316
+ if (searchHeaderParams.current) {
317
+ setSearchHeader(searchHeaderParams.current);
318
+ }
305
319
 
306
320
  return () => {
307
321
  focus?.();
@@ -315,6 +329,7 @@ export const useScreenHeader = ({
315
329
  setAnimatedHeader,
316
330
  setAnimatedSearch,
317
331
  setHeaderType,
332
+ setSearchHeader,
318
333
  ]);
319
334
 
320
335
  return { setSearchHeader, currentTint };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.169.12-beta.7",
3
+ "version": "0.169.12",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},
@@ -1,60 +0,0 @@
1
- import { Platform, StyleSheet } from 'react-native';
2
- import { Colors, Radius } from '../../../Consts';
3
-
4
- export 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
- indicator: {
44
- height: 2,
45
- width: 44,
46
- alignSelf: 'center',
47
- borderBottomLeftRadius: 1,
48
- borderBottomRightRadius: 1,
49
- },
50
- debugBaseLine: { borderWidth: 1, borderColor: Colors.green_06 },
51
- floatingLabel: {
52
- top: -4,
53
- borderRadius: Radius.XL,
54
- paddingHorizontal: 6,
55
- },
56
- indicatorContainer: {
57
- position: 'absolute',
58
- top: 0,
59
- },
60
- });
@@ -1,270 +0,0 @@
1
- import { BottomTabBarProps } from '@react-navigation/bottom-tabs';
2
- import { CommonActions, Route } from '@react-navigation/native';
3
- import React, { useCallback, useContext } from 'react';
4
- import {
5
- Platform,
6
- TouchableOpacity,
7
- useWindowDimensions,
8
- View,
9
- } from 'react-native';
10
- import Animated, {
11
- useAnimatedStyle,
12
- useSharedValue,
13
- withTiming,
14
- } from 'react-native-reanimated';
15
- import { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';
16
- import { Styles } from '../../../Consts';
17
- import { Icon } from '../../../Icon';
18
- import { Text } from '../../../Text';
19
- import { FloatingButtonProps } from '../../types';
20
- import CustomBottomTabItem from './CustomBottomTabItem';
21
- import { ApplicationContext, MiniAppContext } from '../../../Context';
22
- import { styles } from './BottomTabBar.styles';
23
-
24
- type Props = BottomTabBarProps & {
25
- activeTintColor?: string;
26
- inactiveTintColor?: string;
27
- floatingButton?: FloatingButtonProps;
28
- activeBackgroundColor?: string;
29
- allowFontScaling?: boolean;
30
- inactiveBackgroundColor?: string;
31
- labelStyle?: any;
32
- iconStyle?: any;
33
- showLabel?: boolean;
34
- style?: any;
35
- tabStyle?: any;
36
- badgeStyle?: any;
37
- };
38
-
39
- const getPaddingBottom = (insets: EdgeInsets) => {
40
- return Math.max(insets.bottom - Platform.select({ ios: 4, default: 0 }), 0);
41
- };
42
-
43
- export default function BottomTabBar({
44
- state,
45
- navigation,
46
- descriptors,
47
- activeBackgroundColor,
48
- activeTintColor,
49
- allowFontScaling,
50
- inactiveBackgroundColor,
51
- inactiveTintColor,
52
- labelStyle,
53
- iconStyle,
54
- showLabel,
55
- style,
56
- floatingButton,
57
- }: Props) {
58
- const { theme } = useContext(ApplicationContext);
59
- const { routes } = state;
60
- const widthDevice = useWindowDimensions()?.width;
61
- const insets = useSafeAreaInsets();
62
- const useFloating = floatingButton && state.routes.length % 2 === 0;
63
- const itemWidth =
64
- (widthDevice - insets.left - insets.right) /
65
- (state.routes.length + (useFloating ? 1 : 0));
66
- // const buildLink = useLinkBuilder();
67
- const indicatorAnimated = useSharedValue(0);
68
-
69
- const indicatorStyle = useAnimatedStyle(() => ({
70
- width: itemWidth,
71
- transform: [{ translateX: indicatorAnimated.value }],
72
- }));
73
- const paddingBottom = getPaddingBottom(insets);
74
- const focusedTab = state?.routes[state.index]?.name || routes[0]?.params;
75
-
76
- const context = useContext<any>(MiniAppContext);
77
- const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false;
78
-
79
- /**
80
- * render tab item
81
- */
82
- const renderTabItem = useCallback(
83
- (data: Route<string, any>[]) => {
84
- return data?.map(route => {
85
- const focused = route?.params?.name === focusedTab;
86
- const { options } = descriptors[route.key];
87
-
88
- const onPress = () => {
89
- const event = navigation.emit({
90
- type: 'tabPress',
91
- target: route.key,
92
- canPreventDefault: true,
93
- });
94
-
95
- if (!focused && !event.defaultPrevented) {
96
- navigation.dispatch({
97
- ...CommonActions.navigate(route.name),
98
- target: state.key,
99
- });
100
- }
101
- };
102
-
103
- const onLongPress = () => {
104
- navigation.emit({
105
- type: 'tabLongPress',
106
- target: route.key,
107
- });
108
- };
109
-
110
- return (
111
- <CustomBottomTabItem
112
- key={route.key}
113
- route={route}
114
- label={options.tabBarLabel || options.title || route.name}
115
- focused={focused}
116
- onPress={onPress}
117
- onLongPress={onLongPress}
118
- activeTintColor={activeTintColor ?? theme.colors.primary}
119
- inactiveTintColor={inactiveTintColor ?? theme.colors.text.default}
120
- activeBackgroundColor={activeBackgroundColor}
121
- inactiveBackgroundColor={inactiveBackgroundColor}
122
- icon={options.tabBarIcon}
123
- badge={options.tabBarBadge}
124
- showLabel={showLabel}
125
- labelStyle={labelStyle}
126
- iconStyle={iconStyle}
127
- style={options.tabBarStyle}
128
- badgeStyle={options.tabBarBadgeStyle}
129
- allowFontScaling={allowFontScaling}
130
- />
131
- );
132
- });
133
- },
134
- [
135
- focusedTab,
136
- descriptors,
137
- activeTintColor,
138
- theme.colors.primary,
139
- theme.colors.text.default,
140
- inactiveTintColor,
141
- activeBackgroundColor,
142
- inactiveBackgroundColor,
143
- showLabel,
144
- labelStyle,
145
- iconStyle,
146
- allowFontScaling,
147
- navigation,
148
- state.key,
149
- ],
150
- );
151
-
152
- /**
153
- * render floating button
154
- */
155
- const renderFloatingButton = useCallback(() => {
156
- const renderFloatingIcon = () => {
157
- if (typeof floatingButton?.icon === 'string') {
158
- return <Icon source={floatingButton?.icon} size={32} color={'white'} />;
159
- }
160
- return floatingButton?.icon;
161
- };
162
-
163
- return (
164
- <View style={[Styles.flex, showBaseLineDebug && styles.debugBaseLine]}>
165
- <TouchableOpacity
166
- onPress={floatingButton?.onPress}
167
- style={styles.floatingContainer}
168
- >
169
- <View
170
- style={{
171
- ...styles.floatingContent,
172
- backgroundColor: activeTintColor ?? theme.colors.primary,
173
- }}
174
- >
175
- {renderFloatingIcon()}
176
- </View>
177
- <View
178
- style={[
179
- styles.floatingLabel,
180
- { backgroundColor: activeTintColor ?? theme.colors.primary },
181
- ]}
182
- >
183
- <Text
184
- numberOfLines={1}
185
- typography={'description_xs_regular'}
186
- color={'white'}
187
- >
188
- {floatingButton?.label}
189
- </Text>
190
- </View>
191
- </TouchableOpacity>
192
- </View>
193
- );
194
- }, [
195
- activeTintColor,
196
- floatingButton?.icon,
197
- floatingButton?.label,
198
- floatingButton?.onPress,
199
- showBaseLineDebug,
200
- theme.colors.primary,
201
- ]);
202
-
203
- /**
204
- * animated indicator
205
- */
206
- React.useEffect(() => {
207
- let index = state.index;
208
- if (useFloating && index > (state.routes.length - 1) / 2) {
209
- index += 1;
210
- }
211
- indicatorAnimated.value = withTiming(itemWidth * index, { duration: 200 });
212
- }, [
213
- state.index,
214
- itemWidth,
215
- indicatorAnimated,
216
- useFloating,
217
- state.routes.length,
218
- ]);
219
-
220
- /**
221
- * render tab bar
222
- */
223
- const renderTabBar = () => {
224
- if (useFloating) {
225
- const middleIndex = routes.length / 2;
226
- const leftArr = routes.slice(0, middleIndex);
227
- const rightArr = routes.slice(middleIndex);
228
- return (
229
- <>
230
- {renderTabItem(leftArr)}
231
- {renderFloatingButton()}
232
- {renderTabItem(rightArr)}
233
- </>
234
- );
235
- }
236
- return renderTabItem(routes);
237
- };
238
-
239
- return (
240
- <View
241
- style={[
242
- floatingButton ? styles.tabBarFloatingButton : styles.tabBar,
243
- {
244
- backgroundColor: theme.colors.background.surface,
245
- borderTopColor: theme.colors.border.default,
246
- },
247
- {
248
- paddingBottom: paddingBottom,
249
- paddingLeft: insets.left,
250
- paddingRight: insets.right,
251
- },
252
- style,
253
- ]}
254
- pointerEvents={'auto'}
255
- >
256
- <View style={styles.content} accessibilityLabel={'bottom_tab_bar'}>
257
- {useFloating && floatingButton?.container}
258
- <Animated.View style={[styles.indicatorContainer, indicatorStyle]}>
259
- <View
260
- style={[
261
- styles.indicator,
262
- { backgroundColor: activeTintColor ?? theme.colors.primary },
263
- ]}
264
- />
265
- </Animated.View>
266
- {renderTabBar()}
267
- </View>
268
- </View>
269
- );
270
- }
@@ -1,153 +0,0 @@
1
- import React, { useContext } from 'react';
2
- import { TouchableOpacity, StyleSheet } from 'react-native';
3
- import {
4
- BottomTabBarButtonProps,
5
- BottomTabNavigationOptions,
6
- } from '@react-navigation/bottom-tabs';
7
- import { Route } from '@react-navigation/native';
8
- import { TabBarIcon } from './TabBarIcon';
9
- import { Text } from '../../../Text';
10
- import { MiniAppContext } from '../../../Context';
11
- import { Colors } from '../../../Consts';
12
-
13
- type LabelType = NonNullable<BottomTabNavigationOptions['tabBarLabel']>;
14
-
15
- interface CustomBottomTabItemProps {
16
- route: Route<string>;
17
- focused: boolean;
18
- label: LabelType;
19
- onPress: () => void;
20
- onLongPress: () => void;
21
- activeTintColor: string;
22
- inactiveTintColor: string;
23
- activeBackgroundColor?: string;
24
- inactiveBackgroundColor?: string;
25
- icon: any;
26
- badge?: string | number;
27
- showLabel?: boolean;
28
- labelStyle?: any;
29
- iconStyle?: any;
30
- style?: any;
31
- badgeStyle?: any;
32
- allowFontScaling?: boolean;
33
- button?: (props: BottomTabBarButtonProps) => React.ReactNode;
34
- /**
35
- * The accessibility label for the tab.
36
- */
37
- accessibilityLabel?: string;
38
- /**
39
- * An unique ID for testing for the tab.
40
- */
41
- testID?: string;
42
- }
43
-
44
- const CustomBottomTabItem: React.FC<CustomBottomTabItemProps> = ({
45
- route,
46
- focused,
47
- label,
48
- onPress,
49
- onLongPress,
50
- activeTintColor,
51
- inactiveTintColor,
52
- activeBackgroundColor,
53
- inactiveBackgroundColor,
54
- icon,
55
- badge,
56
- showLabel,
57
- labelStyle,
58
- iconStyle,
59
- style,
60
- badgeStyle,
61
- allowFontScaling,
62
- }) => {
63
- const context = useContext<any>(MiniAppContext);
64
- const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false;
65
-
66
- const renderIcon = () => {
67
- if (icon === undefined) {
68
- return null;
69
- }
70
-
71
- const activeOpacity = focused ? 1 : 0;
72
- const inactiveOpacity = focused ? 0 : 1;
73
-
74
- return (
75
- <TabBarIcon
76
- route={route}
77
- badge={badge}
78
- badgeStyle={badgeStyle}
79
- activeOpacity={activeOpacity}
80
- allowFontScaling={allowFontScaling}
81
- inactiveOpacity={inactiveOpacity}
82
- activeTintColor={activeTintColor}
83
- inactiveTintColor={inactiveTintColor}
84
- renderIcon={icon}
85
- style={iconStyle}
86
- />
87
- );
88
- };
89
-
90
- const renderLabel = ({ focused: isFocused }: { focused: boolean }) => {
91
- if (showLabel === false) {
92
- return null;
93
- }
94
-
95
- const color = isFocused ? activeTintColor : inactiveTintColor;
96
-
97
- if (typeof label === 'string') {
98
- return (
99
- <Text
100
- numberOfLines={1}
101
- style={[styles.label, labelStyle]}
102
- color={isFocused ? activeTintColor : inactiveTintColor}
103
- typography={isFocused ? 'label_xs_medium' : 'description_xs_regular'}
104
- allowFontScaling={allowFontScaling}
105
- >
106
- {label}
107
- </Text>
108
- );
109
- }
110
-
111
- return label({
112
- focused: isFocused,
113
- color,
114
- children: route.name,
115
- position: 'below-icon',
116
- });
117
- };
118
-
119
- const background = focused ? activeBackgroundColor : inactiveBackgroundColor;
120
-
121
- return (
122
- <TouchableOpacity
123
- onPress={onPress}
124
- onLongPress={onLongPress}
125
- style={[
126
- styles.container,
127
- { backgroundColor: background },
128
- style,
129
- showBaseLineDebug && styles.debugBaseLine,
130
- ]}
131
- >
132
- {renderIcon()}
133
- {renderLabel({ focused })}
134
- </TouchableOpacity>
135
- );
136
- };
137
-
138
- const styles = StyleSheet.create({
139
- container: {
140
- flex: 1,
141
- alignItems: 'center',
142
- justifyContent: 'center',
143
- paddingVertical: 8,
144
- bottom: -2,
145
- },
146
- label: {
147
- fontSize: 12,
148
- fontWeight: '600',
149
- },
150
- debugBaseLine: { borderWidth: 1, borderColor: Colors.green_06 },
151
- });
152
-
153
- export default CustomBottomTabItem;