@momo-kits/foundation 0.169.17-beta.10 → 0.169.17-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Application/BottomSheet.tsx +2 -2
- package/Application/BottomTab/BottomTabBar.styles.ts +1 -1
- package/Application/BottomTab/DuoTabBar.styles.ts +1 -1
- package/Application/BottomTab/TabBarIcon.tsx +1 -1
- package/Application/BottomTab/index.tsx +1 -15
- package/Application/Components/HeaderExtendHeader.tsx +1 -3
- package/Application/Components/HeaderRight.tsx +3 -24
- package/Application/Components/SearchHeader.tsx +2 -3
- package/Application/ModalScreen.tsx +2 -2
- package/Application/StackScreen.tsx +6 -2
- package/Application/TooltipPortal.tsx +3 -3
- package/Application/headerLayout.ts +3 -7
- package/Application/hooks.ts +1 -1
- package/Application/modalLayout.ts +4 -12
- package/Application/types.tabs.ts +0 -8
- package/Button/index.tsx +2 -2
- package/Divider/DashDivider.tsx +2 -2
- package/Divider/index.tsx +3 -3
- package/FoundationList/index.tsx +1 -1
- package/Icon/types.ts +1 -2
- package/Image/index.tsx +70 -7
- package/Image/styles.ts +2 -0
- package/Image/types.ts +9 -1
- package/Input/Input.tsx +2 -2
- package/Input/InputMoney.tsx +7 -2
- package/Input/InputMoneyView.tsx +2 -2
- package/Input/InputOTP.tsx +2 -2
- package/Input/InputPhoneNumber.tsx +40 -22
- package/Input/InputSearch.tsx +2 -2
- package/Input/InputTextArea.tsx +2 -2
- package/Input/SearchTextTyping.tsx +2 -2
- package/Input/SystemTextInput.tsx +2 -1
- package/Input/TextTyping.tsx +7 -2
- package/Input/index.tsx +1 -14
- package/Layout/Screen.tsx +5 -11
- package/Layout/Section.tsx +3 -14
- package/Layout/screenFooter.tsx +21 -181
- package/Layout/screenHeader.tsx +41 -56
- package/Layout/screenTypes.ts +1 -16
- package/Layout/styles.ts +0 -10
- package/Layout/types.ts +0 -6
- package/Pagination/types.ts +6 -2
- package/package.json +28 -26
- package/Application/BottomTab/Legacy/BottomTabBar.styles.ts +0 -60
- package/Application/BottomTab/Legacy/BottomTabBar.tsx +0 -270
- package/Application/BottomTab/Legacy/CustomBottomTabItem.tsx +0 -153
- package/Application/BottomTab/Legacy/DuoBarCompression.tsx +0 -135
- package/Application/BottomTab/Legacy/DuoRailTabBar.tsx +0 -149
- package/Application/BottomTab/Legacy/DuoTabBar.parts.tsx +0 -202
- package/Application/BottomTab/Legacy/DuoTabBar.styles.ts +0 -123
- package/Application/BottomTab/Legacy/DuoTabBar.tsx +0 -151
- package/Application/BottomTab/Legacy/TabBarIcon.tsx +0 -113
- package/Application/BottomTab/Legacy/TabScreen.tsx +0 -177
- package/Application/BottomTab/Legacy/badge.ts +0 -41
- package/Application/BottomTab/Legacy/hooks.ts +0 -358
- package/Application/BottomTab/Legacy/index.styles.ts +0 -30
- package/Application/BottomTab/Legacy/index.tsx +0 -230
- package/Application/Components/useHeaderRightWidth.ts +0 -46
- package/Input/CountryCodeView.tsx +0 -93
- package/Layout/__tests__/screenFooter.test.ts +0 -56
package/Layout/screenHeader.tsx
CHANGED
|
@@ -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';
|
|
7
8
|
import { Colors, Spacing } from '../Consts';
|
|
8
9
|
import {
|
|
9
|
-
exportHeaderTitle,
|
|
10
10
|
HeaderBackground,
|
|
11
11
|
HeaderLeft,
|
|
12
12
|
HeaderTitle,
|
|
@@ -63,9 +63,8 @@ const getSearchTitleOptions = (
|
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
|
-
* Applies the Screen's navigation header (plain, extended, animated banner or search)
|
|
67
|
-
*
|
|
68
|
-
* search header setter and the tint.
|
|
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.
|
|
69
68
|
*/
|
|
70
69
|
export const useScreenHeader = ({
|
|
71
70
|
navigation,
|
|
@@ -84,7 +83,6 @@ export const useScreenHeader = ({
|
|
|
84
83
|
}: ScreenHeaderParams) => {
|
|
85
84
|
const currentTint = useRef<string | undefined>(undefined);
|
|
86
85
|
const appliedHeaderMode = useRef<string | undefined>(undefined);
|
|
87
|
-
const searchHeaderParams = useRef<SearchHeaderProps | undefined>(undefined);
|
|
88
86
|
const headerLayout = useHeaderLayout(contentLayout);
|
|
89
87
|
const frameOptions = useHeaderFrameOptions(contentLayout);
|
|
90
88
|
|
|
@@ -245,54 +243,45 @@ export const useScreenHeader = ({
|
|
|
245
243
|
}, [navigation?.instance, sharedValue, frameOptions]);
|
|
246
244
|
|
|
247
245
|
// the search field spans the content (or the stretch frame), clear of the side bar
|
|
248
|
-
// and status bar clusters
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
return <HeaderLeft {...props} floating />;
|
|
286
|
-
},
|
|
287
|
-
headerTitle: () => (
|
|
288
|
-
<SearchHeader {...params} animatedValue={sharedValue} />
|
|
289
|
-
),
|
|
290
|
-
};
|
|
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
|
+
};
|
|
291
282
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
[navigation?.instance, sharedValue, frameOptions, searchWidth, searchLeft],
|
|
295
|
-
);
|
|
283
|
+
navigation?.instance?.setOptions(options);
|
|
284
|
+
};
|
|
296
285
|
|
|
297
286
|
useEffect(() => {
|
|
298
287
|
const focus = navigation?.instance?.addListener?.('focus', () => {
|
|
@@ -313,9 +302,6 @@ export const useScreenHeader = ({
|
|
|
313
302
|
setHeaderType(headerType, appliedHeaderMode.current === headerType);
|
|
314
303
|
appliedHeaderMode.current = headerType;
|
|
315
304
|
}
|
|
316
|
-
if (searchHeaderParams.current) {
|
|
317
|
-
setSearchHeader(searchHeaderParams.current);
|
|
318
|
-
}
|
|
319
305
|
|
|
320
306
|
return () => {
|
|
321
307
|
focus?.();
|
|
@@ -329,7 +315,6 @@ export const useScreenHeader = ({
|
|
|
329
315
|
setAnimatedHeader,
|
|
330
316
|
setAnimatedSearch,
|
|
331
317
|
setHeaderType,
|
|
332
|
-
setSearchHeader,
|
|
333
318
|
]);
|
|
334
319
|
|
|
335
320
|
return { setSearchHeader, currentTint };
|
package/Layout/screenTypes.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
SearchHeaderProps,
|
|
8
8
|
} from '../Application/types';
|
|
9
9
|
import { FloatingButtonProps } from './FloatingButton';
|
|
10
|
-
import { HeaderType
|
|
10
|
+
import { HeaderType } from './types';
|
|
11
11
|
import { InputRef } from '../Input';
|
|
12
12
|
import type { HeaderContentLayout } from '../Application/headerLayout';
|
|
13
13
|
|
|
@@ -65,21 +65,6 @@ export interface ScreenProps extends ViewProps {
|
|
|
65
65
|
*/
|
|
66
66
|
marginFooter?: boolean;
|
|
67
67
|
|
|
68
|
-
/**
|
|
69
|
-
* Optional. Footer look on foldable inner displays and wide windows: `anchored`, a
|
|
70
|
-
* full-width bar with a top border, or `sheet`, a centered sheet over the body. Content
|
|
71
|
-
* is capped at 600pt (800pt on windows from 800pt). Defaults to the host's design
|
|
72
|
-
* system config (`footerStyle`), else `anchored`. Phones keep the current footer.
|
|
73
|
-
*/
|
|
74
|
-
footerStyle?: ScreenFooterStyle;
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Optional. If `true`, the screen draws an image behind the footer: on foldables the
|
|
78
|
-
* footer drops its surface fill, sheet and top border so the image shows through.
|
|
79
|
-
* Defaults to `false`.
|
|
80
|
-
*/
|
|
81
|
-
footerHasImageBackground?: boolean;
|
|
82
|
-
|
|
83
68
|
/**
|
|
84
69
|
* Optional. Background color of the screen.
|
|
85
70
|
*/
|
package/Layout/styles.ts
CHANGED
|
@@ -91,15 +91,6 @@ export default StyleSheet.create({
|
|
|
91
91
|
},
|
|
92
92
|
}),
|
|
93
93
|
},
|
|
94
|
-
footerBar: {
|
|
95
|
-
paddingTop: Spacing.S,
|
|
96
|
-
},
|
|
97
|
-
footerSheet: {
|
|
98
|
-
paddingTop: Spacing.S,
|
|
99
|
-
alignSelf: 'center',
|
|
100
|
-
borderTopLeftRadius: Radius.XL,
|
|
101
|
-
borderTopRightRadius: Radius.XL,
|
|
102
|
-
},
|
|
103
94
|
footerClip: {
|
|
104
95
|
marginTop: -Spacing.XL,
|
|
105
96
|
paddingTop: Spacing.XL,
|
|
@@ -107,6 +98,5 @@ export default StyleSheet.create({
|
|
|
107
98
|
},
|
|
108
99
|
debugBaseLine: { borderWidth: 1, borderColor: Colors.green_06 },
|
|
109
100
|
expanded: { flex: 1 },
|
|
110
|
-
centered: { alignSelf: 'center' },
|
|
111
101
|
rowWrap: { flexDirection: 'row', flexWrap: 'wrap' },
|
|
112
102
|
});
|
package/Layout/types.ts
CHANGED
|
@@ -2,12 +2,6 @@ import { NavigationOptions, SearchHeaderProps } from '../Application/types';
|
|
|
2
2
|
|
|
3
3
|
export type HeaderType = 'default' | 'extended' | 'none';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Screen footer look on foldable inner displays and wide windows: `anchored` is a
|
|
7
|
-
* full-width bar with a top border, `sheet` a centered sheet over the body.
|
|
8
|
-
*/
|
|
9
|
-
export type ScreenFooterStyle = 'anchored' | 'sheet';
|
|
10
|
-
|
|
11
5
|
export type ScreenRef = {
|
|
12
6
|
/**
|
|
13
7
|
* Applies navigation options to the screen's header.
|
package/Pagination/types.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ScrollViewProps,
|
|
3
|
+
ViewStyle,
|
|
4
|
+
type ScrollViewInstance,
|
|
5
|
+
} from 'react-native';
|
|
2
6
|
import {Ref} from 'react';
|
|
3
7
|
|
|
4
8
|
export type PaginationProps = {
|
|
@@ -32,7 +36,7 @@ export interface ScrollIndicatorProps extends ScrollViewProps {
|
|
|
32
36
|
* Optional. Represents a reference to the ScrollView component.
|
|
33
37
|
* It can be used to access the instance methods of the ScrollView.
|
|
34
38
|
*/
|
|
35
|
-
scrollViewRef?: Ref<
|
|
39
|
+
scrollViewRef?: Ref<ScrollViewInstance>;
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
export type ChildPaginationProps = Omit<PaginationProps, 'type'>;
|
package/package.json
CHANGED
|
@@ -1,39 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momo-kits/foundation",
|
|
3
|
-
"version": "0.169.17-beta.
|
|
3
|
+
"version": "0.169.17-beta.13",
|
|
4
4
|
"description": "React Native Component Kits",
|
|
5
|
-
"main": "index.ts",
|
|
6
|
-
"scripts": {},
|
|
7
5
|
"keywords": [
|
|
8
6
|
"@momo-kits/foundation"
|
|
9
7
|
],
|
|
8
|
+
"license": "MoMo",
|
|
9
|
+
"main": "index.ts",
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"registry": "https://registry.npmjs.org/"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {},
|
|
10
14
|
"dependencies": {
|
|
11
|
-
"react-
|
|
12
|
-
"@react-navigation/
|
|
13
|
-
"@react-navigation/
|
|
14
|
-
"@react-navigation/
|
|
15
|
-
"@react-navigation/
|
|
16
|
-
"@react-navigation/
|
|
17
|
-
"@react-navigation/stack": "7.4.2",
|
|
18
|
-
"react-native-gesture-handler": "2.27.1",
|
|
19
|
-
"react-native-linear-gradient": "git+https://oauth2:TGi6oBj-LdzsKpLXQSoH@gitlab.mservice.com.vn/momo-platform/public/react-native-linear-gradient#v3.0.0",
|
|
20
|
-
"react-native-reanimated": "4.1.3",
|
|
21
|
-
"react-native-worklets": "0.6.1",
|
|
22
|
-
"react-native-safe-area-context": "5.5.2",
|
|
23
|
-
"react-native-reserved-regions": "0.2.0",
|
|
15
|
+
"@react-navigation/bottom-tabs": "7.21.0",
|
|
16
|
+
"@react-navigation/core": "7.24.0",
|
|
17
|
+
"@react-navigation/elements": "2.9.45",
|
|
18
|
+
"@react-navigation/native": "7.5.1",
|
|
19
|
+
"@react-navigation/routers": "7.6.5",
|
|
20
|
+
"@react-navigation/stack": "7.12.1",
|
|
24
21
|
"@shopify/flash-list": "2.1.0",
|
|
25
|
-
"lottie-react-native": "7.
|
|
22
|
+
"lottie-react-native": "7.3.6",
|
|
23
|
+
"react-native-fast-image": "git+https://oauth2:k_r5y_gV6sX9-TqQxgcd@gitlab.mservice.com.vn/momo-platform/public/react-native-fast-image.git#v8.11.0",
|
|
24
|
+
"react-native-gesture-handler": "3.4.0",
|
|
25
|
+
"react-native-linear-gradient": "git+https://oauth2:k_r5y_gV6sX9-TqQxgcd@gitlab.mservice.com.vn/momo-platform/public/react-native-linear-gradient#v3.0.0",
|
|
26
|
+
"react-native-reanimated": "4.7.1",
|
|
27
|
+
"react-native-safe-area-context": "5.7.0",
|
|
28
|
+
"react-native-reserved-regions": "0.2.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/color": "3.0.6",
|
|
32
|
+
"react-native-reanimated": "4.7.1",
|
|
33
|
+
"react-native-worklets": "0.13.0"
|
|
26
34
|
},
|
|
27
35
|
"peerDependencies": {
|
|
28
36
|
"react-native": "*",
|
|
29
37
|
"react-native-svg": "*",
|
|
30
|
-
"react-native-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"@types/color": "3.0.6"
|
|
34
|
-
},
|
|
35
|
-
"publishConfig": {
|
|
36
|
-
"registry": "https://registry.npmjs.org/"
|
|
37
|
-
},
|
|
38
|
-
"license": "MoMo"
|
|
38
|
+
"react-native-reanimated": ">=4.7.0",
|
|
39
|
+
"react-native-worklets": ">=0.13.0"
|
|
40
|
+
}
|
|
39
41
|
}
|
|
@@ -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
|
-
}
|