@react-navigation/material-top-tabs 8.0.0-alpha.51 → 8.0.0-alpha.52
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.
|
@@ -6,6 +6,7 @@ import { useLinkBuilder, useLocale, useTheme } from '@react-navigation/native';
|
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import { StyleSheet } from 'react-native';
|
|
8
8
|
import { TabBar } from 'react-native-tab-view';
|
|
9
|
+
import useLatestCallback from 'use-latest-callback';
|
|
9
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
11
|
const MaterialLabel = ({
|
|
11
12
|
color,
|
|
@@ -52,8 +53,8 @@ export function MaterialTopTabBar({
|
|
|
52
53
|
const activeColor = focusedOptions.tabBarActiveTintColor ?? (tabBarVariant === 'primary' ? colors.primary : colors.text);
|
|
53
54
|
const inactiveColor = focusedOptions.tabBarInactiveTintColor ?? Color(colors.text)?.alpha(0.68).string() ?? (dark ? 'rgba(255, 255, 255, 0.68)' : 'rgba(0, 0, 0, 0.68)');
|
|
54
55
|
const pressColor = focusedOptions.tabBarPressColor ?? Color(tabBarVariant === 'primary' ? colors.primary : colors.text)?.alpha(0.12).string() ?? (dark ? 'rgba(255, 255, 255, 0.12)' : 'rgba(0, 0, 0, 0.12)');
|
|
55
|
-
const
|
|
56
|
-
|
|
56
|
+
const optionsCache = React.useRef({});
|
|
57
|
+
const nextOptions = Object.fromEntries(state.routes.map(route => {
|
|
57
58
|
const {
|
|
58
59
|
title,
|
|
59
60
|
tabBarLabel,
|
|
@@ -65,11 +66,16 @@ export function MaterialTopTabBar({
|
|
|
65
66
|
tabBarIcon,
|
|
66
67
|
tabBarAllowFontScaling,
|
|
67
68
|
tabBarLabelStyle
|
|
68
|
-
} = options;
|
|
69
|
+
} = descriptors[route.key]?.options ?? {};
|
|
70
|
+
const focused = focusedRoute.key === route.key;
|
|
71
|
+
const href = buildHref(route.name, route.params);
|
|
72
|
+
const previous = optionsCache.current[route.key];
|
|
73
|
+
const deps = [href, route.name, title, tabBarLabel, tabBarButtonTestID, tabBarAccessibilityLabel, tabBarBadge, tabBarShowIcon, tabBarShowLabel, tabBarIcon, tabBarAllowFontScaling, tabBarLabelStyle, typeof tabBarLabel === 'function' && focused];
|
|
74
|
+
if (previous && Object.hasOwn(optionsCache.current, route.key) && previous.deps.length === deps.length && deps.every((dep, index) => Object.is(dep, previous.deps[index]))) {
|
|
75
|
+
return [route.key, previous];
|
|
76
|
+
}
|
|
69
77
|
let icon;
|
|
70
|
-
if (tabBarShowIcon
|
|
71
|
-
icon = undefined;
|
|
72
|
-
} else if (tabBarIcon) {
|
|
78
|
+
if (tabBarShowIcon !== false && tabBarIcon) {
|
|
73
79
|
icon = ({
|
|
74
80
|
focused,
|
|
75
81
|
color,
|
|
@@ -93,8 +99,8 @@ export function MaterialTopTabBar({
|
|
|
93
99
|
return null;
|
|
94
100
|
};
|
|
95
101
|
}
|
|
96
|
-
|
|
97
|
-
href
|
|
102
|
+
const tabOptions = {
|
|
103
|
+
href,
|
|
98
104
|
testID: tabBarButtonTestID,
|
|
99
105
|
accessibilityLabel: tabBarAccessibilityLabel,
|
|
100
106
|
badge: tabBarBadge,
|
|
@@ -103,20 +109,48 @@ export function MaterialTopTabBar({
|
|
|
103
109
|
labelText,
|
|
104
110
|
color
|
|
105
111
|
}) => tabBarLabel({
|
|
106
|
-
focused
|
|
112
|
+
focused,
|
|
107
113
|
color,
|
|
108
114
|
children: labelText ?? route.name
|
|
109
115
|
}) : renderLabelDefault,
|
|
110
116
|
labelAllowFontScaling: tabBarAllowFontScaling,
|
|
111
117
|
labelStyle: tabBarLabelStyle,
|
|
112
|
-
labelText:
|
|
118
|
+
labelText: tabBarShowLabel === false ? undefined : typeof tabBarLabel === 'string' ? tabBarLabel : title !== undefined ? title : route.name
|
|
119
|
+
};
|
|
120
|
+
return [route.key, {
|
|
121
|
+
deps,
|
|
122
|
+
options: tabOptions
|
|
113
123
|
}];
|
|
114
124
|
}));
|
|
125
|
+
React.useInsertionEffect(() => {
|
|
126
|
+
optionsCache.current = nextOptions;
|
|
127
|
+
});
|
|
128
|
+
const onTabPress = useLatestCallback(({
|
|
129
|
+
route,
|
|
130
|
+
preventDefault
|
|
131
|
+
}) => {
|
|
132
|
+
const event = navigation.emit({
|
|
133
|
+
type: 'tabPress',
|
|
134
|
+
target: route.key,
|
|
135
|
+
canPreventDefault: true
|
|
136
|
+
});
|
|
137
|
+
if (event.defaultPrevented) {
|
|
138
|
+
preventDefault();
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
const onTabLongPress = useLatestCallback(({
|
|
142
|
+
route
|
|
143
|
+
}) => navigation.emit({
|
|
144
|
+
type: 'tabLongPress',
|
|
145
|
+
target: route.key
|
|
146
|
+
}));
|
|
115
147
|
const tabBarIndicator = focusedOptions.tabBarIndicator;
|
|
116
148
|
return /*#__PURE__*/_jsx(TabBar, {
|
|
117
149
|
...rest,
|
|
118
150
|
navigationState: state,
|
|
119
|
-
options:
|
|
151
|
+
options: Object.fromEntries(Object.entries(nextOptions).map(([key, {
|
|
152
|
+
options
|
|
153
|
+
}]) => [key, options])),
|
|
120
154
|
direction: direction,
|
|
121
155
|
scrollEnabled: focusedOptions.tabBarScrollEnabled,
|
|
122
156
|
bounces: focusedOptions.tabBarBounces,
|
|
@@ -137,25 +171,8 @@ export function MaterialTopTabBar({
|
|
|
137
171
|
backgroundColor: colors.card,
|
|
138
172
|
borderBottomColor: colors.border
|
|
139
173
|
}, focusedOptions.tabBarStyle],
|
|
140
|
-
onTabPress:
|
|
141
|
-
|
|
142
|
-
preventDefault
|
|
143
|
-
}) => {
|
|
144
|
-
const event = navigation.emit({
|
|
145
|
-
type: 'tabPress',
|
|
146
|
-
target: route.key,
|
|
147
|
-
canPreventDefault: true
|
|
148
|
-
});
|
|
149
|
-
if (event.defaultPrevented) {
|
|
150
|
-
preventDefault();
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
onTabLongPress: ({
|
|
154
|
-
route
|
|
155
|
-
}) => navigation.emit({
|
|
156
|
-
type: 'tabLongPress',
|
|
157
|
-
target: route.key
|
|
158
|
-
}),
|
|
174
|
+
onTabPress: onTabPress,
|
|
175
|
+
onTabLongPress: onTabLongPress,
|
|
159
176
|
renderIndicator: tabBarIndicator ? ({
|
|
160
177
|
navigationState: _,
|
|
161
178
|
...rest
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["PlatformIcon","Text","Color","useLinkBuilder","useLocale","useTheme","React","StyleSheet","TabBar","jsx","_jsx","MaterialLabel","color","labelText","style","allowFontScaling","fonts","medium","styles","label","children","renderLabelDefault","props","MaterialTopTabBar","state","navigation","descriptors","rest","colors","dark","direction","buildHref","focusedRoute","routes","index","Error","focusedOptions","key","options","tabBarVariant","activeColor","tabBarActiveTintColor","primary","text","inactiveColor","tabBarInactiveTintColor","alpha","string","pressColor","tabBarPressColor","
|
|
1
|
+
{"version":3,"names":["PlatformIcon","Text","Color","useLinkBuilder","useLocale","useTheme","React","StyleSheet","TabBar","useLatestCallback","jsx","_jsx","MaterialLabel","color","labelText","style","allowFontScaling","fonts","medium","styles","label","children","renderLabelDefault","props","MaterialTopTabBar","state","navigation","descriptors","rest","colors","dark","direction","buildHref","focusedRoute","routes","index","Error","focusedOptions","key","options","tabBarVariant","activeColor","tabBarActiveTintColor","primary","text","inactiveColor","tabBarInactiveTintColor","alpha","string","pressColor","tabBarPressColor","optionsCache","useRef","nextOptions","Object","fromEntries","map","route","title","tabBarLabel","tabBarButtonTestID","tabBarAccessibilityLabel","tabBarBadge","tabBarShowIcon","tabBarShowLabel","tabBarIcon","tabBarAllowFontScaling","tabBarLabelStyle","focused","href","name","params","previous","current","deps","hasOwn","length","every","dep","is","icon","size","iconValue","isValidElement","tabOptions","testID","accessibilityLabel","badge","undefined","labelAllowFontScaling","labelStyle","useInsertionEffect","onTabPress","preventDefault","event","emit","type","target","canPreventDefault","defaultPrevented","onTabLongPress","tabBarIndicator","navigationState","entries","scrollEnabled","tabBarScrollEnabled","bounces","tabBarBounces","pressOpacity","tabBarPressOpacity","tabStyle","tabBarItemStyle","indicatorStyle","backgroundColor","tabBarIndicatorStyle","gap","tabBarGap","variant","android_ripple","tabBarAndroidRipple","indicatorContainerStyle","tabBarIndicatorContainerStyle","contentContainerStyle","tabBarContentContainerStyle","card","borderBottomColor","border","tabBarStyle","renderIndicator","_","create","textAlign","fontSize"],"sourceRoot":"../../../src","sources":["views/MaterialTopTabBar.tsx"],"mappings":";;AAAA,SAASA,YAAY,EAAEC,IAAI,QAAQ,4BAA4B;AAC/D,SAASC,KAAK,QAAQ,qCAAqC;AAC3D,SAASC,cAAc,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,0BAA0B;AAC9E,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAA0BC,UAAU,QAAQ,cAAc;AAC1D,SAEEC,MAAM,QAGD,uBAAuB;AAC9B,OAAOC,iBAAiB,MAAM,qBAAqB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAapD,MAAMC,aAAa,GAAGA,CAAC;EACrBC,KAAK;EACLC,SAAS;EACTC,KAAK;EACLC;AACkB,CAAC,KAAK;EACxB,MAAM;IAAEC;EAAM,CAAC,GAAGZ,QAAQ,CAAC,CAAC;EAE5B,oBACEM,IAAA,CAACV,IAAI;IACHc,KAAK,EAAE,CAAC;MAAEF;IAAM,CAAC,EAAEI,KAAK,CAACC,MAAM,EAAEC,MAAM,CAACC,KAAK,EAAEL,KAAK,CAAE;IACtDC,gBAAgB,EAAEA,gBAAiB;IAAAK,QAAA,EAElCP;EAAS,CACN,CAAC;AAEX,CAAC;AAED,MAAMQ,kBAAkB,GAAIC,KAAyB,iBACnDZ,IAAA,CAACC,aAAa;EAAA,GAAKW;AAAK,CAAG,CAC5B;AAED,OAAO,SAASC,iBAAiBA,CAAC;EAChCC,KAAK;EACLC,UAAU;EACVC,WAAW;EACX,GAAGC;AACmB,CAAC,EAAE;EACzB,MAAM;IAAEC,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A,aAAc;IAC7BI,UAAU,EAAEA,UAAW;IACvB2D,YAAY,EAAEvE,cAAc,CAACwE,kBAAmB;IAChDC,QAAQ,EAAEzE,cAAc,CAAC0E,eAAgB;IACzCC,cAAc,EAAE,CACd;MAAEC,eAAe,EAAEpF,MAAM,CAACc;IAAQ,CAAC,EACnCN,cAAc,CAAC6E,oBAAoB,CACnC;IACFC,GAAG,EAAE9E,cAAc,CAAC+E,SAAU;IAC9BC,OAAO,EAAE7E,aAAc;IACvB8E,cAAc,EAAEjF,cAAc,CAACkF,mBAAoB;IACnDC,uBAAuB,EAAEnF,cAAc,CAACoF,6BAA8B;IACtEC,qBAAqB,EAAErF,cAAc,CAACsF,2BAA4B;IAClE5G,KAAK,EAAE,CACL;MAAEkG,eAAe,EAAEpF,MAAM,CAAC+F,IAAI;MAAEC,iBAAiB,EAAEhG,MAAM,CAACiG;IAAO,CAAC,EAClEzF,cAAc,CAAC0F,WAAW,CAC1B;IACFnC,UAAU,EAAEA,UAAW;IACvBQ,cAAc,EAAEA,cAAe;IAC/B4B,eAAe,EACb3B,eAAe,GACX,CAAC;MAAEC,eAAe,EAAE2B,CAAC;MAAE,GAAGrG;IAAK,CAAC,KAC9ByE,eAAe,CAAC;MAAE,GAAGzE,IAAI;MAAEH;IAAM,CAAC,CAAC,GACrC+D;EACL,CACF,CAAC;AAEN;AAEA,MAAMrE,MAAM,GAAGZ,UAAU,CAAC2H,MAAM,CAAC;EAC/B9G,KAAK,EAAE;IACL+G,SAAS,EAAE,QAAQ;IACnBC,QAAQ,EAAE,EAAE;IACZnB,eAAe,EAAE;EACnB;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MaterialTopTabBar.d.ts","sourceRoot":"","sources":["../../../../src/views/MaterialTopTabBar.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"MaterialTopTabBar.d.ts","sourceRoot":"","sources":["../../../../src/views/MaterialTopTabBar.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAU,CAAC;AAiCvD,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,UAAU,EACV,WAAW,EACX,GAAG,IAAI,EACR,EAAE,sBAAsB,qBAkNxB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-navigation/material-top-tabs",
|
|
3
3
|
"description": "Integration for the animated tab view component from react-native-tab-view",
|
|
4
|
-
"version": "8.0.0-alpha.
|
|
4
|
+
"version": "8.0.0-alpha.52",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native-component",
|
|
7
7
|
"react-component",
|
|
@@ -46,12 +46,13 @@
|
|
|
46
46
|
"clean": "del lib"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@react-navigation/elements": "^3.0.0-alpha.
|
|
50
|
-
"react-native-tab-view": "^5.0.0-alpha.
|
|
49
|
+
"@react-navigation/elements": "^3.0.0-alpha.51",
|
|
50
|
+
"react-native-tab-view": "^5.0.0-alpha.16",
|
|
51
|
+
"use-latest-callback": "^0.3.5"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
54
|
"@jest/globals": "^30.4.1",
|
|
54
|
-
"@react-navigation/native": "^8.0.0-alpha.
|
|
55
|
+
"@react-navigation/native": "^8.0.0-alpha.47",
|
|
55
56
|
"@testing-library/react-native": "^14.0.0",
|
|
56
57
|
"@types/react": "~19.2.17",
|
|
57
58
|
"del-cli": "^7.0.0",
|
|
@@ -59,12 +60,12 @@
|
|
|
59
60
|
"react-native": "0.85.3",
|
|
60
61
|
"react-native-builder-bob": "^0.43.0",
|
|
61
62
|
"react-native-pager-view": "^8.0.1",
|
|
62
|
-
"react-native-safe-area-context": "~5.
|
|
63
|
+
"react-native-safe-area-context": "~5.10.0",
|
|
63
64
|
"test-renderer": "1.2.0",
|
|
64
65
|
"typescript": "^6.0.3"
|
|
65
66
|
},
|
|
66
67
|
"peerDependencies": {
|
|
67
|
-
"@react-navigation/native": "^8.0.0-alpha.
|
|
68
|
+
"@react-navigation/native": "^8.0.0-alpha.47",
|
|
68
69
|
"react": ">= 19.2.0",
|
|
69
70
|
"react-native": "*",
|
|
70
71
|
"react-native-pager-view": ">= 7.0.0",
|
|
@@ -88,5 +89,5 @@
|
|
|
88
89
|
]
|
|
89
90
|
]
|
|
90
91
|
},
|
|
91
|
-
"gitHead": "
|
|
92
|
+
"gitHead": "e83cb9a88ab92d24caad272442c338de046cfac2"
|
|
92
93
|
}
|
|
@@ -3,7 +3,13 @@ import { Color } from '@react-navigation/elements/internal';
|
|
|
3
3
|
import { useLinkBuilder, useLocale, useTheme } from '@react-navigation/native';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { type ColorValue, StyleSheet } from 'react-native';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
type Route,
|
|
8
|
+
TabBar,
|
|
9
|
+
type TabBarProps,
|
|
10
|
+
type TabDescriptor,
|
|
11
|
+
} from 'react-native-tab-view';
|
|
12
|
+
import useLatestCallback from 'use-latest-callback';
|
|
7
13
|
|
|
8
14
|
import type { MaterialTopTabBarProps } from '../types';
|
|
9
15
|
|
|
@@ -11,6 +17,11 @@ type MaterialLabelProps = Parameters<
|
|
|
11
17
|
NonNullable<TabDescriptor<Route>['label']>
|
|
12
18
|
>[0];
|
|
13
19
|
|
|
20
|
+
type CachedOptions = {
|
|
21
|
+
deps: readonly unknown[];
|
|
22
|
+
options: TabDescriptor<Route>;
|
|
23
|
+
};
|
|
24
|
+
|
|
14
25
|
const MaterialLabel = ({
|
|
15
26
|
color,
|
|
16
27
|
labelText,
|
|
@@ -68,10 +79,10 @@ export function MaterialTopTabBar({
|
|
|
68
79
|
.string() ??
|
|
69
80
|
(dark ? 'rgba(255, 255, 255, 0.12)' : 'rgba(0, 0, 0, 0.12)');
|
|
70
81
|
|
|
71
|
-
const
|
|
72
|
-
state.routes.map((route) => {
|
|
73
|
-
const options = descriptors[route.key]?.options ?? {};
|
|
82
|
+
const optionsCache = React.useRef<Record<string, CachedOptions>>({});
|
|
74
83
|
|
|
84
|
+
const nextOptions = Object.fromEntries<CachedOptions>(
|
|
85
|
+
state.routes.map((route) => {
|
|
75
86
|
const {
|
|
76
87
|
title,
|
|
77
88
|
tabBarLabel,
|
|
@@ -83,13 +94,41 @@ export function MaterialTopTabBar({
|
|
|
83
94
|
tabBarIcon,
|
|
84
95
|
tabBarAllowFontScaling,
|
|
85
96
|
tabBarLabelStyle,
|
|
86
|
-
} = options;
|
|
97
|
+
} = descriptors[route.key]?.options ?? {};
|
|
98
|
+
|
|
99
|
+
const focused = focusedRoute.key === route.key;
|
|
100
|
+
const href = buildHref(route.name, route.params);
|
|
101
|
+
|
|
102
|
+
const previous = optionsCache.current[route.key];
|
|
103
|
+
|
|
104
|
+
const deps = [
|
|
105
|
+
href,
|
|
106
|
+
route.name,
|
|
107
|
+
title,
|
|
108
|
+
tabBarLabel,
|
|
109
|
+
tabBarButtonTestID,
|
|
110
|
+
tabBarAccessibilityLabel,
|
|
111
|
+
tabBarBadge,
|
|
112
|
+
tabBarShowIcon,
|
|
113
|
+
tabBarShowLabel,
|
|
114
|
+
tabBarIcon,
|
|
115
|
+
tabBarAllowFontScaling,
|
|
116
|
+
tabBarLabelStyle,
|
|
117
|
+
typeof tabBarLabel === 'function' && focused,
|
|
118
|
+
];
|
|
119
|
+
|
|
120
|
+
if (
|
|
121
|
+
previous &&
|
|
122
|
+
Object.hasOwn(optionsCache.current, route.key) &&
|
|
123
|
+
previous.deps.length === deps.length &&
|
|
124
|
+
deps.every((dep, index) => Object.is(dep, previous.deps[index]))
|
|
125
|
+
) {
|
|
126
|
+
return [route.key, previous];
|
|
127
|
+
}
|
|
87
128
|
|
|
88
129
|
let icon;
|
|
89
130
|
|
|
90
|
-
if (tabBarShowIcon
|
|
91
|
-
icon = undefined;
|
|
92
|
-
} else if (tabBarIcon) {
|
|
131
|
+
if (tabBarShowIcon !== false && tabBarIcon) {
|
|
93
132
|
icon = ({
|
|
94
133
|
focused,
|
|
95
134
|
color,
|
|
@@ -120,37 +159,63 @@ export function MaterialTopTabBar({
|
|
|
120
159
|
};
|
|
121
160
|
}
|
|
122
161
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
?
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
?
|
|
147
|
-
:
|
|
148
|
-
?
|
|
149
|
-
:
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
162
|
+
const tabOptions: TabDescriptor<Route> = {
|
|
163
|
+
href,
|
|
164
|
+
testID: tabBarButtonTestID,
|
|
165
|
+
accessibilityLabel: tabBarAccessibilityLabel,
|
|
166
|
+
badge: tabBarBadge,
|
|
167
|
+
icon,
|
|
168
|
+
label:
|
|
169
|
+
tabBarShowLabel === false
|
|
170
|
+
? undefined
|
|
171
|
+
: typeof tabBarLabel === 'function'
|
|
172
|
+
? ({ labelText, color }: MaterialLabelProps) =>
|
|
173
|
+
tabBarLabel({
|
|
174
|
+
focused,
|
|
175
|
+
color,
|
|
176
|
+
children: labelText ?? route.name,
|
|
177
|
+
})
|
|
178
|
+
: renderLabelDefault,
|
|
179
|
+
labelAllowFontScaling: tabBarAllowFontScaling,
|
|
180
|
+
labelStyle: tabBarLabelStyle,
|
|
181
|
+
labelText:
|
|
182
|
+
tabBarShowLabel === false
|
|
183
|
+
? undefined
|
|
184
|
+
: typeof tabBarLabel === 'string'
|
|
185
|
+
? tabBarLabel
|
|
186
|
+
: title !== undefined
|
|
187
|
+
? title
|
|
188
|
+
: route.name,
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
return [route.key, { deps, options: tabOptions }];
|
|
192
|
+
})
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
React.useInsertionEffect(() => {
|
|
196
|
+
optionsCache.current = nextOptions;
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const onTabPress = useLatestCallback<
|
|
200
|
+
NonNullable<TabBarProps<Route>['onTabPress']>
|
|
201
|
+
>(({ route, preventDefault }) => {
|
|
202
|
+
const event = navigation.emit({
|
|
203
|
+
type: 'tabPress',
|
|
204
|
+
target: route.key,
|
|
205
|
+
canPreventDefault: true,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
if (event.defaultPrevented) {
|
|
209
|
+
preventDefault();
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const onTabLongPress = useLatestCallback<
|
|
214
|
+
NonNullable<TabBarProps<Route>['onTabLongPress']>
|
|
215
|
+
>(({ route }) =>
|
|
216
|
+
navigation.emit({
|
|
217
|
+
type: 'tabLongPress',
|
|
218
|
+
target: route.key,
|
|
154
219
|
})
|
|
155
220
|
);
|
|
156
221
|
|
|
@@ -160,7 +225,9 @@ export function MaterialTopTabBar({
|
|
|
160
225
|
<TabBar
|
|
161
226
|
{...rest}
|
|
162
227
|
navigationState={state}
|
|
163
|
-
options={
|
|
228
|
+
options={Object.fromEntries(
|
|
229
|
+
Object.entries(nextOptions).map(([key, { options }]) => [key, options])
|
|
230
|
+
)}
|
|
164
231
|
direction={direction}
|
|
165
232
|
scrollEnabled={focusedOptions.tabBarScrollEnabled}
|
|
166
233
|
bounces={focusedOptions.tabBarBounces}
|
|
@@ -182,23 +249,8 @@ export function MaterialTopTabBar({
|
|
|
182
249
|
{ backgroundColor: colors.card, borderBottomColor: colors.border },
|
|
183
250
|
focusedOptions.tabBarStyle,
|
|
184
251
|
]}
|
|
185
|
-
onTabPress={
|
|
186
|
-
|
|
187
|
-
type: 'tabPress',
|
|
188
|
-
target: route.key,
|
|
189
|
-
canPreventDefault: true,
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
if (event.defaultPrevented) {
|
|
193
|
-
preventDefault();
|
|
194
|
-
}
|
|
195
|
-
}}
|
|
196
|
-
onTabLongPress={({ route }) =>
|
|
197
|
-
navigation.emit({
|
|
198
|
-
type: 'tabLongPress',
|
|
199
|
-
target: route.key,
|
|
200
|
-
})
|
|
201
|
-
}
|
|
252
|
+
onTabPress={onTabPress}
|
|
253
|
+
onTabLongPress={onTabLongPress}
|
|
202
254
|
renderIndicator={
|
|
203
255
|
tabBarIndicator
|
|
204
256
|
? ({ navigationState: _, ...rest }) =>
|