@momo-kits/foundation 0.168.1-beta.39 → 0.168.1-beta.40

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.
Files changed (153) hide show
  1. package/Application/BottomSheet.tsx +398 -86
  2. package/Application/BottomTab/BottomTabBar.tsx +275 -215
  3. package/Application/BottomTab/CustomBottomTabItem.tsx +107 -131
  4. package/Application/BottomTab/DuoBarCompression.tsx +28 -14
  5. package/Application/BottomTab/DuoTabBar.tsx +540 -32
  6. package/Application/BottomTab/TabBarIcon.tsx +72 -146
  7. package/Application/BottomTab/index.tsx +353 -89
  8. package/Application/BottomTab/useLiquidSelection.ts +374 -0
  9. package/Application/Components/BackgroundImageView.tsx +0 -4
  10. package/Application/Components/DuoGlassBackground.tsx +5 -7
  11. package/Application/Components/HeaderAnimated.tsx +13 -41
  12. package/Application/Components/HeaderBackground.tsx +3 -20
  13. package/Application/Components/HeaderExtendHeader.tsx +46 -66
  14. package/Application/Components/HeaderLeft.tsx +18 -5
  15. package/Application/Components/HeaderRight.tsx +529 -8
  16. package/Application/Components/HeaderTitle.tsx +579 -16
  17. package/Application/Components/NavigationButton.tsx +11 -18
  18. package/Application/Components/SearchHeader.tsx +18 -38
  19. package/Application/Localize.ts +0 -7
  20. package/Application/ModalScreen.tsx +18 -41
  21. package/Application/Navigation.ts +17 -15
  22. package/Application/NavigationContainer.tsx +21 -23
  23. package/Application/Navigator.ts +48 -20
  24. package/Application/ScaleSizeProvider.tsx +6 -13
  25. package/Application/StackScreen.tsx +172 -27
  26. package/Application/TooltipPortal.tsx +5 -12
  27. package/Application/WidgetContainer.tsx +7 -20
  28. package/Application/device.ts +52 -0
  29. package/Application/index.ts +1 -23
  30. package/Application/types.ts +242 -17
  31. package/Application/utils.tsx +493 -0
  32. package/Badge/Badge.tsx +0 -5
  33. package/Badge/BadgeDot.tsx +0 -1
  34. package/Badge/BadgeDotAnimation.tsx +7 -15
  35. package/Badge/BadgeRibbon.tsx +39 -47
  36. package/Badge/Shape.tsx +0 -2
  37. package/Badge/styles.ts +0 -2
  38. package/Badge/types.ts +2 -2
  39. package/Button/index.tsx +152 -21
  40. package/Button/styles.ts +1 -1
  41. package/CheckBox/index.tsx +6 -5
  42. package/Consts/theme.ts +10 -10
  43. package/Context/index.ts +1 -5
  44. package/Divider/DashDivider.tsx +11 -11
  45. package/Divider/index.tsx +7 -21
  46. package/FoundationList/index.tsx +0 -4
  47. package/Icon/index.tsx +6 -6
  48. package/Icon/types.ts +1 -1
  49. package/IconButton/index.tsx +12 -4
  50. package/Image/index.tsx +7 -9
  51. package/Input/Input.tsx +12 -10
  52. package/Input/InputDropDown.tsx +13 -10
  53. package/Input/InputMoney.tsx +152 -45
  54. package/Input/InputOTP.tsx +34 -36
  55. package/Input/InputPhoneNumber.tsx +5 -8
  56. package/Input/InputSearch.tsx +111 -19
  57. package/Input/InputTextArea.tsx +5 -5
  58. package/Input/SystemTextInput.tsx +2 -7
  59. package/Input/TextTyping.tsx +0 -4
  60. package/Input/common.tsx +17 -31
  61. package/Input/index.tsx +21 -24
  62. package/Input/styles.ts +5 -25
  63. package/Input/utils.ts +12 -14
  64. package/Layout/Card.tsx +4 -7
  65. package/Layout/FloatingButton.tsx +21 -26
  66. package/Layout/Item.tsx +2 -6
  67. package/Layout/ItemList.tsx +7 -9
  68. package/Layout/ItemSectionList.tsx +1 -2
  69. package/Layout/ReservedRegions.tsx +17 -34
  70. package/Layout/Screen.tsx +696 -122
  71. package/Layout/Section.tsx +7 -9
  72. package/Layout/TrackingScope.tsx +0 -1
  73. package/Layout/index.ts +4 -10
  74. package/Layout/styles.ts +0 -2
  75. package/Layout/types.ts +4 -2
  76. package/Layout/utils.ts +181 -40
  77. package/Loader/DotLoader.tsx +3 -11
  78. package/Loader/Loader.tsx +0 -4
  79. package/Loader/ProgressBar.tsx +6 -3
  80. package/Loader/Spinner.tsx +3 -11
  81. package/Loader/styles.ts +0 -4
  82. package/Loader/utils.ts +7 -11
  83. package/Pagination/Dot.tsx +0 -4
  84. package/Pagination/PaginationDot.tsx +0 -1
  85. package/Pagination/PaginationNumber.tsx +3 -5
  86. package/Pagination/PaginationScroll.tsx +0 -5
  87. package/Pagination/PaginationWhiteDot.tsx +0 -1
  88. package/Pagination/index.tsx +0 -4
  89. package/Pagination/types.ts +2 -2
  90. package/Popup/PopupNotify.tsx +102 -94
  91. package/Popup/PopupPromotion.tsx +11 -9
  92. package/Popup/types.ts +4 -11
  93. package/Popup/utils.ts +18 -50
  94. package/Radio/index.tsx +10 -6
  95. package/Radio/styles.ts +0 -6
  96. package/Skeleton/index.tsx +9 -9
  97. package/Skeleton/styles.ts +0 -1
  98. package/Switch/index.tsx +0 -1
  99. package/Tag/index.tsx +4 -8
  100. package/Tag/types.ts +3 -3
  101. package/Text/index.tsx +5 -25
  102. package/Text/styles.ts +1 -1
  103. package/Text/types.ts +6 -1
  104. package/Text/utils.ts +4 -20
  105. package/Title/index.tsx +40 -42
  106. package/Title/styles.ts +0 -6
  107. package/ViewBoundary/index.tsx +2 -4
  108. package/index.ts +6 -0
  109. package/package.json +1 -2
  110. package/Application/BottomSheet.hooks.ts +0 -195
  111. package/Application/BottomSheet.parts.tsx +0 -157
  112. package/Application/BottomSheet.styles.ts +0 -43
  113. package/Application/BottomTab/ActiveIndicator.tsx +0 -91
  114. package/Application/BottomTab/BottomTabBar.styles.ts +0 -65
  115. package/Application/BottomTab/BottomTabInset.tsx +0 -18
  116. package/Application/BottomTab/CurvedContainer.tsx +0 -155
  117. package/Application/BottomTab/DuoRailTabBar.tsx +0 -223
  118. package/Application/BottomTab/DuoTabBar.styles.ts +0 -81
  119. package/Application/BottomTab/TabScreen.tsx +0 -160
  120. package/Application/BottomTab/metrics.ts +0 -164
  121. package/Application/BottomTab/tabItems.ts +0 -46
  122. package/Application/BottomTab/usePressLift.ts +0 -32
  123. package/Application/Components/HeaderRight.styles.ts +0 -146
  124. package/Application/Components/HeaderTitle.shared.ts +0 -44
  125. package/Application/Components/HeaderTitle.styles.ts +0 -125
  126. package/Application/Components/HeaderToolkitAction.tsx +0 -180
  127. package/Application/Components/SwipeBackHaptic.tsx +0 -95
  128. package/Application/Components/TitleJourney.tsx +0 -110
  129. package/Application/Components/TitleLocation.tsx +0 -73
  130. package/Application/Components/TitleUser.tsx +0 -304
  131. package/Application/Components/useToolkitActions.tsx +0 -218
  132. package/Application/ModalIconButton.tsx +0 -66
  133. package/Application/StackScreen.tracking.ts +0 -143
  134. package/Application/headerLayout.ts +0 -158
  135. package/Application/hooks.ts +0 -137
  136. package/Application/modalLayout.ts +0 -176
  137. package/Application/navigationOptions.tsx +0 -212
  138. package/Application/types.header.ts +0 -121
  139. package/Application/types.tabs.ts +0 -48
  140. package/Application/types.theme.ts +0 -87
  141. package/Application/utils.ts +0 -107
  142. package/Button/utils.ts +0 -133
  143. package/Input/InputMoneyView.tsx +0 -194
  144. package/Input/SearchTextTyping.tsx +0 -108
  145. package/Input/moneyUtils.ts +0 -23
  146. package/Layout/layoutMetrics.ts +0 -58
  147. package/Layout/layoutTypes.ts +0 -86
  148. package/Layout/screenContent.tsx +0 -92
  149. package/Layout/screenFooter.tsx +0 -63
  150. package/Layout/screenHeader.tsx +0 -321
  151. package/Layout/screenQuickReturn.tsx +0 -64
  152. package/Layout/screenScroll.ts +0 -107
  153. package/Layout/screenTypes.ts +0 -143
