@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.
@@ -7,38 +7,36 @@ import {
7
7
  useTheme,
8
8
  } from '@react-navigation/native';
9
9
  import Color from 'color';
10
- import { type StyleProp, StyleSheet, type ViewStyle } from 'react-native';
11
- import { TabBar, TabBarIndicator } from 'react-native-tab-view';
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 MaterialLabelType = {
16
- color: string;
17
- labelText?: string;
18
- labelStyle?: StyleProp<ViewStyle>;
19
- allowScaling?: boolean;
20
- };
20
+ type MaterialLabelProps = Parameters<
21
+ NonNullable<TabDescriptor<Route>['label']>
22
+ >[0];
21
23
 
22
- const MaterialLabel = ({
24
+ const renderLabelDefault = ({
23
25
  color,
24
26
  labelText,
25
- labelStyle,
26
- allowScaling,
27
- }: MaterialLabelType) => {
27
+ style,
28
+ allowFontScaling,
29
+ }: MaterialLabelProps) => {
28
30
  return (
29
31
  <Text
30
- style={[{ color }, styles.label, labelStyle]}
31
- allowFontScaling={allowScaling}
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: options.tabBarButtonTestID,
68
- accessibilityLabel: options.tabBarAccessibilityLabel,
69
- badge: options.tabBarBadge,
70
- icon:
71
- options.tabBarShowIcon === false ? undefined : options.tabBarIcon,
72
- label: options.tabBarShowLabel === false ? undefined : renderLabel,
73
- labelAllowFontScaling: options.tabBarAllowFontScaling,
74
- labelStyle: options.tabBarLabelStyle,
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
- : options.title !== undefined
79
- ? options.title
80
- : route.name,
98
+ : typeof tabBarLabel === 'string'
99
+ ? tabBarLabel
100
+ : title !== undefined
101
+ ? title
102
+ : route.name,
81
103
  },
82
104
  ];
83
105
  })