@react-navigation/material-top-tabs 7.0.0 → 7.0.2
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/lib/commonjs/views/MaterialTopTabBar.js +32 -18
- package/lib/commonjs/views/MaterialTopTabBar.js.map +1 -1
- package/lib/module/views/MaterialTopTabBar.js +32 -18
- package/lib/module/views/MaterialTopTabBar.js.map +1 -1
- package/lib/typescript/commonjs/src/views/MaterialTopTabBar.d.ts.map +1 -1
- package/lib/typescript/commonjs/tsconfig.build.tsbuildinfo +1 -1
- package/lib/typescript/module/src/views/MaterialTopTabBar.d.ts.map +1 -1
- package/lib/typescript/module/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/views/MaterialTopTabBar.tsx +51 -29
|
@@ -7,38 +7,36 @@ import {
|
|
|
7
7
|
useTheme,
|
|
8
8
|
} from '@react-navigation/native';
|
|
9
9
|
import Color from 'color';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { StyleSheet } from 'react-native';
|
|
11
|
+
import {
|
|
12
|
+
type Route,
|
|
13
|
+
TabBar,
|
|
14
|
+
TabBarIndicator,
|
|
15
|
+
type TabDescriptor,
|
|
16
|
+
} from 'react-native-tab-view';
|
|
12
17
|
|
|
13
18
|
import type { MaterialTopTabBarProps } from '../types';
|
|
14
19
|
|
|
15
|
-
type
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
labelStyle?: StyleProp<ViewStyle>;
|
|
19
|
-
allowScaling?: boolean;
|
|
20
|
-
};
|
|
20
|
+
type MaterialLabelProps = Parameters<
|
|
21
|
+
NonNullable<TabDescriptor<Route>['label']>
|
|
22
|
+
>[0];
|
|
21
23
|
|
|
22
|
-
const
|
|
24
|
+
const renderLabelDefault = ({
|
|
23
25
|
color,
|
|
24
26
|
labelText,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}:
|
|
27
|
+
style,
|
|
28
|
+
allowFontScaling,
|
|
29
|
+
}: MaterialLabelProps) => {
|
|
28
30
|
return (
|
|
29
31
|
<Text
|
|
30
|
-
style={[{ color }, styles.label,
|
|
31
|
-
allowFontScaling={
|
|
32
|
+
style={[{ color }, styles.label, style]}
|
|
33
|
+
allowFontScaling={allowFontScaling}
|
|
32
34
|
>
|
|
33
35
|
{labelText}
|
|
34
36
|
</Text>
|
|
35
37
|
);
|
|
36
38
|
};
|
|
37
39
|
|
|
38
|
-
const renderLabel = (props: MaterialLabelType) => {
|
|
39
|
-
return <MaterialLabel {...props} />;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
40
|
export function MaterialTopTabBar({
|
|
43
41
|
state,
|
|
44
42
|
navigation,
|
|
@@ -60,24 +58,48 @@ export function MaterialTopTabBar({
|
|
|
60
58
|
state.routes.map((route) => {
|
|
61
59
|
const { options } = descriptors[route.key];
|
|
62
60
|
|
|
61
|
+
const {
|
|
62
|
+
title,
|
|
63
|
+
tabBarLabel,
|
|
64
|
+
tabBarButtonTestID,
|
|
65
|
+
tabBarAccessibilityLabel,
|
|
66
|
+
tabBarBadge,
|
|
67
|
+
tabBarShowIcon,
|
|
68
|
+
tabBarShowLabel,
|
|
69
|
+
tabBarIcon,
|
|
70
|
+
tabBarAllowFontScaling,
|
|
71
|
+
tabBarLabelStyle,
|
|
72
|
+
} = options;
|
|
73
|
+
|
|
63
74
|
return [
|
|
64
75
|
route.key,
|
|
65
76
|
{
|
|
66
77
|
href: buildHref(route.name, route.params),
|
|
67
|
-
testID:
|
|
68
|
-
accessibilityLabel:
|
|
69
|
-
badge:
|
|
70
|
-
icon:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
testID: tabBarButtonTestID,
|
|
79
|
+
accessibilityLabel: tabBarAccessibilityLabel,
|
|
80
|
+
badge: tabBarBadge,
|
|
81
|
+
icon: tabBarShowIcon === false ? undefined : tabBarIcon,
|
|
82
|
+
label:
|
|
83
|
+
tabBarShowLabel === false
|
|
84
|
+
? undefined
|
|
85
|
+
: typeof tabBarLabel === 'function'
|
|
86
|
+
? ({ labelText, color }: MaterialLabelProps) =>
|
|
87
|
+
tabBarLabel({
|
|
88
|
+
focused: state.routes[state.index].key === route.key,
|
|
89
|
+
color,
|
|
90
|
+
children: labelText ?? route.name,
|
|
91
|
+
})
|
|
92
|
+
: renderLabelDefault,
|
|
93
|
+
labelAllowFontScaling: tabBarAllowFontScaling,
|
|
94
|
+
labelStyle: tabBarLabelStyle,
|
|
75
95
|
labelText:
|
|
76
96
|
options.tabBarShowLabel === false
|
|
77
97
|
? undefined
|
|
78
|
-
:
|
|
79
|
-
?
|
|
80
|
-
:
|
|
98
|
+
: typeof tabBarLabel === 'string'
|
|
99
|
+
? tabBarLabel
|
|
100
|
+
: title !== undefined
|
|
101
|
+
? title
|
|
102
|
+
: route.name,
|
|
81
103
|
},
|
|
82
104
|
];
|
|
83
105
|
})
|