@@ -1,138 +1,136 @@
1
- import React, { useContext, useEffect } from 'react';
1
+ import React, { useContext } from 'react';
2
+ import { TouchableOpacity, StyleSheet } from 'react-native';
2
3
  import {
3
- LayoutChangeEvent,
4
- StyleSheet,
5
- TouchableOpacity,
6
- View,
7
- } from 'react-native';
8
- import Animated, {
9
- useAnimatedStyle,
10
- useSharedValue,
11
- withTiming,
12
- } from 'react-native-reanimated';
4
+ BottomTabBarButtonProps,
5
+ BottomTabNavigationOptions,
6
+ } from '@react-navigation/bottom-tabs';
7
+ import { Route } from '@react-navigation/native';
13
8
  import { TabBarIcon } from './TabBarIcon';
14
9
  import { Text } from '../../Text';
15
10
  import { MiniAppContext } from '../../Context';
16
- import { Colors, Spacing } from '../../Consts';
17
- import { TabBarMetrics, TabBarMotion } from './metrics';
11
+ import { Colors } from '../../Consts';
18
12
 
19
- type IconRenderer = (props: {
20
- focused: boolean;
21
- color: string;
22
- size: number;
23
- }) => React.ReactNode;
13
+ type LabelType = NonNullable<BottomTabNavigationOptions['tabBarLabel']>;
24
14
 
