@momo-kits/foundation 0.169.6-beta.1 → 0.169.6
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.hooks.ts +8 -8
- package/Application/BottomSheet.parts.tsx +44 -34
- package/Application/BottomSheet.tsx +35 -26
- package/Application/BottomTab/ActiveIndicator.tsx +15 -14
- package/Application/BottomTab/BottomTabBar.styles.ts +1 -18
- package/Application/BottomTab/BottomTabBar.tsx +58 -57
- package/Application/BottomTab/BottomTabInset.tsx +8 -4
- package/Application/BottomTab/CurvedContainer.tsx +16 -20
- package/Application/BottomTab/CustomBottomTabItem.tsx +14 -15
- package/Application/BottomTab/DuoBarCompression.tsx +13 -19
- package/Application/BottomTab/DuoRailTabBar.tsx +20 -20
- package/Application/BottomTab/DuoTabBar.tsx +11 -24
- package/Application/BottomTab/TabBarIcon.tsx +15 -29
- package/Application/BottomTab/TabScreen.tsx +1 -5
- package/Application/BottomTab/index.tsx +33 -30
- package/Application/BottomTab/metrics.ts +25 -48
- package/Application/BottomTab/tabItems.ts +1 -1
- package/Application/BottomTab/usePressLift.ts +2 -2
- package/Application/Components/BackgroundImageView.tsx +4 -0
- package/Application/Components/DuoGlassBackground.tsx +5 -4
- package/Application/Components/HeaderAnimated.tsx +4 -0
- package/Application/Components/HeaderBackground.tsx +4 -0
- package/Application/Components/HeaderExtendHeader.tsx +11 -10
- package/Application/Components/HeaderLeft.tsx +2 -1
- package/Application/Components/HeaderRight.tsx +2 -1
- package/Application/Components/HeaderTitle.shared.ts +11 -9
- package/Application/Components/HeaderTitle.tsx +4 -3
- package/Application/Components/HeaderToolkitAction.tsx +17 -20
- package/Application/Components/NavigationButton.tsx +2 -1
- package/Application/Components/SearchHeader.tsx +17 -10
- package/Application/Components/TitleJourney.tsx +2 -2
- package/Application/Components/TitleLocation.tsx +2 -2
- package/Application/Components/TitleUser.tsx +2 -2
- package/Application/Components/useToolkitActions.tsx +17 -32
- package/Application/Localize.ts +7 -0
- package/Application/ModalScreen.tsx +9 -3
- package/Application/Navigation.ts +14 -16
- package/Application/NavigationContainer.tsx +19 -16
- package/Application/Navigator.ts +20 -48
- package/Application/ScaleSizeProvider.tsx +13 -6
- package/Application/StackScreen.tracking.ts +11 -26
- package/Application/StackScreen.tsx +8 -35
- package/Application/TooltipPortal.tsx +12 -5
- package/Application/WidgetContainer.tsx +10 -4
- package/Application/modalLayout.ts +13 -14
- package/Application/navigationOptions.tsx +21 -17
- package/Application/types.tabs.ts +1 -0
- package/Badge/Badge.tsx +5 -0
- package/Badge/BadgeDot.tsx +1 -0
- package/Badge/BadgeDotAnimation.tsx +15 -7
- package/Badge/BadgeRibbon.tsx +46 -38
- package/Badge/Shape.tsx +2 -0
- package/Badge/types.ts +2 -2
- package/Button/index.tsx +5 -16
- package/Button/utils.ts +9 -15
- package/CheckBox/index.tsx +4 -0
- package/Consts/theme.ts +10 -10
- package/Context/index.ts +5 -1
- package/Divider/DashDivider.tsx +1 -0
- package/Divider/index.tsx +4 -0
- package/FoundationList/index.tsx +4 -0
- package/Icon/index.tsx +6 -6
- package/Icon/types.ts +1 -1
- package/IconButton/index.tsx +4 -12
- package/Image/index.tsx +9 -7
- package/Input/Input.tsx +8 -9
- package/Input/InputDropDown.tsx +10 -12
- package/Input/InputMoney.tsx +12 -8
- package/Input/InputMoneyView.tsx +14 -7
- package/Input/InputOTP.tsx +35 -33
- package/Input/InputPhoneNumber.tsx +8 -9
- package/Input/InputSearch.tsx +4 -6
- package/Input/InputTextArea.tsx +4 -0
- package/Input/SearchTextTyping.tsx +4 -0
- package/Input/SystemTextInput.tsx +7 -2
- package/Input/TextTyping.tsx +4 -0
- package/Input/common.tsx +26 -12
- package/Input/index.tsx +17 -20
- package/Input/moneyUtils.ts +10 -4
- package/Input/styles.ts +0 -5
- package/Input/utils.ts +14 -12
- package/Layout/Card.tsx +7 -4
- package/Layout/FloatingButton.tsx +4 -0
- package/Layout/Item.tsx +6 -2
- package/Layout/ItemList.tsx +9 -7
- package/Layout/ItemSectionList.tsx +2 -1
- package/Layout/ReservedRegions.tsx +25 -25
- package/Layout/Screen.tsx +56 -58
- package/Layout/Section.tsx +8 -5
- package/Layout/TrackingScope.tsx +1 -0
- package/Layout/screenContent.tsx +4 -2
- package/Layout/screenFooter.tsx +28 -18
- package/Layout/screenHeader.tsx +34 -31
- package/Layout/screenQuickReturn.tsx +17 -20
- package/Layout/screenScroll.ts +4 -7
- package/Layout/screenTypes.ts +3 -2
- package/Layout/types.ts +2 -4
- package/Layout/utils.ts +31 -37
- package/Loader/DotLoader.tsx +4 -0
- package/Loader/Loader.tsx +4 -0
- package/Loader/ProgressBar.tsx +1 -0
- package/Loader/Spinner.tsx +4 -0
- package/Loader/utils.ts +11 -7
- package/Pagination/Dot.tsx +4 -0
- package/Pagination/PaginationDot.tsx +1 -0
- package/Pagination/PaginationNumber.tsx +5 -3
- package/Pagination/PaginationScroll.tsx +5 -0
- package/Pagination/PaginationWhiteDot.tsx +1 -0
- package/Pagination/index.tsx +4 -0
- package/Pagination/types.ts +2 -2
- package/Popup/PopupNotify.tsx +44 -48
- package/Popup/PopupPromotion.tsx +4 -7
- package/Popup/types.ts +4 -4
- package/Popup/utils.ts +4 -0
- package/Radio/index.tsx +4 -0
- package/Skeleton/index.tsx +8 -0
- package/Switch/index.tsx +1 -0
- package/Tag/index.tsx +5 -1
- package/Tag/types.ts +3 -3
- package/Text/index.tsx +14 -3
- package/Text/styles.ts +1 -1
- package/Text/types.ts +1 -6
- package/Text/utils.ts +20 -4
- package/Title/index.tsx +41 -32
- package/ViewBoundary/index.tsx +4 -2
- package/index.ts +0 -6
- package/package.json +1 -1
- package/Application/__tests__/modalLayout.test.ts +0 -128
|
@@ -13,7 +13,7 @@ import Animated, {
|
|
|
13
13
|
import { TabBarIcon } from './TabBarIcon';
|
|
14
14
|
import { Text } from '../../Text';
|
|
15
15
|
import { MiniAppContext } from '../../Context';
|
|
16
|
-
import { Colors } from '../../Consts';
|
|
16
|
+
import { Colors, Spacing } from '../../Consts';
|
|
17
17
|
import { TabBarMetrics, TabBarMotion } from './metrics';
|
|
18
18
|
|
|
19
19
|
type IconRenderer = (props: {
|
|
@@ -35,8 +35,8 @@ type TabItemContentProps = {
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
* icon in its indicator slot, label
|
|
39
|
-
*
|
|
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
40
|
*/
|
|
41
41
|
const TabItemContent: React.FC<TabItemContentProps> = ({
|
|
42
42
|
label,
|
|
@@ -69,9 +69,9 @@ const TabItemContent: React.FC<TabItemContentProps> = ({
|
|
|
69
69
|
</Text>
|
|
70
70
|
);
|
|
71
71
|
|
|
72
|
-
//
|
|
73
|
-
const
|
|
74
|
-
<View style={
|
|
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
75
|
{renderText(inactiveTintColor)}
|
|
76
76
|
<Animated.View
|
|
77
77
|
pointerEvents={'none'}
|
|
@@ -94,7 +94,7 @@ const TabItemContent: React.FC<TabItemContentProps> = ({
|
|
|
94
94
|
renderIcon={icon}
|
|
95
95
|
/>
|
|
96
96
|
</View>
|
|
97
|
-
{!hideLabel &&
|
|
97
|
+
{!hideLabel && labelNode}
|
|
98
98
|
</>
|
|
99
99
|
);
|
|
100
100
|
};
|
|
@@ -108,7 +108,7 @@ type CustomBottomTabItemProps = TabItemContentProps & {
|
|
|
108
108
|
};
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
|
-
*
|
|
111
|
+
* Horizontal navigation item (.Nav/itemTab), filling an even share of the container.
|
|
112
112
|
*/
|
|
113
113
|
const CustomBottomTabItem: React.FC<CustomBottomTabItemProps> = ({
|
|
114
114
|
onPress,
|
|
@@ -143,7 +143,7 @@ const styles = StyleSheet.create({
|
|
|
143
143
|
minWidth: 1,
|
|
144
144
|
alignItems: 'center',
|
|
145
145
|
justifyContent: 'center',
|
|
146
|
-
gap:
|
|
146
|
+
gap: Spacing.XXS,
|
|
147
147
|
},
|
|
148
148
|
slot: {
|
|
149
149
|
height: TabBarMetrics.indicatorHeight,
|
|
@@ -160,13 +160,12 @@ const styles = StyleSheet.create({
|
|
|
160
160
|
paddingVertical: TabBarMetrics.railIndicatorPaddingVertical,
|
|
161
161
|
paddingHorizontal: TabBarMetrics.indicatorPaddingHorizontal,
|
|
162
162
|
},
|
|
163
|
-
|
|
164
|
-
alignSelf: 'stretch',
|
|
165
|
-
// fixed to the design line height so a capped-scale label overflows downward and the
|
|
166
|
-
// icon above it stays put
|
|
163
|
+
labelSlot: {
|
|
167
164
|
height: TabBarMetrics.labelHeight,
|
|
168
|
-
|
|
169
|
-
|
|
165
|
+
alignSelf: 'stretch',
|
|
166
|
+
},
|
|
167
|
+
railLabelSlot: {
|
|
168
|
+
height: TabBarMetrics.railLabelHeight,
|
|
170
169
|
},
|
|
171
170
|
label: {
|
|
172
171
|
textAlign: 'center',
|
|
@@ -28,9 +28,9 @@ type DuoBarCompression = {
|
|
|
28
28
|
|
|
29
29
|
// space kept between the top and the bottom groups (HIG Vertical controls)
|
|
30
30
|
const GROUP_GAP = Spacing.M;
|
|
31
|
+
const BACK_SLOT_HEIGHT = DuoMetrics.controlSize + Spacing.M;
|
|
31
32
|
// Back, then the right toolkit: help + home capsule
|
|
32
|
-
const DEFAULT_TOOLBAR_HEIGHT =
|
|
33
|
-
DuoMetrics.controlSize + Spacing.M + 2 * DuoMetrics.itemPitch;
|
|
33
|
+
const DEFAULT_TOOLBAR_HEIGHT = BACK_SLOT_HEIGHT + 2 * DuoMetrics.itemPitch;
|
|
34
34
|
// Back, then the single button the toolbar folds into
|
|
35
35
|
const COMPRESSED_TOOLBAR_HEIGHT = 2 * DuoMetrics.controlSize + Spacing.M;
|
|
36
36
|
|
|
@@ -39,16 +39,12 @@ const NO_COMPRESSION: DuoBarCompression = {
|
|
|
39
39
|
tabBarCompressed: false,
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
const DuoBarCompressionContext =
|
|
43
|
-
createContext<DuoBarCompression>(NO_COMPRESSION);
|
|
42
|
+
const DuoBarCompressionContext = createContext(NO_COMPRESSION);
|
|
44
43
|
|
|
45
44
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* - one fits whole beside the other compressed: one is compressed, tapping it swaps them
|
|
50
|
-
* - otherwise both rest compressed; tapping one opens it for a moment (the rail closes
|
|
51
|
-
* again once a tab is picked)
|
|
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.
|
|
52
48
|
*/
|
|
53
49
|
const DuoBarCompressionProvider: React.FC<{
|
|
54
50
|
behavior?: DuoBarCompressionBehavior;
|
|
@@ -71,18 +67,16 @@ const DuoBarCompressionProvider: React.FC<{
|
|
|
71
67
|
}
|
|
72
68
|
const room = height - sideBar.bottom - sideBar.top - GROUP_GAP;
|
|
73
69
|
const tabBar = getRailHeight(tabCount, hasQr);
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
(hasQr ? TabBarMetrics.railCtaGap + TabBarMetrics.railCtaHeight : 0);
|
|
70
|
+
const qrHeight = TabBarMetrics.railCtaGap + TabBarMetrics.railCtaHeight;
|
|
71
|
+
const compressedTabBar = DuoMetrics.controlSize + (hasQr ? qrHeight : 0);
|
|
77
72
|
const fits = (toolbar: number, tabs: number) => toolbar + tabs <= room;
|
|
78
73
|
|
|
79
74
|
if (fits(toolbarHeight, tabBar)) {
|
|
80
75
|
return { ...NO_COMPRESSION, setToolbarHeight };
|
|
81
76
|
}
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (canSwap) {
|
|
77
|
+
const canCompressToolbar = fits(COMPRESSED_TOOLBAR_HEIGHT, tabBar);
|
|
78
|
+
const canCompressTabBar = fits(toolbarHeight, compressedTabBar);
|
|
79
|
+
if (canCompressToolbar && canCompressTabBar) {
|
|
86
80
|
return {
|
|
87
81
|
toolbarCompressed: expanded === 'tabBar',
|
|
88
82
|
tabBarCompressed: expanded === 'toolbar',
|
|
@@ -97,8 +91,7 @@ const DuoBarCompressionProvider: React.FC<{
|
|
|
97
91
|
expandTabBar: () => setOpened('tabBar'),
|
|
98
92
|
setToolbarHeight,
|
|
99
93
|
};
|
|
100
|
-
//
|
|
101
|
-
// it closes again once a tab is picked
|
|
94
|
+
// An opened rail shows even if only the group gap is short; picking a tab closes it.
|
|
102
95
|
if (opened === 'tabBar') {
|
|
103
96
|
return {
|
|
104
97
|
...open,
|
|
@@ -122,6 +115,7 @@ const DuoBarCompressionProvider: React.FC<{
|
|
|
122
115
|
);
|
|
123
116
|
};
|
|
124
117
|
|
|
118
|
+
/** Compression state of the Duo side bars; no compression outside the provider. */
|
|
125
119
|
const useDuoBarCompression = () => useContext(DuoBarCompressionContext);
|
|
126
120
|
|
|
127
121
|
export { DuoBarCompressionProvider, useDuoBarCompression };
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
import type { DuoTabBarProps } from './DuoTabBar';
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* Center action icon: an icon name drawn at the CTA size, or a custom node
|
|
26
|
+
* Center action icon: an icon name drawn at the CTA size, or a custom node.
|
|
27
27
|
*/
|
|
28
28
|
const CtaIcon: React.FC<{ icon: FloatingButtonProps['icon'] }> = ({ icon }) => {
|
|
29
29
|
if (typeof icon === 'string') {
|
|
@@ -39,7 +39,7 @@ const CtaIcon: React.FC<{ icon: FloatingButtonProps['icon'] }> = ({ icon }) => {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* Vertical container (.Nav/Duo/Item column) with the sliding active indicator.
|
|
43
43
|
*/
|
|
44
44
|
const Rail: React.FC<{
|
|
45
45
|
items: TabItem[];
|
|
@@ -88,7 +88,7 @@ const Rail: React.FC<{
|
|
|
88
88
|
);
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
|
-
*
|
|
91
|
+
* Center action of the rail: a round button with its label, under the container.
|
|
92
92
|
*/
|
|
93
93
|
const RailCenterAction: React.FC<{ floatingButton: FloatingButtonProps }> = ({
|
|
94
94
|
floatingButton,
|
|
@@ -114,13 +114,13 @@ const RailCenterAction: React.FC<{ floatingButton: FloatingButtonProps }> = ({
|
|
|
114
114
|
<CtaIcon icon={floatingButton.icon} />
|
|
115
115
|
</Animated.View>
|
|
116
116
|
<View style={styles.railCtaLabel}>
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
117
|
+
<Text
|
|
118
|
+
numberOfLines={1}
|
|
119
|
+
typography={'label_xs_medium'}
|
|
120
|
+
color={theme.colors.text.secondary}
|
|
121
|
+
>
|
|
122
|
+
{floatingButton.label}
|
|
123
|
+
</Text>
|
|
124
124
|
{floatingButton.labelContent && (
|
|
125
125
|
<View pointerEvents={'none'} style={styles.railCtaLabelOverlay}>
|
|
126
126
|
{floatingButton.labelContent}
|
|
@@ -132,14 +132,14 @@ const RailCenterAction: React.FC<{ floatingButton: FloatingButtonProps }> = ({
|
|
|
132
132
|
};
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
135
|
+
* Vertical bar anchored to the bottom of the Duo side bar, center action below it. When the
|
|
136
|
+
* side bar is short it can shrink to one button showing the current tab (HIG "Tab bar
|
|
137
|
+
* compressed"); tapping it expands the rail and compresses the toolbar.
|
|
138
138
|
*/
|
|
139
139
|
const DuoRailTabBar: React.FC<DuoTabBarProps> = props => {
|
|
140
140
|
const { sideBar } = useScreenLayout();
|
|
141
|
-
const
|
|
142
|
-
|
|
141
|
+
const compression = useDuoBarCompression();
|
|
142
|
+
const { tabBarCompressed, expandTabBar, onTabSelected } = compression;
|
|
143
143
|
const compactLift = usePressLift();
|
|
144
144
|
const { state, floatingButton, activeTintColor, inactiveTintColor } = props;
|
|
145
145
|
const items = getTabItems(props);
|
|
@@ -149,8 +149,7 @@ const DuoRailTabBar: React.FC<DuoTabBarProps> = props => {
|
|
|
149
149
|
return null;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
//
|
|
153
|
-
// from the strip's inner edge
|
|
152
|
+
// Lines up with the side bar header buttons: a 48 lane kept 12 from the inner edge.
|
|
154
153
|
const columnStyle = [
|
|
155
154
|
styles.railColumn,
|
|
156
155
|
{
|
|
@@ -160,9 +159,10 @@ const DuoRailTabBar: React.FC<DuoTabBarProps> = props => {
|
|
|
160
159
|
},
|
|
161
160
|
sideBar.edge === 'right' ? styles.railColumnRight : styles.railColumnLeft,
|
|
162
161
|
];
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
let cta: React.ReactNode;
|
|
163
|
+
if (floatingButton) {
|
|
164
|
+
cta = <RailCenterAction floatingButton={floatingButton} />;
|
|
165
|
+
}
|
|
166
166
|
|
|
167
167
|
if (!tabBarCompressed) {
|
|
168
168
|
return (
|
|
@@ -3,11 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import { useWindowDimensions, View } from 'react-native';
|
|
4
4
|
import { useScreenLayout } from '../../Layout/utils';
|
|
5
5
|
import { FloatingButtonProps } from '../types';
|
|
6
|
-
import {
|
|
7
|
-
getSystemIndicatorHeight,
|
|
8
|
-
hasCenterAction,
|
|
9
|
-
HorizontalTabBar,
|
|
10
|
-
} from './BottomTabBar';
|
|
6
|
+
import { getSystemIndicatorHeight, HorizontalTabBar } from './BottomTabBar';
|
|
11
7
|
import { getHorizontalBarWidth, TabBarMetrics } from './metrics';
|
|
12
8
|
import { getTabItems } from './tabItems';
|
|
13
9
|
import { DuoRailTabBar } from './DuoRailTabBar';
|
|
@@ -20,8 +16,8 @@ type DuoTabBarProps = BottomTabBarProps & {
|
|
|
20
16
|
};
|
|
21
17
|
|
|
22
18
|
/**
|
|
23
|
-
*
|
|
24
|
-
* 0 when the Duo rail sits in the side bar
|
|
19
|
+
* Space tab content leaves under the floating horizontal tab bar (phone and unfolded Duo);
|
|
20
|
+
* 0 when the Duo rail sits in the side bar.
|
|
25
21
|
*/
|
|
26
22
|
const useDuoTabBarInset = () => {
|
|
27
23
|
const { isIPhoneDuo, sideBar, insets } = useScreenLayout();
|
|
@@ -32,13 +28,12 @@ const useDuoTabBarInset = () => {
|
|
|
32
28
|
};
|
|
33
29
|
|
|
34
30
|
/**
|
|
35
|
-
*
|
|
31
|
+
* Horizontal navigation bar of the unfolded display: 65% of the short side, centered.
|
|
36
32
|
*/
|
|
37
33
|
const DuoFloatingTabBar: React.FC<DuoTabBarProps> = props => {
|
|
38
34
|
const { insets } = useScreenLayout();
|
|
39
35
|
const { width, height } = useWindowDimensions();
|
|
40
36
|
const { floatingButton, activeTintColor, inactiveTintColor } = props;
|
|
41
|
-
const tabItems = getTabItems(props);
|
|
42
37
|
|
|
43
38
|
return (
|
|
44
39
|
<View
|
|
@@ -49,15 +44,8 @@ const DuoFloatingTabBar: React.FC<DuoTabBarProps> = props => {
|
|
|
49
44
|
]}
|
|
50
45
|
>
|
|
51
46
|
<HorizontalTabBar
|
|
52
|
-
items={
|
|
53
|
-
width={getHorizontalBarWidth(
|
|
54
|
-
width,
|
|
55
|
-
height,
|
|
56
|
-
insets.left,
|
|
57
|
-
insets.right,
|
|
58
|
-
tabItems.length,
|
|
59
|
-
hasCenterAction(floatingButton, tabItems.length),
|
|
60
|
-
)}
|
|
47
|
+
items={getTabItems(props)}
|
|
48
|
+
width={getHorizontalBarWidth(width, height, insets.left, insets.right)}
|
|
61
49
|
floatingButton={floatingButton}
|
|
62
50
|
activeTintColor={activeTintColor}
|
|
63
51
|
inactiveTintColor={inactiveTintColor}
|
|
@@ -67,15 +55,14 @@ const DuoFloatingTabBar: React.FC<DuoTabBarProps> = props => {
|
|
|
67
55
|
};
|
|
68
56
|
|
|
69
57
|
/**
|
|
70
|
-
* iPhone Duo tab bar: rail in the side bar, or the horizontal bar when unfolded portrait
|
|
58
|
+
* iPhone Duo tab bar: the rail in the side bar, or the horizontal bar when unfolded portrait.
|
|
71
59
|
*/
|
|
72
60
|
const DuoTabBar: React.FC<DuoTabBarProps> = props => {
|
|
73
61
|
const { sideBar } = useScreenLayout();
|
|
74
|
-
|
|
75
|
-
<DuoRailTabBar {...props}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
);
|
|
62
|
+
if (sideBar) {
|
|
63
|
+
return <DuoRailTabBar {...props} />;
|
|
64
|
+
}
|
|
65
|
+
return <DuoFloatingTabBar {...props} />;
|
|
79
66
|
};
|
|
80
67
|
|
|
81
68
|
export type { DuoTabBarProps };
|
|
@@ -7,9 +7,10 @@ import Animated, {
|
|
|
7
7
|
} from 'react-native-reanimated';
|
|
8
8
|
|
|
9
9
|
import { Colors, Spacing } from '../../Consts';
|
|
10
|
-
import { ApplicationContext
|
|
10
|
+
import { ApplicationContext } from '../../Context';
|
|
11
11
|
import { BadgeDot } from '../../Badge';
|
|
12
12
|
import { Text } from '../../Text';
|
|
13
|
+
import ScaleSizeProvider from '../ScaleSizeProvider';
|
|
13
14
|
import { TabBarMetrics, TabBarMotion } from './metrics';
|
|
14
15
|
|
|
15
16
|
type Props = {
|
|
@@ -28,7 +29,8 @@ type Props = {
|
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
|
-
*
|
|
32
|
+
* Badge value of a tab: undefined hides it, '' is a dot (also 0 when `showDot`), numbers
|
|
33
|
+
* cap at 99+.
|
|
32
34
|
*/
|
|
33
35
|
export const getTabBadge = (
|
|
34
36
|
badgeLabel?: string | number,
|
|
@@ -52,27 +54,8 @@ export const getTabBadge = (
|
|
|
52
54
|
};
|
|
53
55
|
|
|
54
56
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*/
|
|
58
|
-
export const FixedScaleText: React.FC<{ children: React.ReactNode }> = ({
|
|
59
|
-
children,
|
|
60
|
-
}) => {
|
|
61
|
-
const context = useContext<any>(MiniAppContext);
|
|
62
|
-
return (
|
|
63
|
-
<MiniAppContext.Provider
|
|
64
|
-
value={{
|
|
65
|
-
...context,
|
|
66
|
-
fontScale: { useOSScaleRate: false, userScaleRate: 1 },
|
|
67
|
-
}}
|
|
68
|
-
>
|
|
69
|
-
{children}
|
|
70
|
-
</MiniAppContext.Provider>
|
|
71
|
-
);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* numbers use the error color, text the warning color (Figma Badge round numeric / text)
|
|
57
|
+
* Label badge of a tab: numbers use the error color, text the warning color (Figma Badge
|
|
58
|
+
* round numeric / text). The text keeps its design size to fit the 16 height.
|
|
76
59
|
*/
|
|
77
60
|
const TabBadge: React.FC<{ label: string; vertical?: boolean }> = ({
|
|
78
61
|
label,
|
|
@@ -80,19 +63,21 @@ const TabBadge: React.FC<{ label: string; vertical?: boolean }> = ({
|
|
|
80
63
|
}) => {
|
|
81
64
|
const { theme } = useContext(ApplicationContext);
|
|
82
65
|
const isNumber = /^\d+\+?$/.test(label);
|
|
66
|
+
let backgroundColor = theme.colors.warning.primary;
|
|
67
|
+
if (isNumber) {
|
|
68
|
+
backgroundColor = theme.colors.error.primary;
|
|
69
|
+
}
|
|
83
70
|
const badge = (
|
|
84
71
|
<View
|
|
85
72
|
style={[
|
|
86
73
|
styles.badge,
|
|
87
74
|
{
|
|
88
|
-
backgroundColor
|
|
89
|
-
? theme.colors.error.primary
|
|
90
|
-
: theme.colors.warning.primary,
|
|
75
|
+
backgroundColor,
|
|
91
76
|
borderColor: theme.colors.background.surface,
|
|
92
77
|
},
|
|
93
78
|
]}
|
|
94
79
|
>
|
|
95
|
-
<
|
|
80
|
+
<ScaleSizeProvider scaleSizeMaxRate={1}>
|
|
96
81
|
<Text
|
|
97
82
|
numberOfLines={1}
|
|
98
83
|
typography={'action_xxs_bold'}
|
|
@@ -100,7 +85,7 @@ const TabBadge: React.FC<{ label: string; vertical?: boolean }> = ({
|
|
|
100
85
|
>
|
|
101
86
|
{label}
|
|
102
87
|
</Text>
|
|
103
|
-
</
|
|
88
|
+
</ScaleSizeProvider>
|
|
104
89
|
</View>
|
|
105
90
|
);
|
|
106
91
|
if (vertical) {
|
|
@@ -110,7 +95,8 @@ const TabBadge: React.FC<{ label: string; vertical?: boolean }> = ({
|
|
|
110
95
|
};
|
|
111
96
|
|
|
112
97
|
/**
|
|
113
|
-
* 24
|
|
98
|
+
* Tab icon (24) with its badge; active and inactive icons are stacked and cross-fade on
|
|
99
|
+
* focus.
|
|
114
100
|
*/
|
|
115
101
|
export function TabBarIcon({
|
|
116
102
|
focused,
|
|
@@ -29,8 +29,7 @@ const TabScreen: React.FC<any> = ({ route, navigation }) => {
|
|
|
29
29
|
|
|
30
30
|
const screenName = screen?.name || screen?.type?.name || 'Invalid';
|
|
31
31
|
const { isBackgroundToForeground } = useAppState();
|
|
32
|
-
// the floating
|
|
33
|
-
// keeps clear of the bar itself (scroll content running under the bar)
|
|
32
|
+
// Pad clear of the floating bar unless a Screen inside claims the inset to scroll under it.
|
|
34
33
|
const { inset: tabBarInset } = useContext(BottomTabInsetContext);
|
|
35
34
|
const [insetClaimed, setInsetClaimed] = useState(false);
|
|
36
35
|
const tabInsetValue = useMemo(
|
|
@@ -54,9 +53,6 @@ const TabScreen: React.FC<any> = ({ route, navigation }) => {
|
|
|
54
53
|
...data,
|
|
55
54
|
});
|
|
56
55
|
|
|
57
|
-
/**
|
|
58
|
-
* debug toast
|
|
59
|
-
*/
|
|
60
56
|
navigator?.maxApi?.showToastDebug?.({
|
|
61
57
|
appId: context.appId,
|
|
62
58
|
message: `${screenName} screen_navigated`,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
BottomTabBarProps,
|
|
2
3
|
BottomTabNavigationOptions,
|
|
3
4
|
createBottomTabNavigator,
|
|
4
5
|
} from '@react-navigation/bottom-tabs';
|
|
@@ -13,6 +14,7 @@ import {
|
|
|
13
14
|
} from 'react-native';
|
|
14
15
|
import { Icon } from '../../Icon';
|
|
15
16
|
import { BottomTabProps } from '../types';
|
|
17
|
+
import ScaleSizeProvider from '../ScaleSizeProvider';
|
|
16
18
|
import BottomTabBar, { hasCenterAction } from './BottomTabBar';
|
|
17
19
|
import { TabBarMetrics } from './metrics';
|
|
18
20
|
import { getTabBadge } from './TabBarIcon';
|
|
@@ -23,6 +25,8 @@ import TabScreen from './TabScreen';
|
|
|
23
25
|
import { ApplicationContext } from '../../Context';
|
|
24
26
|
import { useScreenLayout } from '../../Layout';
|
|
25
27
|
|
|
28
|
+
type SceneInterpolator = BottomTabNavigationOptions['sceneStyleInterpolator'];
|
|
29
|
+
|
|
26
30
|
const Tab = createBottomTabNavigator();
|
|
27
31
|
|
|
28
32
|
// the tab screens slide in index order over 280ms, CSS `ease`
|
|
@@ -32,12 +36,11 @@ const TAB_SWITCH_SPEC = {
|
|
|
32
36
|
};
|
|
33
37
|
|
|
34
38
|
/**
|
|
35
|
-
*
|
|
36
|
-
* width off screen on their side
|
|
39
|
+
* Tab slide interpolator. Scene progress is -1 for tabs before the active one and 1 for
|
|
40
|
+
* tabs after it, so they wait a full width off screen on their side.
|
|
37
41
|
*/
|
|
38
|
-
const getTabSlide =
|
|
39
|
-
(
|
|
40
|
-
({ current }) => ({
|
|
42
|
+
const getTabSlide = (width: number): SceneInterpolator => {
|
|
43
|
+
return ({ current }) => ({
|
|
41
44
|
sceneStyle: {
|
|
42
45
|
transform: [
|
|
43
46
|
{
|
|
@@ -49,6 +52,7 @@ const getTabSlide =
|
|
|
49
52
|
],
|
|
50
53
|
},
|
|
51
54
|
});
|
|
55
|
+
};
|
|
52
56
|
|
|
53
57
|
/**
|
|
54
58
|
* App tab navigator: the floating bar on phones, the rail or floating bar on
|
|
@@ -67,11 +71,11 @@ const BottomTab: React.FC<BottomTabProps> = ({
|
|
|
67
71
|
const { isIPhoneDuo } = useScreenLayout();
|
|
68
72
|
const { width: windowWidth } = useWindowDimensions();
|
|
69
73
|
const barInset = useDuoTabBarInset();
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
// The center action's button rises above the bar; tab content leaves room for it too.
|
|
75
|
+
let tabBarInset = barInset;
|
|
76
|
+
if (barInset && hasCenterAction(floatingButton, tabs.length)) {
|
|
77
|
+
tabBarInset = barInset + TabBarMetrics.ctaLift;
|
|
78
|
+
}
|
|
75
79
|
const initialIndex = tabs.findIndex(i => i.name === initialRouteName);
|
|
76
80
|
const activeIndex = React.useRef(initialIndex > 0 ? initialIndex : 0);
|
|
77
81
|
|
|
@@ -83,15 +87,15 @@ const BottomTab: React.FC<BottomTabProps> = ({
|
|
|
83
87
|
});
|
|
84
88
|
}, [navigation]);
|
|
85
89
|
|
|
86
|
-
// Focus, not mount:
|
|
87
|
-
// onFocus only fires on tab changes.
|
|
90
|
+
// Focus, not mount/onFocus: popping back from a pushed screen only refocuses BottomTab.
|
|
88
91
|
useFocusEffect(
|
|
89
92
|
React.useCallback(() => {
|
|
90
93
|
NativeModules?.MiniAppModule?.setShouldUseFloatingArrowBack?.(
|
|
91
94
|
activeIndex.current !== 0,
|
|
92
95
|
);
|
|
93
|
-
return () =>
|
|
96
|
+
return () => {
|
|
94
97
|
NativeModules?.MiniAppModule?.setShouldUseFloatingArrowBack?.(false);
|
|
98
|
+
};
|
|
95
99
|
}, []),
|
|
96
100
|
);
|
|
97
101
|
|
|
@@ -128,6 +132,21 @@ const BottomTab: React.FC<BottomTabProps> = ({
|
|
|
128
132
|
},
|
|
129
133
|
};
|
|
130
134
|
|
|
135
|
+
// One cap for the whole bar (labels, CTA, custom content) so it fits the fixed bar and notch.
|
|
136
|
+
const renderTabBar = (props: BottomTabBarProps) => {
|
|
137
|
+
const TabBar = isIPhoneDuo ? DuoTabBar : BottomTabBar;
|
|
138
|
+
return (
|
|
139
|
+
<ScaleSizeProvider scaleSizeMaxRate={TabBarMetrics.labelMaxScale}>
|
|
140
|
+
<TabBar
|
|
141
|
+
{...props}
|
|
142
|
+
floatingButton={floatingButton}
|
|
143
|
+
inactiveTintColor={theme.colors.text.secondary}
|
|
144
|
+
activeTintColor={theme.colors.primary}
|
|
145
|
+
/>
|
|
146
|
+
</ScaleSizeProvider>
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
|
|
131
150
|
return (
|
|
132
151
|
<DuoBarCompressionProvider
|
|
133
152
|
behavior={compressionBehavior}
|
|
@@ -145,23 +164,7 @@ const BottomTab: React.FC<BottomTabProps> = ({
|
|
|
145
164
|
transitionSpec: TAB_SWITCH_SPEC,
|
|
146
165
|
sceneStyleInterpolator: getTabSlide(windowWidth),
|
|
147
166
|
}}
|
|
148
|
-
tabBar={
|
|
149
|
-
isIPhoneDuo ? (
|
|
150
|
-
<DuoTabBar
|
|
151
|
-
{...props}
|
|
152
|
-
floatingButton={floatingButton}
|
|
153
|
-
inactiveTintColor={theme.colors.text.secondary}
|
|
154
|
-
activeTintColor={theme.colors.primary}
|
|
155
|
-
/>
|
|
156
|
-
) : (
|
|
157
|
-
<BottomTabBar
|
|
158
|
-
{...props}
|
|
159
|
-
floatingButton={floatingButton}
|
|
160
|
-
inactiveTintColor={theme.colors.text.secondary}
|
|
161
|
-
activeTintColor={theme.colors.primary}
|
|
162
|
-
/>
|
|
163
|
-
)
|
|
164
|
-
}
|
|
167
|
+
tabBar={renderTabBar}
|
|
165
168
|
initialRouteName={initialRouteName}
|
|
166
169
|
>
|
|
167
170
|
{tabs.map((item, index) => (
|