@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.
- package/Application/BottomSheet.tsx +398 -86
- package/Application/BottomTab/BottomTabBar.tsx +275 -215
- package/Application/BottomTab/CustomBottomTabItem.tsx +107 -131
- package/Application/BottomTab/DuoBarCompression.tsx +28 -14
- package/Application/BottomTab/DuoTabBar.tsx +540 -32
- package/Application/BottomTab/TabBarIcon.tsx +72 -146
- package/Application/BottomTab/index.tsx +353 -89
- package/Application/BottomTab/useLiquidSelection.ts +374 -0
- package/Application/Components/BackgroundImageView.tsx +0 -4
- package/Application/Components/DuoGlassBackground.tsx +5 -7
- package/Application/Components/HeaderAnimated.tsx +13 -41
- package/Application/Components/HeaderBackground.tsx +3 -20
- package/Application/Components/HeaderExtendHeader.tsx +46 -66
- package/Application/Components/HeaderLeft.tsx +18 -5
- package/Application/Components/HeaderRight.tsx +529 -8
- package/Application/Components/HeaderTitle.tsx +579 -16
- package/Application/Components/NavigationButton.tsx +11 -18
- package/Application/Components/SearchHeader.tsx +18 -38
- package/Application/Localize.ts +0 -7
- package/Application/ModalScreen.tsx +18 -41
- package/Application/Navigation.ts +17 -15
- package/Application/NavigationContainer.tsx +21 -23
- package/Application/Navigator.ts +48 -20
- package/Application/ScaleSizeProvider.tsx +6 -13
- package/Application/StackScreen.tsx +172 -27
- package/Application/TooltipPortal.tsx +5 -12
- package/Application/WidgetContainer.tsx +7 -20
- package/Application/device.ts +52 -0
- package/Application/index.ts +1 -23
- package/Application/types.ts +242 -17
- package/Application/utils.tsx +493 -0
- package/Badge/Badge.tsx +0 -5
- package/Badge/BadgeDot.tsx +0 -1
- package/Badge/BadgeDotAnimation.tsx +7 -15
- package/Badge/BadgeRibbon.tsx +39 -47
- package/Badge/Shape.tsx +0 -2
- package/Badge/styles.ts +0 -2
- package/Badge/types.ts +2 -2
- package/Button/index.tsx +152 -21
- package/Button/styles.ts +1 -1
- package/CheckBox/index.tsx +6 -5
- package/Consts/theme.ts +10 -10
- package/Context/index.ts +1 -5
- package/Divider/DashDivider.tsx +11 -11
- package/Divider/index.tsx +7 -21
- package/FoundationList/index.tsx +0 -4
- package/Icon/index.tsx +6 -6
- package/Icon/types.ts +1 -1
- package/IconButton/index.tsx +12 -4
- package/Image/index.tsx +7 -9
- package/Input/Input.tsx +12 -10
- package/Input/InputDropDown.tsx +13 -10
- package/Input/InputMoney.tsx +152 -45
- package/Input/InputOTP.tsx +34 -36
- package/Input/InputPhoneNumber.tsx +5 -8
- package/Input/InputSearch.tsx +111 -19
- package/Input/InputTextArea.tsx +5 -5
- package/Input/SystemTextInput.tsx +2 -7
- package/Input/TextTyping.tsx +0 -4
- package/Input/common.tsx +17 -31
- package/Input/index.tsx +21 -24
- package/Input/styles.ts +5 -25
- package/Input/utils.ts +12 -14
- package/Layout/Card.tsx +4 -7
- package/Layout/FloatingButton.tsx +21 -26
- package/Layout/Item.tsx +2 -6
- package/Layout/ItemList.tsx +7 -9
- package/Layout/ItemSectionList.tsx +1 -2
- package/Layout/ReservedRegions.tsx +17 -34
- package/Layout/Screen.tsx +696 -122
- package/Layout/Section.tsx +7 -9
- package/Layout/TrackingScope.tsx +0 -1
- package/Layout/index.ts +4 -10
- package/Layout/styles.ts +0 -2
- package/Layout/types.ts +4 -2
- package/Layout/utils.ts +181 -40
- package/Loader/DotLoader.tsx +3 -11
- package/Loader/Loader.tsx +0 -4
- package/Loader/ProgressBar.tsx +6 -3
- package/Loader/Spinner.tsx +3 -11
- package/Loader/styles.ts +0 -4
- package/Loader/utils.ts +7 -11
- package/Pagination/Dot.tsx +0 -4
- package/Pagination/PaginationDot.tsx +0 -1
- package/Pagination/PaginationNumber.tsx +3 -5
- package/Pagination/PaginationScroll.tsx +0 -5
- package/Pagination/PaginationWhiteDot.tsx +0 -1
- package/Pagination/index.tsx +0 -4
- package/Pagination/types.ts +2 -2
- package/Popup/PopupNotify.tsx +102 -94
- package/Popup/PopupPromotion.tsx +11 -9
- package/Popup/types.ts +4 -11
- package/Popup/utils.ts +18 -50
- package/Radio/index.tsx +10 -6
- package/Radio/styles.ts +0 -6
- package/Skeleton/index.tsx +9 -9
- package/Skeleton/styles.ts +0 -1
- package/Switch/index.tsx +0 -1
- package/Tag/index.tsx +4 -8
- package/Tag/types.ts +3 -3
- package/Text/index.tsx +5 -25
- package/Text/styles.ts +1 -1
- package/Text/types.ts +6 -1
- package/Text/utils.ts +4 -20
- package/Title/index.tsx +40 -42
- package/Title/styles.ts +0 -6
- package/ViewBoundary/index.tsx +2 -4
- package/index.ts +6 -0
- package/package.json +1 -2
- package/Application/BottomSheet.hooks.ts +0 -195
- package/Application/BottomSheet.parts.tsx +0 -157
- package/Application/BottomSheet.styles.ts +0 -43
- package/Application/BottomTab/ActiveIndicator.tsx +0 -91
- package/Application/BottomTab/BottomTabBar.styles.ts +0 -65
- package/Application/BottomTab/BottomTabInset.tsx +0 -18
- package/Application/BottomTab/CurvedContainer.tsx +0 -155
- package/Application/BottomTab/DuoRailTabBar.tsx +0 -223
- package/Application/BottomTab/DuoTabBar.styles.ts +0 -81
- package/Application/BottomTab/TabScreen.tsx +0 -160
- package/Application/BottomTab/metrics.ts +0 -164
- package/Application/BottomTab/tabItems.ts +0 -46
- package/Application/BottomTab/usePressLift.ts +0 -32
- package/Application/Components/HeaderRight.styles.ts +0 -146
- package/Application/Components/HeaderTitle.shared.ts +0 -44
- package/Application/Components/HeaderTitle.styles.ts +0 -125
- package/Application/Components/HeaderToolkitAction.tsx +0 -180
- package/Application/Components/SwipeBackHaptic.tsx +0 -95
- package/Application/Components/TitleJourney.tsx +0 -110
- package/Application/Components/TitleLocation.tsx +0 -73
- package/Application/Components/TitleUser.tsx +0 -304
- package/Application/Components/useToolkitActions.tsx +0 -218
- package/Application/ModalIconButton.tsx +0 -66
- package/Application/StackScreen.tracking.ts +0 -143
- package/Application/headerLayout.ts +0 -158
- package/Application/hooks.ts +0 -137
- package/Application/modalLayout.ts +0 -176
- package/Application/navigationOptions.tsx +0 -212
- package/Application/types.header.ts +0 -121
- package/Application/types.tabs.ts +0 -48
- package/Application/types.theme.ts +0 -87
- package/Application/utils.ts +0 -107
- package/Button/utils.ts +0 -133
- package/Input/InputMoneyView.tsx +0 -194
- package/Input/SearchTextTyping.tsx +0 -108
- package/Input/moneyUtils.ts +0 -23
- package/Layout/layoutMetrics.ts +0 -58
- package/Layout/layoutTypes.ts +0 -86
- package/Layout/screenContent.tsx +0 -92
- package/Layout/screenFooter.tsx +0 -63
- package/Layout/screenHeader.tsx +0 -321
- package/Layout/screenQuickReturn.tsx +0 -64
- package/Layout/screenScroll.ts +0 -107
- package/Layout/screenTypes.ts +0 -143
|
@@ -1,69 +1,577 @@
|
|
|
1
1
|
import { BottomTabBarProps } from '@react-navigation/bottom-tabs';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { CommonActions, Route } from '@react-navigation/native';
|
|
3
|
+
import React, { ReactNode, useContext, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import {
|
|
5
|
+
LayoutChangeEvent,
|
|
6
|
+
StyleProp,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
TouchableOpacity,
|
|
9
|
+
View,
|
|
10
|
+
ViewStyle,
|
|
11
|
+
} from 'react-native';
|
|
12
|
+
import { GestureDetector } from 'react-native-gesture-handler';
|
|
13
|
+
import Animated from 'react-native-reanimated';
|
|
14
|
+
import { Colors, Radius, Spacing } from '../../Consts';
|
|
15
|
+
import { ApplicationContext, MiniAppContext } from '../../Context';
|
|
16
|
+
import { Icon } from '../../Icon';
|
|
17
|
+
import { DuoMetrics, useScreenLayout } from '../../Layout/utils';
|
|
18
|
+
import { Text } from '../../Text';
|
|
19
|
+
import { useDuoBarCompression } from './DuoBarCompression';
|
|
5
20
|
import { FloatingButtonProps } from '../types';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
21
|
+
import { TabBarIcon } from './TabBarIcon';
|
|
22
|
+
import {
|
|
23
|
+
LiquidSelection,
|
|
24
|
+
useLiquidItem,
|
|
25
|
+
useLiquidSelection,
|
|
26
|
+
usePressLift,
|
|
27
|
+
} from './useLiquidSelection';
|
|
11
28
|
|
|
12
|
-
type
|
|
29
|
+
type Props = BottomTabBarProps & {
|
|
13
30
|
activeTintColor: string;
|
|
14
31
|
inactiveTintColor: string;
|
|
15
32
|
floatingButton?: FloatingButtonProps;
|
|
16
33
|
};
|
|
17
34
|
|
|
35
|
+
const ITEM_SIZE = DuoMetrics.controlSize;
|
|
36
|
+
const ICON_SIZE = 28;
|
|
37
|
+
const QR_ICON_SIZE = 24;
|
|
38
|
+
const RAIL_PADDING = 6;
|
|
39
|
+
const RAIL_GAP = Spacing.XXS;
|
|
40
|
+
const RAIL_PITCH = ITEM_SIZE + RAIL_GAP;
|
|
41
|
+
// selection bubble overflows the 48 rail cell by 5 above and below (Figma MT2)
|
|
42
|
+
const RAIL_BUBBLE_WIDTH = 44;
|
|
43
|
+
const RAIL_BUBBLE_HEIGHT = 58;
|
|
44
|
+
const FLOATING_HEIGHT = DuoMetrics.floatingTabBarHeight;
|
|
45
|
+
const FLOATING_PADDING = Spacing.XS;
|
|
46
|
+
// the system bar sizes its pill to the tabs instead of stretching it across the display
|
|
47
|
+
const FLOATING_ITEM_WIDTH = 80;
|
|
48
|
+
const FLOATING_BUBBLE_RADIUS = (FLOATING_HEIGHT - 2 * FLOATING_PADDING) / 2;
|
|
49
|
+
|
|
18
50
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
51
|
+
* distance from the screen bottom to the floating tab bar, overlapping the home
|
|
52
|
+
* indicator inset like the system tab bar
|
|
53
|
+
*/
|
|
54
|
+
const getFloatingTabBarBottom = (bottomInset: number) =>
|
|
55
|
+
Math.max(bottomInset - DuoMetrics.floatingTabBarInsetOverlap, Spacing.S);
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* space tab content leaves under the Duo floating tab bar, 0 elsewhere
|
|
21
59
|
*/
|
|
22
60
|
const useDuoTabBarInset = () => {
|
|
23
61
|
const { isIPhoneDuo, sideBar, insets } = useScreenLayout();
|
|
24
|
-
if (isIPhoneDuo
|
|
62
|
+
if (!isIPhoneDuo || sideBar) {
|
|
25
63
|
return 0;
|
|
26
64
|
}
|
|
27
|
-
return
|
|
65
|
+
return FLOATING_HEIGHT + getFloatingTabBarBottom(insets.bottom);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const BarMaterial: React.FC<{ radius: number }> = ({ radius }) => {
|
|
69
|
+
const { theme } = useContext(ApplicationContext);
|
|
70
|
+
return (
|
|
71
|
+
<View
|
|
72
|
+
pointerEvents={'none'}
|
|
73
|
+
style={[
|
|
74
|
+
StyleSheet.absoluteFill,
|
|
75
|
+
styles.barMaterial,
|
|
76
|
+
{
|
|
77
|
+
borderRadius: radius,
|
|
78
|
+
backgroundColor: theme.colors.background.surface,
|
|
79
|
+
borderColor: theme.colors.border.default,
|
|
80
|
+
},
|
|
81
|
+
]}
|
|
82
|
+
/>
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// Figma Home-2026 tab bar "Selection": brand pink at 8%
|
|
87
|
+
const SELECTION_TINT_ALPHA = '14';
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* pink tinted capsule under the selected tab
|
|
91
|
+
*/
|
|
92
|
+
const SelectionMaterial: React.FC<{ radius: number }> = ({ radius }) => {
|
|
93
|
+
const { theme } = useContext(ApplicationContext);
|
|
94
|
+
return (
|
|
95
|
+
<View
|
|
96
|
+
pointerEvents={'none'}
|
|
97
|
+
style={[
|
|
98
|
+
StyleSheet.absoluteFill,
|
|
99
|
+
{
|
|
100
|
+
borderRadius: radius,
|
|
101
|
+
backgroundColor: theme.colors.primary + SELECTION_TINT_ALPHA,
|
|
102
|
+
},
|
|
103
|
+
]}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* tab label at its design size: like the system tab bar it doesn't grow with the wide
|
|
110
|
+
* Duo displays, which Text otherwise scales up to 5pt
|
|
111
|
+
*/
|
|
112
|
+
const TabLabel: React.FC<{
|
|
113
|
+
label: string;
|
|
114
|
+
color: string;
|
|
115
|
+
typography: 'label_xs_medium';
|
|
116
|
+
}> = ({ label, color, typography }) => {
|
|
117
|
+
const context = useContext<any>(MiniAppContext);
|
|
118
|
+
return (
|
|
119
|
+
<MiniAppContext.Provider
|
|
120
|
+
value={{
|
|
121
|
+
...context,
|
|
122
|
+
fontScale: { useOSScaleRate: false, userScaleRate: 1 },
|
|
123
|
+
}}
|
|
124
|
+
>
|
|
125
|
+
<Text numberOfLines={1} typography={typography} color={color}>
|
|
126
|
+
{label}
|
|
127
|
+
</Text>
|
|
128
|
+
</MiniAppContext.Provider>
|
|
129
|
+
);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const getTabItems = ({
|
|
133
|
+
state,
|
|
134
|
+
descriptors,
|
|
135
|
+
navigation,
|
|
136
|
+
activeTintColor,
|
|
137
|
+
inactiveTintColor,
|
|
138
|
+
}: Props) => {
|
|
139
|
+
return state.routes.map((route: Route<string>, index: number) => {
|
|
140
|
+
const { options } = descriptors[route.key];
|
|
141
|
+
const focused = index === state.index;
|
|
142
|
+
const label = options.title ?? route.name;
|
|
143
|
+
|
|
144
|
+
const onPress = () => {
|
|
145
|
+
const event = navigation.emit({
|
|
146
|
+
type: 'tabPress',
|
|
147
|
+
target: route.key,
|
|
148
|
+
canPreventDefault: true,
|
|
149
|
+
});
|
|
150
|
+
if (!focused && !event.defaultPrevented) {
|
|
151
|
+
navigation.dispatch({
|
|
152
|
+
...CommonActions.navigate(route.name),
|
|
153
|
+
target: state.key,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const onLongPress = () => {
|
|
159
|
+
navigation.emit({ type: 'tabLongPress', target: route.key });
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const renderIcon = (active: boolean) =>
|
|
163
|
+
options.tabBarIcon && (
|
|
164
|
+
<TabBarIcon
|
|
165
|
+
route={route}
|
|
166
|
+
badge={options.tabBarBadge}
|
|
167
|
+
badgeStyle={options.tabBarBadgeStyle}
|
|
168
|
+
activeOpacity={active ? 1 : 0}
|
|
169
|
+
inactiveOpacity={active ? 0 : 1}
|
|
170
|
+
activeTintColor={activeTintColor}
|
|
171
|
+
inactiveTintColor={inactiveTintColor}
|
|
172
|
+
renderIcon={options.tabBarIcon}
|
|
173
|
+
style={styles.icon}
|
|
174
|
+
/>
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
return { route, focused, label, onPress, onLongPress, renderIcon };
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const QrIcon: React.FC<{ icon: FloatingButtonProps['icon']; size: number }> = ({
|
|
182
|
+
icon,
|
|
183
|
+
size,
|
|
184
|
+
}) => {
|
|
185
|
+
if (typeof icon === 'string') {
|
|
186
|
+
return <Icon source={icon} size={size} color={Colors.black_01} />;
|
|
187
|
+
}
|
|
188
|
+
return <>{icon}</>;
|
|
28
189
|
};
|
|
29
190
|
|
|
191
|
+
type TabItem = ReturnType<typeof getTabItems>[number];
|
|
192
|
+
|
|
30
193
|
/**
|
|
31
|
-
*
|
|
194
|
+
* tab item: a tap is handled here as before, a drag over the bar is handled by the bar's
|
|
195
|
+
* gesture. The active layer fades in as the lens passes over it
|
|
32
196
|
*/
|
|
33
|
-
const
|
|
197
|
+
const LiquidTabItem: React.FC<{
|
|
198
|
+
item: TabItem;
|
|
199
|
+
itemIndex: number;
|
|
200
|
+
selection: LiquidSelection;
|
|
201
|
+
onSelect: () => void;
|
|
202
|
+
renderContent: (active: boolean) => ReactNode;
|
|
203
|
+
style: StyleProp<ViewStyle>;
|
|
204
|
+
}> = ({ item, itemIndex, selection, onSelect, renderContent, style }) => {
|
|
205
|
+
const { activeStyle, popStyle } = useLiquidItem(selection, itemIndex);
|
|
206
|
+
const activeLayerStyle = useMemo(
|
|
207
|
+
() => [StyleSheet.absoluteFill, styles.itemLayer, activeStyle],
|
|
208
|
+
[activeStyle],
|
|
209
|
+
);
|
|
210
|
+
// like the system tab bar, a held tab is still picked when released
|
|
211
|
+
const longPressed = useRef(false);
|
|
212
|
+
|
|
213
|
+
return (
|
|
214
|
+
<TouchableOpacity
|
|
215
|
+
accessibilityRole={'tab'}
|
|
216
|
+
accessibilityLabel={item.label}
|
|
217
|
+
accessibilityState={{ selected: item.focused }}
|
|
218
|
+
activeOpacity={1}
|
|
219
|
+
onPressIn={() => {
|
|
220
|
+
longPressed.current = false;
|
|
221
|
+
selection.pressIn(itemIndex);
|
|
222
|
+
}}
|
|
223
|
+
onPressOut={() => {
|
|
224
|
+
if (selection.pressOut() && longPressed.current) {
|
|
225
|
+
onSelect();
|
|
226
|
+
}
|
|
227
|
+
}}
|
|
228
|
+
onPress={onSelect}
|
|
229
|
+
onLongPress={() => {
|
|
230
|
+
longPressed.current = true;
|
|
231
|
+
item.onLongPress();
|
|
232
|
+
}}
|
|
233
|
+
style={style}
|
|
234
|
+
>
|
|
235
|
+
<Animated.View style={popStyle}>
|
|
236
|
+
<View style={styles.itemLayer}>{renderContent(false)}</View>
|
|
237
|
+
<Animated.View style={activeLayerStyle}>
|
|
238
|
+
{renderContent(true)}
|
|
239
|
+
</Animated.View>
|
|
240
|
+
</Animated.View>
|
|
241
|
+
</TouchableOpacity>
|
|
242
|
+
);
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* column of icon-only tab items with the sliding selection bubble
|
|
247
|
+
*/
|
|
248
|
+
const Rail: React.FC<{
|
|
249
|
+
items: TabItem[];
|
|
250
|
+
index: number;
|
|
251
|
+
onItemPress?: () => void;
|
|
252
|
+
}> = ({ items, index, onItemPress }) => {
|
|
253
|
+
const onSelect = (itemIndex: number) => {
|
|
254
|
+
items[itemIndex]?.onPress();
|
|
255
|
+
onItemPress?.();
|
|
256
|
+
};
|
|
257
|
+
const selection = useLiquidSelection({
|
|
258
|
+
count: items.length,
|
|
259
|
+
pitch: RAIL_PITCH,
|
|
260
|
+
firstCenter: RAIL_PADDING + ITEM_SIZE / 2,
|
|
261
|
+
axis: 'y',
|
|
262
|
+
index,
|
|
263
|
+
onSelect,
|
|
264
|
+
});
|
|
265
|
+
const { barStyle, bubbleStyle } = selection;
|
|
266
|
+
// stable style arrays: the tab switch re-renders the rail while the lens is still
|
|
267
|
+
// springing back, a new array would re-attach the animated style mid animation
|
|
268
|
+
const railStyle = useMemo(() => [styles.rail, barStyle], [barStyle]);
|
|
269
|
+
const railBubbleStyle = useMemo(
|
|
270
|
+
() => [styles.railBubble, bubbleStyle],
|
|
271
|
+
[bubbleStyle],
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
return (
|
|
275
|
+
<GestureDetector gesture={selection.gesture}>
|
|
276
|
+
<Animated.View style={railStyle} accessibilityLabel={'bottom_tab_bar'}>
|
|
277
|
+
<BarMaterial radius={ITEM_SIZE / 2} />
|
|
278
|
+
<Animated.View pointerEvents={'none'} style={railBubbleStyle}>
|
|
279
|
+
<SelectionMaterial radius={RAIL_BUBBLE_WIDTH / 2} />
|
|
280
|
+
</Animated.View>
|
|
281
|
+
{items.map((item, itemIndex) => (
|
|
282
|
+
<LiquidTabItem
|
|
283
|
+
key={item.route.key}
|
|
284
|
+
item={item}
|
|
285
|
+
itemIndex={itemIndex}
|
|
286
|
+
selection={selection}
|
|
287
|
+
onSelect={() => onSelect(itemIndex)}
|
|
288
|
+
renderContent={item.renderIcon}
|
|
289
|
+
style={styles.railItem}
|
|
290
|
+
/>
|
|
291
|
+
))}
|
|
292
|
+
</Animated.View>
|
|
293
|
+
</GestureDetector>
|
|
294
|
+
);
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* vertical bar anchored to the bottom of the Duo side bar, QR button below it (Figma MT1-C/E).
|
|
299
|
+
* When the side bar is short, it can shrink to one button showing the current tab
|
|
300
|
+
* (HIG "Tab bar compressed"); tapping it expands the rail and compresses the toolbar
|
|
301
|
+
*/
|
|
302
|
+
const DuoRailTabBar: React.FC<Props> = props => {
|
|
303
|
+
const { theme } = useContext(ApplicationContext);
|
|
304
|
+
const { sideBar } = useScreenLayout();
|
|
305
|
+
const { tabBarCompressed, expandTabBar, onTabSelected } =
|
|
306
|
+
useDuoBarCompression();
|
|
307
|
+
const compactLift = usePressLift();
|
|
308
|
+
const { state, floatingButton } = props;
|
|
309
|
+
const items = getTabItems(props);
|
|
310
|
+
const current = items[state.index];
|
|
311
|
+
|
|
312
|
+
const columnStyle = sideBar && [
|
|
313
|
+
styles.railColumn,
|
|
314
|
+
{
|
|
315
|
+
[sideBar.edge]: 0,
|
|
316
|
+
width: sideBar.width,
|
|
317
|
+
bottom: sideBar.bottom,
|
|
318
|
+
},
|
|
319
|
+
sideBar.edge === 'right' ? styles.railColumnRight : styles.railColumnLeft,
|
|
320
|
+
];
|
|
321
|
+
|
|
322
|
+
const qr = floatingButton && (
|
|
323
|
+
<TouchableOpacity
|
|
324
|
+
accessibilityRole={'button'}
|
|
325
|
+
accessibilityLabel={floatingButton.label}
|
|
326
|
+
onPress={floatingButton.onPress}
|
|
327
|
+
style={[styles.railQr, { backgroundColor: theme.colors.primary }]}
|
|
328
|
+
>
|
|
329
|
+
<QrIcon icon={floatingButton.icon} size={QR_ICON_SIZE} />
|
|
330
|
+
</TouchableOpacity>
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
if (!sideBar) {
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (!tabBarCompressed) {
|
|
338
|
+
return (
|
|
339
|
+
<View pointerEvents={'box-none'} style={columnStyle}>
|
|
340
|
+
<Rail items={items} index={state.index} onItemPress={onTabSelected} />
|
|
341
|
+
{qr}
|
|
342
|
+
</View>
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return (
|
|
347
|
+
<View pointerEvents={'box-none'} style={columnStyle}>
|
|
348
|
+
<Animated.View style={compactLift.style}>
|
|
349
|
+
<TouchableOpacity
|
|
350
|
+
accessibilityRole={'button'}
|
|
351
|
+
accessibilityLabel={current?.label}
|
|
352
|
+
accessibilityHint={'bottom_tab_bar'}
|
|
353
|
+
activeOpacity={1}
|
|
354
|
+
onPressIn={compactLift.onPressIn}
|
|
355
|
+
onPressOut={compactLift.onPressOut}
|
|
356
|
+
onPress={expandTabBar}
|
|
357
|
+
style={styles.railCompact}
|
|
358
|
+
>
|
|
359
|
+
<BarMaterial radius={Radius.XL} />
|
|
360
|
+
{current?.renderIcon(true)}
|
|
361
|
+
</TouchableOpacity>
|
|
362
|
+
</Animated.View>
|
|
363
|
+
{qr}
|
|
364
|
+
</View>
|
|
365
|
+
);
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* floating labelled bar for the unfolded portrait display, QR pinned in its own
|
|
370
|
+
* platter on the trailing side
|
|
371
|
+
*/
|
|
372
|
+
const DuoFloatingTabBar: React.FC<Props> = props => {
|
|
373
|
+
const { theme } = useContext(ApplicationContext);
|
|
34
374
|
const { insets } = useScreenLayout();
|
|
35
|
-
const {
|
|
36
|
-
const
|
|
375
|
+
const { state, floatingButton, activeTintColor, inactiveTintColor } = props;
|
|
376
|
+
const items = getTabItems(props);
|
|
377
|
+
const [rowWidth, setRowWidth] = useState(0);
|
|
378
|
+
const cellWidth = rowWidth / state.routes.length;
|
|
379
|
+
|
|
380
|
+
const selection = useLiquidSelection({
|
|
381
|
+
count: items.length,
|
|
382
|
+
pitch: cellWidth,
|
|
383
|
+
firstCenter: cellWidth / 2,
|
|
384
|
+
axis: 'x',
|
|
385
|
+
index: state.index,
|
|
386
|
+
onSelect: itemIndex => items[itemIndex]?.onPress(),
|
|
387
|
+
});
|
|
388
|
+
const { barStyle, bubbleStyle } = selection;
|
|
389
|
+
const tabCount = state.routes.length;
|
|
390
|
+
// stable style arrays, see Rail
|
|
391
|
+
const floatingBarStyle = useMemo(
|
|
392
|
+
() => [
|
|
393
|
+
styles.floatingBar,
|
|
394
|
+
{ width: tabCount * FLOATING_ITEM_WIDTH + 2 * FLOATING_PADDING },
|
|
395
|
+
barStyle,
|
|
396
|
+
],
|
|
397
|
+
[tabCount, barStyle],
|
|
398
|
+
);
|
|
399
|
+
const floatingBubbleStyle = useMemo(
|
|
400
|
+
() => [styles.floatingBubble, { width: cellWidth }, bubbleStyle],
|
|
401
|
+
[cellWidth, bubbleStyle],
|
|
402
|
+
);
|
|
403
|
+
|
|
404
|
+
const onRowLayout = (e: LayoutChangeEvent) =>
|
|
405
|
+
setRowWidth(e.nativeEvent.layout.width);
|
|
37
406
|
|
|
38
407
|
return (
|
|
39
408
|
<View
|
|
40
409
|
pointerEvents={'box-none'}
|
|
41
410
|
style={[
|
|
42
411
|
styles.floating,
|
|
43
|
-
{
|
|
412
|
+
{
|
|
413
|
+
left: insets.left + DuoMetrics.floatingTabBarMargin,
|
|
414
|
+
right: insets.right + DuoMetrics.floatingTabBarMargin,
|
|
415
|
+
bottom: getFloatingTabBarBottom(insets.bottom),
|
|
416
|
+
},
|
|
44
417
|
]}
|
|
45
418
|
>
|
|
46
|
-
<
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
419
|
+
<Animated.View
|
|
420
|
+
style={floatingBarStyle}
|
|
421
|
+
accessibilityLabel={'bottom_tab_bar'}
|
|
422
|
+
>
|
|
423
|
+
<BarMaterial radius={FLOATING_HEIGHT / 2} />
|
|
424
|
+
<GestureDetector gesture={selection.gesture}>
|
|
425
|
+
<View style={styles.floatingRow} onLayout={onRowLayout}>
|
|
426
|
+
{rowWidth > 0 && (
|
|
427
|
+
<Animated.View pointerEvents={'none'} style={floatingBubbleStyle}>
|
|
428
|
+
<SelectionMaterial radius={FLOATING_BUBBLE_RADIUS} />
|
|
429
|
+
</Animated.View>
|
|
430
|
+
)}
|
|
431
|
+
{items.map((item, index) => (
|
|
432
|
+
<LiquidTabItem
|
|
433
|
+
key={item.route.key}
|
|
434
|
+
item={item}
|
|
435
|
+
itemIndex={index}
|
|
436
|
+
selection={selection}
|
|
437
|
+
onSelect={item.onPress}
|
|
438
|
+
renderContent={active => (
|
|
439
|
+
<>
|
|
440
|
+
{item.renderIcon(active)}
|
|
441
|
+
<TabLabel
|
|
442
|
+
label={item.label}
|
|
443
|
+
typography={'label_xs_medium'}
|
|
444
|
+
color={active ? activeTintColor : inactiveTintColor}
|
|
445
|
+
/>
|
|
446
|
+
</>
|
|
447
|
+
)}
|
|
448
|
+
style={styles.floatingItem}
|
|
449
|
+
/>
|
|
450
|
+
))}
|
|
451
|
+
</View>
|
|
452
|
+
</GestureDetector>
|
|
453
|
+
</Animated.View>
|
|
454
|
+
{floatingButton && (
|
|
455
|
+
<TouchableOpacity
|
|
456
|
+
accessibilityRole={'button'}
|
|
457
|
+
accessibilityLabel={floatingButton.label}
|
|
458
|
+
onPress={floatingButton.onPress}
|
|
459
|
+
style={[styles.floatingQr, { backgroundColor: theme.colors.primary }]}
|
|
460
|
+
>
|
|
461
|
+
<QrIcon icon={floatingButton.icon} size={QR_ICON_SIZE} />
|
|
462
|
+
</TouchableOpacity>
|
|
463
|
+
)}
|
|
53
464
|
</View>
|
|
54
465
|
);
|
|
55
466
|
};
|
|
56
467
|
|
|
57
468
|
/**
|
|
58
|
-
* iPhone Duo tab bar:
|
|
469
|
+
* iPhone Duo tab bar: rail in the side bar, or a floating bar when unfolded portrait
|
|
59
470
|
*/
|
|
60
|
-
const DuoTabBar: React.FC<
|
|
471
|
+
const DuoTabBar: React.FC<Props> = props => {
|
|
61
472
|
const { sideBar } = useScreenLayout();
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
473
|
+
return sideBar ? (
|
|
474
|
+
<DuoRailTabBar {...props} />
|
|
475
|
+
) : (
|
|
476
|
+
<DuoFloatingTabBar {...props} />
|
|
477
|
+
);
|
|
66
478
|
};
|
|
67
479
|
|
|
68
|
-
|
|
480
|
+
const styles = StyleSheet.create({
|
|
481
|
+
barMaterial: {
|
|
482
|
+
borderWidth: 1,
|
|
483
|
+
},
|
|
484
|
+
icon: {
|
|
485
|
+
width: ICON_SIZE,
|
|
486
|
+
height: ICON_SIZE,
|
|
487
|
+
},
|
|
488
|
+
railColumn: {
|
|
489
|
+
position: 'absolute',
|
|
490
|
+
gap: Spacing.M,
|
|
491
|
+
},
|
|
492
|
+
railColumnRight: {
|
|
493
|
+
alignItems: 'flex-start',
|
|
494
|
+
paddingLeft: Spacing.M,
|
|
495
|
+
},
|
|
496
|
+
railColumnLeft: {
|
|
497
|
+
alignItems: 'flex-end',
|
|
498
|
+
paddingRight: Spacing.M,
|
|
499
|
+
},
|
|
500
|
+
railCompact: {
|
|
501
|
+
width: ITEM_SIZE,
|
|
502
|
+
height: ITEM_SIZE,
|
|
503
|
+
borderRadius: ITEM_SIZE / 2,
|
|
504
|
+
alignItems: 'center',
|
|
505
|
+
justifyContent: 'center',
|
|
506
|
+
},
|
|
507
|
+
rail: {
|
|
508
|
+
width: ITEM_SIZE,
|
|
509
|
+
paddingVertical: RAIL_PADDING,
|
|
510
|
+
gap: RAIL_GAP,
|
|
511
|
+
},
|
|
512
|
+
railBubble: {
|
|
513
|
+
position: 'absolute',
|
|
514
|
+
top: RAIL_PADDING - (RAIL_BUBBLE_HEIGHT - ITEM_SIZE) / 2,
|
|
515
|
+
left: (ITEM_SIZE - RAIL_BUBBLE_WIDTH) / 2,
|
|
516
|
+
width: RAIL_BUBBLE_WIDTH,
|
|
517
|
+
height: RAIL_BUBBLE_HEIGHT,
|
|
518
|
+
},
|
|
519
|
+
railItem: {
|
|
520
|
+
width: ITEM_SIZE,
|
|
521
|
+
height: ITEM_SIZE,
|
|
522
|
+
alignItems: 'center',
|
|
523
|
+
justifyContent: 'center',
|
|
524
|
+
},
|
|
525
|
+
railQr: {
|
|
526
|
+
width: ITEM_SIZE,
|
|
527
|
+
height: ITEM_SIZE,
|
|
528
|
+
borderRadius: ITEM_SIZE / 2,
|
|
529
|
+
alignItems: 'center',
|
|
530
|
+
justifyContent: 'center',
|
|
531
|
+
},
|
|
532
|
+
floating: {
|
|
533
|
+
position: 'absolute',
|
|
534
|
+
flexDirection: 'row',
|
|
535
|
+
justifyContent: 'center',
|
|
536
|
+
gap: Spacing.S,
|
|
537
|
+
},
|
|
538
|
+
floatingBar: {
|
|
539
|
+
flexShrink: 1,
|
|
540
|
+
height: FLOATING_HEIGHT,
|
|
541
|
+
padding: FLOATING_PADDING,
|
|
542
|
+
},
|
|
543
|
+
floatingRow: {
|
|
544
|
+
flex: 1,
|
|
545
|
+
flexDirection: 'row',
|
|
546
|
+
},
|
|
547
|
+
floatingBubble: {
|
|
548
|
+
position: 'absolute',
|
|
549
|
+
top: 0,
|
|
550
|
+
bottom: 0,
|
|
551
|
+
left: 0,
|
|
552
|
+
},
|
|
553
|
+
floatingItem: {
|
|
554
|
+
flex: 1,
|
|
555
|
+
alignItems: 'center',
|
|
556
|
+
justifyContent: 'center',
|
|
557
|
+
},
|
|
558
|
+
itemLayer: {
|
|
559
|
+
alignItems: 'center',
|
|
560
|
+
justifyContent: 'center',
|
|
561
|
+
gap: Spacing.XXS,
|
|
562
|
+
},
|
|
563
|
+
// pink fills the whole pinned platter
|
|
564
|
+
floatingQr: {
|
|
565
|
+
width: FLOATING_HEIGHT,
|
|
566
|
+
height: FLOATING_HEIGHT,
|
|
567
|
+
borderRadius: FLOATING_HEIGHT / 2,
|
|
568
|
+
alignItems: 'center',
|
|
569
|
+
justifyContent: 'center',
|
|
570
|
+
shadowColor: Colors.black_20,
|
|
571
|
+
shadowOffset: { width: 0, height: 6 },
|
|
572
|
+
shadowOpacity: 0.16,
|
|
573
|
+
shadowRadius: 16,
|
|
574
|
+
},
|
|
575
|
+
});
|
|
576
|
+
|
|
69
577
|
export { DuoTabBar, useDuoTabBarInset };
|