25
- type TabItemContentProps = {
26
- label: string;
15
+ interface CustomBottomTabItemProps {
16
+ route: Route<string>;
27
17
  focused: boolean;
18
+ label: LabelType;
19
+ onPress: () => void;
20
+ onLongPress: () => void;
28
21
  activeTintColor: string;
29
22
  inactiveTintColor: string;
30
- icon?: IconRenderer;
23
+ activeBackgroundColor?: string;
24
+ inactiveBackgroundColor?: string;
25
+ icon: any;
31
26
  badge?: string | number;
32
- // rail item (.Nav/Duo/Item) instead of the horizontal one (.Nav/itemTab)
33
- vertical?: boolean;
34
- hideLabel?: boolean;
35
- };
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
+ }
36
43
 
37
- /**
38
- * Tab item body: the icon in its indicator slot, the label in a fixed slot under it so a
39
- * scaled label grows down. The bar slides one shared active indicator behind the icon slots.
40
- */
41
- const TabItemContent: React.FC<TabItemContentProps> = ({
42
- label,
44
+ const CustomBottomTabItem: React.FC<CustomBottomTabItemProps> = ({
45
+ route,
43
46
  focused,
47
+ label,
48
+ onPress,
49
+ onLongPress,
44
50
  activeTintColor,
45
51
  inactiveTintColor,
52
+ activeBackgroundColor,
53
+ inactiveBackgroundColor,
46
54
  icon,
47
55
  badge,
48
- vertical,
49
- hideLabel,
56
+ showLabel,
57
+ labelStyle,
58
+ iconStyle,
59
+ style,
60
+ badgeStyle,
61
+ allowFontScaling,
50
62
  }) => {
51
- const progress = useSharedValue(focused ? 1 : 0);
63
+ const context = useContext<any>(MiniAppContext);
64
+ const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false;
52
65
 
53
- useEffect(() => {
54
- progress.value = withTiming(focused ? 1 : 0, TabBarMotion.tint);
55
- }, [focused, progress]);
66
+ const renderIcon = () => {
67
+ if (icon === undefined) {
68
+ return null;
69
+ }
56
70
 
57
- const activeLabelStyle = useAnimatedStyle(() => ({
58
- opacity: progress.value,
59
- }));
71
+ const activeOpacity = focused ? 1 : 0;
72
+ const inactiveOpacity = focused ? 0 : 1;
60
73
 
61
- const renderText = (color: string) => (
62
- <Text
63
- numberOfLines={1}
64
- typography={vertical ? 'label_xs_medium' : 'label_s_medium'}
65
- color={color}
66
- style={!vertical && styles.label}
67
- >
68
- {label}
69
- </Text>
70
- );
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
+ };
71
89
 
72
- // Active label fades in over the inactive one; a scaled label overflows down.
73
- const labelNode = (
74
- <View style={vertical ? styles.railLabelSlot : styles.labelSlot}>
75
- {renderText(inactiveTintColor)}
76
- <Animated.View
77
- pointerEvents={'none'}
78
- style={[StyleSheet.absoluteFill, activeLabelStyle]}
79
- >
80
- {renderText(activeTintColor)}
81
- </Animated.View>
82
- </View>
83
- );
90
+ const renderLabel = ({ focused }: { focused: boolean }) => {
91
+ if (showLabel === false) {
92
+ return null;
93
+ }
84
94
 
85
- return (
86
- <>
87
- <View style={vertical ? styles.railSlot : styles.slot}>
88
- <TabBarIcon
89
- focused={focused}
90
- badge={badge}
91
- vertical={vertical}
92
- activeTintColor={activeTintColor}
93
- inactiveTintColor={inactiveTintColor}
94
- renderIcon={icon}
95
- />
96
- </View>
97
- {!hideLabel && labelNode}
98
- </>
99
- );
100
- };
95
+ const color = focused ? activeTintColor : inactiveTintColor;
101
96
 
102
- type CustomBottomTabItemProps = TabItemContentProps & {
103
- onPress: () => void;
104
- onLongPress: () => void;
105
- onLayout?: (e: LayoutChangeEvent) => void;
106
- accessibilityLabel?: string;
107
- testID?: string;
108
- };
97
+ if (typeof label === 'string') {
98
+ return (
99
+ <Text
100
+ numberOfLines={1}
101
+ style={[styles.label, labelStyle]}
102
+ color={focused ? activeTintColor : inactiveTintColor}
103
+ typography={focused ? 'label_xs_medium' : 'description_xs_regular'}
104
+ allowFontScaling={allowFontScaling}
105
+ >
106
+ {label}
107
+ </Text>
108
+ );
109
+ }
109
110
 
110
- /**
111
- * Horizontal navigation item (.Nav/itemTab), filling an even share of the container.
112
- */
113
- const CustomBottomTabItem: React.FC<CustomBottomTabItemProps> = ({
114
- onPress,
115
- onLongPress,
116
- onLayout,
117
- accessibilityLabel,
118
- testID,
119
- ...content
120
- }) => {
121
- const context = useContext<any>(MiniAppContext);
122
- const showBaseLineDebug = context?.features?.showBaseLineDebug ?? false;
111
+ return label({
112
+ focused,
113
+ color,
114
+ children: route.name,
115
+ position: 'below-icon',
116
+ });
117
+ };
118
+
119
+ const background = focused ? activeBackgroundColor : inactiveBackgroundColor;
123
120
 
124
121
  return (
125
122
  <TouchableOpacity
126
- accessibilityRole={'tab'}
127
- accessibilityLabel={accessibilityLabel ?? content.label}
128
- accessibilityState={{ selected: content.focused }}
129
- testID={testID}
130
123
  onPress={onPress}
131
124
  onLongPress={onLongPress}
132
- onLayout={onLayout}
133
- style={[styles.container, showBaseLineDebug && styles.debugBaseLine]}
125
+ style={[
126
+ styles.container,
127
+ { backgroundColor: background },
128
+ style,
129
+ showBaseLineDebug && styles.debugBaseLine,
130
+ ]}
134
131
  >
135
- <TabItemContent {...content} />
132
+ {renderIcon()}
133
+ {renderLabel({ focused })}
136
134
  </TouchableOpacity>
137
135
  );
138
136
  };
@@ -140,38 +138,16 @@ const CustomBottomTabItem: React.FC<CustomBottomTabItemProps> = ({
140
138
  const styles = StyleSheet.create({
141
139
  container: {
142
140
  flex: 1,
143
- minWidth: 1,
144
141
  alignItems: 'center',
145
142
  justifyContent: 'center',
146
- gap: Spacing.XXS,
147
- },
148
- slot: {
149
- height: TabBarMetrics.indicatorHeight,
150
- alignSelf: 'stretch',
151
- alignItems: 'center',
152
- justifyContent: 'center',
153
- paddingVertical: TabBarMetrics.indicatorPaddingVertical,
154
- paddingHorizontal: TabBarMetrics.indicatorPaddingHorizontal,
155
- },
156
- railSlot: {
157
- height: TabBarMetrics.railIndicatorHeight,
158
- alignItems: 'center',
159
- justifyContent: 'center',
160
- paddingVertical: TabBarMetrics.railIndicatorPaddingVertical,
161
- paddingHorizontal: TabBarMetrics.indicatorPaddingHorizontal,
162
- },
163
- labelSlot: {
164
- height: TabBarMetrics.labelHeight,
165
- alignSelf: 'stretch',
166
- },
167
- railLabelSlot: {
168
- height: TabBarMetrics.railLabelHeight,
143
+ paddingVertical: 8,
144
+ bottom: -2,
169
145
  },
170
146
  label: {
171
- textAlign: 'center',
147
+ fontSize: 12,
148
+ fontWeight: '600',
172
149
  },
173
150
  debugBaseLine: { borderWidth: 1, borderColor: Colors.green_06 },
174
151
  });
175
152
 
176
- export { TabItemContent };
177
153
  export default CustomBottomTabItem;
@@ -8,7 +8,6 @@ import React, {
8
8
  import { Spacing } from '../../Consts';
9
9
  import { useScreenLayout } from '../../Layout';
10
10
  import { DuoMetrics } from '../../Layout/utils';
11
- import { getRailHeight, TabBarMetrics } from './metrics';
12
11
 
13
12
  export type DuoBarCompressionBehavior = 'toolbar' | 'tabBar';
14
13
 
@@ -26,11 +25,13 @@ type DuoBarCompression = {
26
25
  setToolbarHeight?: (height: number) => void;
27
26
  };
28
27
 
28
+ const RAIL_PADDING = 6;
29
+ const RAIL_GAP = Spacing.XXS;
29
30
  // space kept between the top and the bottom groups (HIG Vertical controls)
30
31
  const GROUP_GAP = Spacing.M;
31
- const BACK_SLOT_HEIGHT = DuoMetrics.controlSize + Spacing.M;
32
32
  // Back, then the right toolkit: help + home capsule
33
- const DEFAULT_TOOLBAR_HEIGHT = BACK_SLOT_HEIGHT + 2 * DuoMetrics.itemPitch;
33
+ const DEFAULT_TOOLBAR_HEIGHT =
34
+ DuoMetrics.controlSize + Spacing.M + 2 * DuoMetrics.itemPitch;
34
35
  // Back, then the single button the toolbar folds into
35
36
  const COMPRESSED_TOOLBAR_HEIGHT = 2 * DuoMetrics.controlSize + Spacing.M;
36
37
 
@@ -39,12 +40,25 @@ const NO_COMPRESSION: DuoBarCompression = {
39
40
  tabBarCompressed: false,
40
41
  };
41
42
 
42
- const DuoBarCompressionContext = createContext(NO_COMPRESSION);
43
+ const DuoBarCompressionContext =
44
+ createContext<DuoBarCompression>(NO_COMPRESSION);
43
45
 
44
46
  /**
45
- * Keeps the Duo side bar's toolbar and tab bar clear of each other (HIG Vertical controls):
46
- * both stay whole if they fit, else one is compressed and tapping it swaps them, else both
47
- * rest compressed and tapping one opens it until a tab is picked.
47
+ * height of the vertical tab rail, plus the QR button under it
48
+ */
49
+ const getRailHeight = (tabCount: number, hasQr: boolean) =>
50
+ 2 * RAIL_PADDING +
51
+ tabCount * DuoMetrics.controlSize +
52
+ Math.max(tabCount - 1, 0) * RAIL_GAP +
53
+ (hasQr ? Spacing.M + DuoMetrics.controlSize : 0);
54
+
55
+ /**
56
+ * keeps the side bar's toolbar and tab bar clear of each other (HIG, Designing for
57
+ * iPhone Duo: Vertical controls):
58
+ * - both fit: both stay whole
59
+ * - one fits whole beside the other compressed: one is compressed, tapping it swaps them
60
+ * - otherwise both rest compressed; tapping one opens it for a moment (the rail closes
61
+ * again once a tab is picked)
48
62
  */
49
63
  const DuoBarCompressionProvider: React.FC<{
50
64
  behavior?: DuoBarCompressionBehavior;
@@ -67,16 +81,16 @@ const DuoBarCompressionProvider: React.FC<{
67
81
  }
68
82
  const room = height - sideBar.bottom - sideBar.top - GROUP_GAP;
69
83
  const tabBar = getRailHeight(tabCount, hasQr);
70
- const qrHeight = TabBarMetrics.railCtaGap + TabBarMetrics.railCtaHeight;
71
- const compressedTabBar = DuoMetrics.controlSize + (hasQr ? qrHeight : 0);
84
+ const compressedTabBar = getRailHeight(1, hasQr) - 2 * RAIL_PADDING;
72
85
  const fits = (toolbar: number, tabs: number) => toolbar + tabs <= room;
73
86
 
74
87
  if (fits(toolbarHeight, tabBar)) {
75
88
  return { ...NO_COMPRESSION, setToolbarHeight };
76
89
  }
77
- const canCompressToolbar = fits(COMPRESSED_TOOLBAR_HEIGHT, tabBar);
78
- const canCompressTabBar = fits(toolbarHeight, compressedTabBar);
79
- if (canCompressToolbar && canCompressTabBar) {
90
+ const canSwap =
91
+ fits(COMPRESSED_TOOLBAR_HEIGHT, tabBar) &&
92
+ fits(toolbarHeight, compressedTabBar);
93
+ if (canSwap) {
80
94
  return {
81
95
  toolbarCompressed: expanded === 'tabBar',
82
96
  tabBarCompressed: expanded === 'toolbar',
@@ -91,7 +105,8 @@ const DuoBarCompressionProvider: React.FC<{
91
105
  expandTabBar: () => setOpened('tabBar'),
92
106
  setToolbarHeight,
93
107
  };
94
- // An opened rail shows even if only the group gap is short; picking a tab closes it.
108
+ // an opened rail always shows, even when only the gap between the groups is short:
109
+ // it closes again once a tab is picked
95
110
  if (opened === 'tabBar') {
96
111
  return {
97
112
  ...open,
@@ -115,7 +130,6 @@ const DuoBarCompressionProvider: React.FC<{
115
130
  );
116
131
  };
117
132
 
118
- /** Compression state of the Duo side bars; no compression outside the provider. */
119
133
  const useDuoBarCompression = () => useContext(DuoBarCompressionContext);
120
134
 
121
135
  export { DuoBarCompressionProvider, useDuoBarCompression };