@react-navigation/bottom-tabs 7.9.0 → 8.0.0-alpha.0
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/module/index.js +3 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/navigators/createBottomTabNavigator.js +27 -9
- package/lib/module/navigators/createBottomTabNavigator.js.map +1 -1
- package/lib/module/utils/BottomTabAnimationContext.js +5 -0
- package/lib/module/utils/BottomTabAnimationContext.js.map +1 -0
- package/lib/module/utils/useBottomTabAnimation.js +12 -0
- package/lib/module/utils/useBottomTabAnimation.js.map +1 -0
- package/lib/module/utils/useTabBarPosition.js +34 -0
- package/lib/module/utils/useTabBarPosition.js.map +1 -0
- package/lib/module/views/BottomTabBar.js +46 -49
- package/lib/module/views/BottomTabBar.js.map +1 -1
- package/lib/module/views/BottomTabItem.js +17 -15
- package/lib/module/views/BottomTabItem.js.map +1 -1
- package/lib/module/views/BottomTabViewCommon.js +16 -0
- package/lib/module/views/BottomTabViewCommon.js.map +1 -0
- package/lib/module/views/{BottomTabView.js → BottomTabViewCustom.js} +107 -106
- package/lib/module/views/BottomTabViewCustom.js.map +1 -0
- package/lib/module/views/BottomTabViewNative.android.js +4 -0
- package/lib/module/views/BottomTabViewNative.android.js.map +1 -0
- package/lib/module/views/BottomTabViewNative.ios.js +4 -0
- package/lib/module/views/BottomTabViewNative.ios.js.map +1 -0
- package/lib/module/views/BottomTabViewNative.js +5 -0
- package/lib/module/views/BottomTabViewNative.js.map +1 -0
- package/lib/module/{unstable/NativeBottomTabView.native.js → views/BottomTabViewNativeImpl.js} +95 -77
- package/lib/module/views/BottomTabViewNativeImpl.js.map +1 -0
- package/lib/module/views/ScreenContent.js +39 -0
- package/lib/module/views/ScreenContent.js.map +1 -0
- package/lib/module/views/TabBarIcon.js +40 -4
- package/lib/module/views/TabBarIcon.js.map +1 -1
- package/lib/typescript/src/index.d.ts +4 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/navigators/createBottomTabNavigator.d.ts +10 -6
- package/lib/typescript/src/navigators/createBottomTabNavigator.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +383 -115
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils/BottomTabAnimationContext.d.ts +4 -0
- package/lib/typescript/src/utils/BottomTabAnimationContext.d.ts.map +1 -0
- package/lib/typescript/src/utils/useBottomTabAnimation.d.ts +2 -0
- package/lib/typescript/src/utils/useBottomTabAnimation.d.ts.map +1 -0
- package/lib/typescript/src/utils/useTabBarPosition.d.ts +3 -0
- package/lib/typescript/src/utils/useTabBarPosition.d.ts.map +1 -0
- package/lib/typescript/src/views/BottomTabBar.d.ts +4 -4
- package/lib/typescript/src/views/BottomTabBar.d.ts.map +1 -1
- package/lib/typescript/src/views/BottomTabItem.d.ts +16 -14
- package/lib/typescript/src/views/BottomTabItem.d.ts.map +1 -1
- package/lib/typescript/src/views/{BottomTabView.d.ts → BottomTabViewCommon.d.ts} +2 -2
- package/lib/typescript/src/views/BottomTabViewCommon.d.ts.map +1 -0
- package/lib/typescript/src/views/BottomTabViewCustom.d.ts +10 -0
- package/lib/typescript/src/views/BottomTabViewCustom.d.ts.map +1 -0
- package/lib/typescript/src/views/BottomTabViewNative.android.d.ts +2 -0
- package/lib/typescript/src/views/BottomTabViewNative.android.d.ts.map +1 -0
- package/lib/typescript/src/views/BottomTabViewNative.d.ts +3 -0
- package/lib/typescript/src/views/BottomTabViewNative.d.ts.map +1 -0
- package/lib/typescript/src/views/BottomTabViewNative.ios.d.ts +2 -0
- package/lib/typescript/src/views/BottomTabViewNative.ios.d.ts.map +1 -0
- package/lib/typescript/src/views/BottomTabViewNativeImpl.d.ts +10 -0
- package/lib/typescript/src/views/BottomTabViewNativeImpl.d.ts.map +1 -0
- package/lib/typescript/src/views/ScreenContent.d.ts +13 -0
- package/lib/typescript/src/views/ScreenContent.d.ts.map +1 -0
- package/lib/typescript/src/views/TabBarIcon.d.ts +9 -9
- package/lib/typescript/src/views/TabBarIcon.d.ts.map +1 -1
- package/package.json +11 -16
- package/src/index.tsx +7 -2
- package/src/navigators/createBottomTabNavigator.tsx +78 -27
- package/src/types.tsx +417 -122
- package/src/utils/BottomTabAnimationContext.tsx +7 -0
- package/src/utils/useBottomTabAnimation.tsx +15 -0
- package/src/utils/useTabBarPosition.tsx +41 -0
- package/src/views/BottomTabBar.tsx +68 -67
- package/src/views/BottomTabItem.tsx +39 -34
- package/src/views/BottomTabViewCommon.tsx +26 -0
- package/src/views/{BottomTabView.tsx → BottomTabViewCustom.tsx} +142 -129
- package/src/views/BottomTabViewNative.android.tsx +1 -0
- package/src/views/BottomTabViewNative.ios.tsx +1 -0
- package/src/views/BottomTabViewNative.tsx +3 -0
- package/src/{unstable/NativeBottomTabView.native.tsx → views/BottomTabViewNativeImpl.tsx} +139 -116
- package/src/views/ScreenContent.tsx +58 -0
- package/src/views/TabBarIcon.tsx +63 -10
- package/lib/module/unstable/NativeBottomTabView.js +0 -6
- package/lib/module/unstable/NativeBottomTabView.js.map +0 -1
- package/lib/module/unstable/NativeBottomTabView.native.js.map +0 -1
- package/lib/module/unstable/NativeScreen/NativeScreen.js +0 -152
- package/lib/module/unstable/NativeScreen/NativeScreen.js.map +0 -1
- package/lib/module/unstable/NativeScreen/debounce.js +0 -12
- package/lib/module/unstable/NativeScreen/debounce.js.map +0 -1
- package/lib/module/unstable/NativeScreen/types.js +0 -4
- package/lib/module/unstable/NativeScreen/types.js.map +0 -1
- package/lib/module/unstable/NativeScreen/useAnimatedHeaderHeight.js +0 -12
- package/lib/module/unstable/NativeScreen/useAnimatedHeaderHeight.js.map +0 -1
- package/lib/module/unstable/NativeScreen/useHeaderConfig.js +0 -304
- package/lib/module/unstable/NativeScreen/useHeaderConfig.js.map +0 -1
- package/lib/module/unstable/createNativeBottomTabNavigator.js +0 -6
- package/lib/module/unstable/createNativeBottomTabNavigator.js.map +0 -1
- package/lib/module/unstable/createNativeBottomTabNavigator.native.js +0 -65
- package/lib/module/unstable/createNativeBottomTabNavigator.native.js.map +0 -1
- package/lib/module/unstable/index.js +0 -16
- package/lib/module/unstable/index.js.map +0 -1
- package/lib/module/unstable/types.js +0 -4
- package/lib/module/unstable/types.js.map +0 -1
- package/lib/module/views/BottomTabView.js.map +0 -1
- package/lib/module/views/ScreenFallback.js +0 -42
- package/lib/module/views/ScreenFallback.js.map +0 -1
- package/lib/typescript/src/unstable/NativeBottomTabView.d.ts +0 -10
- package/lib/typescript/src/unstable/NativeBottomTabView.d.ts.map +0 -1
- package/lib/typescript/src/unstable/NativeBottomTabView.native.d.ts +0 -10
- package/lib/typescript/src/unstable/NativeBottomTabView.native.d.ts.map +0 -1
- package/lib/typescript/src/unstable/NativeScreen/NativeScreen.d.ts +0 -8
- package/lib/typescript/src/unstable/NativeScreen/NativeScreen.d.ts.map +0 -1
- package/lib/typescript/src/unstable/NativeScreen/debounce.d.ts +0 -2
- package/lib/typescript/src/unstable/NativeScreen/debounce.d.ts.map +0 -1
- package/lib/typescript/src/unstable/NativeScreen/types.d.ts +0 -523
- package/lib/typescript/src/unstable/NativeScreen/types.d.ts.map +0 -1
- package/lib/typescript/src/unstable/NativeScreen/useAnimatedHeaderHeight.d.ts +0 -5
- package/lib/typescript/src/unstable/NativeScreen/useAnimatedHeaderHeight.d.ts.map +0 -1
- package/lib/typescript/src/unstable/NativeScreen/useHeaderConfig.d.ts +0 -11
- package/lib/typescript/src/unstable/NativeScreen/useHeaderConfig.d.ts.map +0 -1
- package/lib/typescript/src/unstable/createNativeBottomTabNavigator.d.ts +0 -2
- package/lib/typescript/src/unstable/createNativeBottomTabNavigator.d.ts.map +0 -1
- package/lib/typescript/src/unstable/createNativeBottomTabNavigator.native.d.ts +0 -16
- package/lib/typescript/src/unstable/createNativeBottomTabNavigator.native.d.ts.map +0 -1
- package/lib/typescript/src/unstable/index.d.ts +0 -13
- package/lib/typescript/src/unstable/index.d.ts.map +0 -1
- package/lib/typescript/src/unstable/types.d.ts +0 -319
- package/lib/typescript/src/unstable/types.d.ts.map +0 -1
- package/lib/typescript/src/views/BottomTabView.d.ts.map +0 -1
- package/lib/typescript/src/views/ScreenFallback.d.ts +0 -18
- package/lib/typescript/src/views/ScreenFallback.d.ts.map +0 -1
- package/src/unstable/NativeBottomTabView.tsx +0 -20
- package/src/unstable/NativeScreen/NativeScreen.tsx +0 -212
- package/src/unstable/NativeScreen/debounce.tsx +0 -14
- package/src/unstable/NativeScreen/types.ts +0 -573
- package/src/unstable/NativeScreen/useAnimatedHeaderHeight.tsx +0 -18
- package/src/unstable/NativeScreen/useHeaderConfig.tsx +0 -434
- package/src/unstable/createNativeBottomTabNavigator.native.tsx +0 -116
- package/src/unstable/createNativeBottomTabNavigator.tsx +0 -4
- package/src/unstable/index.tsx +0 -23
- package/src/unstable/types.tsx +0 -405
- package/src/views/ScreenFallback.tsx +0 -50
|
@@ -1,434 +0,0 @@
|
|
|
1
|
-
import { getHeaderTitle, HeaderTitle } from '@react-navigation/elements';
|
|
2
|
-
import {
|
|
3
|
-
type Route,
|
|
4
|
-
type Theme,
|
|
5
|
-
useLocale,
|
|
6
|
-
useTheme,
|
|
7
|
-
} from '@react-navigation/native';
|
|
8
|
-
import Color from 'color';
|
|
9
|
-
import { Platform, StyleSheet, type TextStyle, View } from 'react-native';
|
|
10
|
-
import {
|
|
11
|
-
type HeaderBarButtonItem,
|
|
12
|
-
type HeaderBarButtonItemMenuAction,
|
|
13
|
-
type HeaderBarButtonItemSubmenu,
|
|
14
|
-
isSearchBarAvailableForCurrentPlatform,
|
|
15
|
-
ScreenStackHeaderCenterView,
|
|
16
|
-
type ScreenStackHeaderConfigProps,
|
|
17
|
-
ScreenStackHeaderLeftView,
|
|
18
|
-
ScreenStackHeaderRightView,
|
|
19
|
-
ScreenStackHeaderSearchBarView,
|
|
20
|
-
SearchBar,
|
|
21
|
-
} from 'react-native-screens';
|
|
22
|
-
|
|
23
|
-
import type {
|
|
24
|
-
NativeHeaderOptions,
|
|
25
|
-
NativeScreenHeaderItem,
|
|
26
|
-
NativeScreenHeaderItemMenuAction,
|
|
27
|
-
NativeScreenHeaderItemMenuSubmenu,
|
|
28
|
-
} from './types';
|
|
29
|
-
|
|
30
|
-
type Props = NativeHeaderOptions & {
|
|
31
|
-
headerTopInsetEnabled: boolean;
|
|
32
|
-
headerHeight: number;
|
|
33
|
-
route: Route<string>;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const processBarButtonItems = (
|
|
37
|
-
items: NativeScreenHeaderItem[] | undefined,
|
|
38
|
-
colors: Theme['colors'],
|
|
39
|
-
fonts: Theme['fonts']
|
|
40
|
-
) => {
|
|
41
|
-
return items
|
|
42
|
-
?.map((item, index) => {
|
|
43
|
-
if (item.type === 'custom') {
|
|
44
|
-
// Handled with `ScreenStackHeaderLeftView` or `ScreenStackHeaderRightView`
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (item.type === 'spacing') {
|
|
49
|
-
if (item.spacing == null) {
|
|
50
|
-
throw new Error(
|
|
51
|
-
`Spacing item must have a 'spacing' property defined: ${JSON.stringify(
|
|
52
|
-
item
|
|
53
|
-
)}`
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return item;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (item.type === 'button' || item.type === 'menu') {
|
|
61
|
-
if (item.type === 'menu' && item.menu == null) {
|
|
62
|
-
throw new Error(
|
|
63
|
-
`Menu item must have a 'menu' property defined: ${JSON.stringify(
|
|
64
|
-
item
|
|
65
|
-
)}`
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const { badge, label, labelStyle, icon, ...rest } = item;
|
|
70
|
-
|
|
71
|
-
let processedItem: HeaderBarButtonItem = {
|
|
72
|
-
...rest,
|
|
73
|
-
index,
|
|
74
|
-
title: label,
|
|
75
|
-
titleStyle: {
|
|
76
|
-
...fonts.regular,
|
|
77
|
-
...labelStyle,
|
|
78
|
-
},
|
|
79
|
-
icon:
|
|
80
|
-
icon?.type === 'image'
|
|
81
|
-
? icon.tinted === false
|
|
82
|
-
? {
|
|
83
|
-
type: 'imageSource',
|
|
84
|
-
imageSource: icon.source,
|
|
85
|
-
}
|
|
86
|
-
: {
|
|
87
|
-
type: 'templateSource',
|
|
88
|
-
templateSource: icon.source,
|
|
89
|
-
}
|
|
90
|
-
: icon,
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
if (processedItem.type === 'menu' && item.type === 'menu') {
|
|
94
|
-
const { multiselectable, layout } = item.menu;
|
|
95
|
-
|
|
96
|
-
processedItem = {
|
|
97
|
-
...processedItem,
|
|
98
|
-
menu: {
|
|
99
|
-
...processedItem.menu,
|
|
100
|
-
singleSelection: !multiselectable,
|
|
101
|
-
displayAsPalette: layout === 'palette',
|
|
102
|
-
items: item.menu.items.map(getMenuItem),
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (badge) {
|
|
108
|
-
const badgeBackgroundColor =
|
|
109
|
-
badge.style?.backgroundColor ?? colors.notification;
|
|
110
|
-
const badgeTextColor =
|
|
111
|
-
typeof badgeBackgroundColor === 'string' &&
|
|
112
|
-
Color(badgeBackgroundColor)?.isLight()
|
|
113
|
-
? 'black'
|
|
114
|
-
: 'white';
|
|
115
|
-
|
|
116
|
-
processedItem = {
|
|
117
|
-
...processedItem,
|
|
118
|
-
badge: {
|
|
119
|
-
...badge,
|
|
120
|
-
value: String(badge.value),
|
|
121
|
-
style: {
|
|
122
|
-
backgroundColor: badgeBackgroundColor,
|
|
123
|
-
color: badgeTextColor,
|
|
124
|
-
...fonts.regular,
|
|
125
|
-
...badge.style,
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return processedItem;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
throw new Error(
|
|
135
|
-
`Invalid item type: ${JSON.stringify(item)}. Valid types are 'button', 'menu', 'custom' and 'spacing'.`
|
|
136
|
-
);
|
|
137
|
-
})
|
|
138
|
-
.filter((item) => item != null);
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const getMenuItem = (
|
|
142
|
-
item: NativeScreenHeaderItemMenuAction | NativeScreenHeaderItemMenuSubmenu
|
|
143
|
-
): HeaderBarButtonItemMenuAction | HeaderBarButtonItemSubmenu => {
|
|
144
|
-
if (item.type === 'submenu') {
|
|
145
|
-
const { label, inline, layout, items, multiselectable, ...rest } = item;
|
|
146
|
-
|
|
147
|
-
return {
|
|
148
|
-
...rest,
|
|
149
|
-
title: label,
|
|
150
|
-
displayAsPalette: layout === 'palette',
|
|
151
|
-
displayInline: inline,
|
|
152
|
-
singleSelection: !multiselectable,
|
|
153
|
-
items: items.map(getMenuItem),
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const { label, description, ...rest } = item;
|
|
158
|
-
|
|
159
|
-
return {
|
|
160
|
-
...rest,
|
|
161
|
-
title: label,
|
|
162
|
-
subtitle: description,
|
|
163
|
-
};
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
export function useHeaderConfig({
|
|
167
|
-
headerShadowVisible,
|
|
168
|
-
headerLargeStyle,
|
|
169
|
-
headerLargeTitleEnabled,
|
|
170
|
-
headerLargeTitleShadowVisible,
|
|
171
|
-
headerLargeTitleStyle,
|
|
172
|
-
headerBackground,
|
|
173
|
-
headerLeft,
|
|
174
|
-
headerRight,
|
|
175
|
-
headerShown,
|
|
176
|
-
headerStyle,
|
|
177
|
-
headerBlurEffect,
|
|
178
|
-
headerTintColor,
|
|
179
|
-
headerTitle,
|
|
180
|
-
headerTitleAlign,
|
|
181
|
-
headerTitleStyle,
|
|
182
|
-
headerTransparent,
|
|
183
|
-
headerSearchBarOptions,
|
|
184
|
-
headerTopInsetEnabled,
|
|
185
|
-
route,
|
|
186
|
-
title,
|
|
187
|
-
unstable_headerLeftItems: headerLeftItems,
|
|
188
|
-
unstable_headerRightItems: headerRightItems,
|
|
189
|
-
}: Props): ScreenStackHeaderConfigProps {
|
|
190
|
-
const { direction } = useLocale();
|
|
191
|
-
const { colors, fonts, dark } = useTheme();
|
|
192
|
-
const tintColor =
|
|
193
|
-
headerTintColor ?? (Platform.OS === 'ios' ? colors.primary : colors.text);
|
|
194
|
-
|
|
195
|
-
const headerLargeTitleStyleFlattened =
|
|
196
|
-
StyleSheet.flatten([
|
|
197
|
-
Platform.select({ ios: fonts.heavy, default: fonts.medium }),
|
|
198
|
-
headerLargeTitleStyle,
|
|
199
|
-
]) || {};
|
|
200
|
-
|
|
201
|
-
const headerTitleStyleFlattened =
|
|
202
|
-
StyleSheet.flatten([
|
|
203
|
-
Platform.select({ ios: fonts.bold, default: fonts.medium }),
|
|
204
|
-
headerTitleStyle,
|
|
205
|
-
]) || {};
|
|
206
|
-
|
|
207
|
-
const headerStyleFlattened = StyleSheet.flatten(headerStyle) || {};
|
|
208
|
-
const headerLargeStyleFlattened = StyleSheet.flatten(headerLargeStyle) || {};
|
|
209
|
-
|
|
210
|
-
const titleText = getHeaderTitle({ title, headerTitle }, route.name);
|
|
211
|
-
|
|
212
|
-
const titleColor =
|
|
213
|
-
'color' in headerTitleStyleFlattened
|
|
214
|
-
? headerTitleStyleFlattened.color
|
|
215
|
-
: (headerTintColor ?? colors.text);
|
|
216
|
-
|
|
217
|
-
const titleFontSize =
|
|
218
|
-
'fontSize' in headerTitleStyleFlattened
|
|
219
|
-
? headerTitleStyleFlattened.fontSize
|
|
220
|
-
: undefined;
|
|
221
|
-
|
|
222
|
-
const titleFontFamily = headerTitleStyleFlattened.fontFamily;
|
|
223
|
-
const titleFontWeight = headerTitleStyleFlattened.fontWeight;
|
|
224
|
-
|
|
225
|
-
const largeTitleFontFamily = headerLargeTitleStyleFlattened.fontFamily;
|
|
226
|
-
const largeTitleBackgroundColor = headerLargeStyleFlattened.backgroundColor;
|
|
227
|
-
|
|
228
|
-
const largeTitleColor =
|
|
229
|
-
'color' in headerLargeTitleStyleFlattened
|
|
230
|
-
? headerLargeTitleStyleFlattened.color
|
|
231
|
-
: undefined;
|
|
232
|
-
|
|
233
|
-
const largeTitleFontSize =
|
|
234
|
-
'fontSize' in headerLargeTitleStyleFlattened
|
|
235
|
-
? headerLargeTitleStyleFlattened.fontSize
|
|
236
|
-
: undefined;
|
|
237
|
-
|
|
238
|
-
const largeTitleFontWeight = headerLargeTitleStyleFlattened.fontWeight;
|
|
239
|
-
|
|
240
|
-
const headerTitleStyleSupported: TextStyle = { color: titleColor };
|
|
241
|
-
|
|
242
|
-
if (headerTitleStyleFlattened.fontFamily != null) {
|
|
243
|
-
headerTitleStyleSupported.fontFamily = headerTitleStyleFlattened.fontFamily;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (titleFontSize != null) {
|
|
247
|
-
headerTitleStyleSupported.fontSize = titleFontSize;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
if (titleFontWeight != null) {
|
|
251
|
-
headerTitleStyleSupported.fontWeight = titleFontWeight;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const headerBackgroundColor =
|
|
255
|
-
headerStyleFlattened.backgroundColor ??
|
|
256
|
-
(headerBackground != null || headerTransparent
|
|
257
|
-
? 'transparent'
|
|
258
|
-
: colors.card);
|
|
259
|
-
|
|
260
|
-
const headerLeftElement = headerLeft?.({
|
|
261
|
-
tintColor,
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
const headerRightElement = headerRight?.({
|
|
265
|
-
tintColor,
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
const headerTitleElement =
|
|
269
|
-
typeof headerTitle === 'function'
|
|
270
|
-
? headerTitle({
|
|
271
|
-
tintColor,
|
|
272
|
-
children: titleText,
|
|
273
|
-
})
|
|
274
|
-
: null;
|
|
275
|
-
|
|
276
|
-
const hasHeaderSearchBar =
|
|
277
|
-
isSearchBarAvailableForCurrentPlatform && headerSearchBarOptions != null;
|
|
278
|
-
|
|
279
|
-
const translucent =
|
|
280
|
-
headerBackground != null ||
|
|
281
|
-
headerTransparent ||
|
|
282
|
-
// When using a SearchBar or large title, the header needs to be translucent for it to work on iOS
|
|
283
|
-
((hasHeaderSearchBar || headerLargeTitleEnabled) &&
|
|
284
|
-
Platform.OS === 'ios' &&
|
|
285
|
-
headerTransparent !== false);
|
|
286
|
-
|
|
287
|
-
const isCenterViewRenderedAndroid = headerTitleAlign === 'center';
|
|
288
|
-
|
|
289
|
-
const leftItems = headerLeftItems?.({
|
|
290
|
-
tintColor,
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
let rightItems = headerRightItems?.({
|
|
294
|
-
tintColor,
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
if (rightItems) {
|
|
298
|
-
// iOS renders right items in reverse order
|
|
299
|
-
// So we need to reverse them here to match the order
|
|
300
|
-
rightItems = [...rightItems].reverse();
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const children = (
|
|
304
|
-
<>
|
|
305
|
-
{Platform.OS === 'ios' ? (
|
|
306
|
-
<>
|
|
307
|
-
{leftItems ? (
|
|
308
|
-
leftItems.map((item, index) => {
|
|
309
|
-
if (item.type === 'custom') {
|
|
310
|
-
return (
|
|
311
|
-
<ScreenStackHeaderLeftView
|
|
312
|
-
// eslint-disable-next-line @eslint-react/no-array-index-key
|
|
313
|
-
key={index}
|
|
314
|
-
hidesSharedBackground={item.hidesSharedBackground}
|
|
315
|
-
>
|
|
316
|
-
{item.element}
|
|
317
|
-
</ScreenStackHeaderLeftView>
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
return null;
|
|
322
|
-
})
|
|
323
|
-
) : headerLeftElement != null ? (
|
|
324
|
-
<ScreenStackHeaderLeftView>
|
|
325
|
-
{headerLeftElement}
|
|
326
|
-
</ScreenStackHeaderLeftView>
|
|
327
|
-
) : null}
|
|
328
|
-
{headerTitleElement != null ? (
|
|
329
|
-
<ScreenStackHeaderCenterView>
|
|
330
|
-
{headerTitleElement}
|
|
331
|
-
</ScreenStackHeaderCenterView>
|
|
332
|
-
) : null}
|
|
333
|
-
</>
|
|
334
|
-
) : (
|
|
335
|
-
<>
|
|
336
|
-
{headerLeftElement != null || typeof headerTitle === 'function' ? (
|
|
337
|
-
// The style passed to header left, together with title element being wrapped
|
|
338
|
-
// in flex view is reqruied for proper header layout, in particular,
|
|
339
|
-
// for the text truncation to work.
|
|
340
|
-
<ScreenStackHeaderLeftView
|
|
341
|
-
style={!isCenterViewRenderedAndroid ? { flex: 1 } : null}
|
|
342
|
-
>
|
|
343
|
-
{headerLeftElement}
|
|
344
|
-
{headerTitleAlign !== 'center' ? (
|
|
345
|
-
typeof headerTitle === 'function' ? (
|
|
346
|
-
<View style={{ flex: 1 }}>{headerTitleElement}</View>
|
|
347
|
-
) : (
|
|
348
|
-
<View style={{ flex: 1 }}>
|
|
349
|
-
<HeaderTitle
|
|
350
|
-
tintColor={tintColor}
|
|
351
|
-
style={headerTitleStyleSupported}
|
|
352
|
-
>
|
|
353
|
-
{titleText}
|
|
354
|
-
</HeaderTitle>
|
|
355
|
-
</View>
|
|
356
|
-
)
|
|
357
|
-
) : null}
|
|
358
|
-
</ScreenStackHeaderLeftView>
|
|
359
|
-
) : null}
|
|
360
|
-
{isCenterViewRenderedAndroid ? (
|
|
361
|
-
<ScreenStackHeaderCenterView>
|
|
362
|
-
{typeof headerTitle === 'function' ? (
|
|
363
|
-
headerTitleElement
|
|
364
|
-
) : (
|
|
365
|
-
<HeaderTitle
|
|
366
|
-
tintColor={tintColor}
|
|
367
|
-
style={headerTitleStyleSupported}
|
|
368
|
-
>
|
|
369
|
-
{titleText}
|
|
370
|
-
</HeaderTitle>
|
|
371
|
-
)}
|
|
372
|
-
</ScreenStackHeaderCenterView>
|
|
373
|
-
) : null}
|
|
374
|
-
</>
|
|
375
|
-
)}
|
|
376
|
-
{Platform.OS === 'ios' && rightItems ? (
|
|
377
|
-
rightItems.map((item, index) => {
|
|
378
|
-
if (item.type === 'custom') {
|
|
379
|
-
return (
|
|
380
|
-
<ScreenStackHeaderRightView
|
|
381
|
-
// eslint-disable-next-line @eslint-react/no-array-index-key
|
|
382
|
-
key={index}
|
|
383
|
-
hidesSharedBackground={item.hidesSharedBackground}
|
|
384
|
-
>
|
|
385
|
-
{item.element}
|
|
386
|
-
</ScreenStackHeaderRightView>
|
|
387
|
-
);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
return null;
|
|
391
|
-
})
|
|
392
|
-
) : headerRightElement != null ? (
|
|
393
|
-
<ScreenStackHeaderRightView>
|
|
394
|
-
{headerRightElement}
|
|
395
|
-
</ScreenStackHeaderRightView>
|
|
396
|
-
) : null}
|
|
397
|
-
{hasHeaderSearchBar ? (
|
|
398
|
-
<ScreenStackHeaderSearchBarView>
|
|
399
|
-
<SearchBar {...headerSearchBarOptions} />
|
|
400
|
-
</ScreenStackHeaderSearchBarView>
|
|
401
|
-
) : null}
|
|
402
|
-
</>
|
|
403
|
-
);
|
|
404
|
-
|
|
405
|
-
return {
|
|
406
|
-
backgroundColor: headerBackgroundColor,
|
|
407
|
-
blurEffect: headerBlurEffect,
|
|
408
|
-
color: tintColor,
|
|
409
|
-
direction,
|
|
410
|
-
hidden: headerShown === false,
|
|
411
|
-
hideShadow:
|
|
412
|
-
headerShadowVisible === false ||
|
|
413
|
-
headerBackground != null ||
|
|
414
|
-
(headerTransparent && headerShadowVisible !== true),
|
|
415
|
-
largeTitle: headerLargeTitleEnabled,
|
|
416
|
-
largeTitleBackgroundColor,
|
|
417
|
-
largeTitleColor,
|
|
418
|
-
largeTitleFontFamily,
|
|
419
|
-
largeTitleFontSize,
|
|
420
|
-
largeTitleFontWeight,
|
|
421
|
-
largeTitleHideShadow: headerLargeTitleShadowVisible === false,
|
|
422
|
-
title: titleText,
|
|
423
|
-
titleColor,
|
|
424
|
-
titleFontFamily,
|
|
425
|
-
titleFontSize,
|
|
426
|
-
titleFontWeight: String(titleFontWeight),
|
|
427
|
-
topInsetEnabled: headerTopInsetEnabled,
|
|
428
|
-
translucent: translucent === true,
|
|
429
|
-
children,
|
|
430
|
-
headerLeftBarButtonItems: processBarButtonItems(leftItems, colors, fonts),
|
|
431
|
-
headerRightBarButtonItems: processBarButtonItems(rightItems, colors, fonts),
|
|
432
|
-
experimental_userInterfaceStyle: dark ? 'dark' : 'light',
|
|
433
|
-
} as const;
|
|
434
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createNavigatorFactory,
|
|
3
|
-
type NavigatorTypeBagBase,
|
|
4
|
-
type ParamListBase,
|
|
5
|
-
StackActions,
|
|
6
|
-
type StaticConfig,
|
|
7
|
-
type TabActionHelpers,
|
|
8
|
-
type TabNavigationState,
|
|
9
|
-
TabRouter,
|
|
10
|
-
type TabRouterOptions,
|
|
11
|
-
type TypedNavigator,
|
|
12
|
-
useNavigationBuilder,
|
|
13
|
-
} from '@react-navigation/native';
|
|
14
|
-
import * as React from 'react';
|
|
15
|
-
|
|
16
|
-
import { NativeBottomTabView } from './NativeBottomTabView.native';
|
|
17
|
-
import type {
|
|
18
|
-
NativeBottomTabNavigationEventMap,
|
|
19
|
-
NativeBottomTabNavigationOptions,
|
|
20
|
-
NativeBottomTabNavigationProp,
|
|
21
|
-
NativeBottomTabNavigatorProps,
|
|
22
|
-
} from './types';
|
|
23
|
-
|
|
24
|
-
function NativeBottomTabNavigator({
|
|
25
|
-
id,
|
|
26
|
-
initialRouteName,
|
|
27
|
-
backBehavior,
|
|
28
|
-
children,
|
|
29
|
-
layout,
|
|
30
|
-
screenListeners,
|
|
31
|
-
screenOptions,
|
|
32
|
-
screenLayout,
|
|
33
|
-
UNSTABLE_router,
|
|
34
|
-
UNSTABLE_routeNamesChangeBehavior,
|
|
35
|
-
...rest
|
|
36
|
-
}: NativeBottomTabNavigatorProps) {
|
|
37
|
-
const { state, navigation, descriptors, NavigationContent } =
|
|
38
|
-
useNavigationBuilder<
|
|
39
|
-
TabNavigationState<ParamListBase>,
|
|
40
|
-
TabRouterOptions,
|
|
41
|
-
TabActionHelpers<ParamListBase>,
|
|
42
|
-
NativeBottomTabNavigationOptions,
|
|
43
|
-
NativeBottomTabNavigationEventMap
|
|
44
|
-
>(TabRouter, {
|
|
45
|
-
id,
|
|
46
|
-
initialRouteName,
|
|
47
|
-
backBehavior,
|
|
48
|
-
children,
|
|
49
|
-
layout,
|
|
50
|
-
screenListeners,
|
|
51
|
-
screenOptions,
|
|
52
|
-
screenLayout,
|
|
53
|
-
UNSTABLE_router,
|
|
54
|
-
UNSTABLE_routeNamesChangeBehavior,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const focusedRouteKey = state.routes[state.index].key;
|
|
58
|
-
const previousRouteKeyRef = React.useRef(focusedRouteKey);
|
|
59
|
-
|
|
60
|
-
React.useEffect(() => {
|
|
61
|
-
const previousRouteKey = previousRouteKeyRef.current;
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
previousRouteKey !== focusedRouteKey &&
|
|
65
|
-
descriptors[previousRouteKey]?.options.popToTopOnBlur
|
|
66
|
-
) {
|
|
67
|
-
const prevRoute = state.routes.find(
|
|
68
|
-
(route) => route.key === previousRouteKey
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
if (prevRoute?.state?.type === 'stack' && prevRoute.state.key) {
|
|
72
|
-
const popToTopAction = {
|
|
73
|
-
...StackActions.popToTop(),
|
|
74
|
-
target: prevRoute.state.key,
|
|
75
|
-
};
|
|
76
|
-
navigation.dispatch(popToTopAction);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
previousRouteKeyRef.current = focusedRouteKey;
|
|
81
|
-
}, [descriptors, focusedRouteKey, navigation, state.index, state.routes]);
|
|
82
|
-
|
|
83
|
-
return (
|
|
84
|
-
<NavigationContent>
|
|
85
|
-
<NativeBottomTabView
|
|
86
|
-
{...rest}
|
|
87
|
-
state={state}
|
|
88
|
-
navigation={navigation}
|
|
89
|
-
descriptors={descriptors}
|
|
90
|
-
/>
|
|
91
|
-
</NavigationContent>
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function createNativeBottomTabNavigator<
|
|
96
|
-
const ParamList extends ParamListBase,
|
|
97
|
-
const NavigatorID extends string | undefined = string | undefined,
|
|
98
|
-
const TypeBag extends NavigatorTypeBagBase = {
|
|
99
|
-
ParamList: ParamList;
|
|
100
|
-
NavigatorID: NavigatorID;
|
|
101
|
-
State: TabNavigationState<ParamList>;
|
|
102
|
-
ScreenOptions: NativeBottomTabNavigationOptions;
|
|
103
|
-
EventMap: NativeBottomTabNavigationEventMap;
|
|
104
|
-
NavigationList: {
|
|
105
|
-
[RouteName in keyof ParamList]: NativeBottomTabNavigationProp<
|
|
106
|
-
ParamList,
|
|
107
|
-
RouteName,
|
|
108
|
-
NavigatorID
|
|
109
|
-
>;
|
|
110
|
-
};
|
|
111
|
-
Navigator: typeof NativeBottomTabNavigator;
|
|
112
|
-
},
|
|
113
|
-
const Config extends StaticConfig<TypeBag> = StaticConfig<TypeBag>,
|
|
114
|
-
>(config?: Config): TypedNavigator<TypeBag, Config> {
|
|
115
|
-
return createNavigatorFactory(NativeBottomTabNavigator)(config);
|
|
116
|
-
}
|
package/src/unstable/index.tsx
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Navigators
|
|
3
|
-
*/
|
|
4
|
-
export { createNativeBottomTabNavigator } from './createNativeBottomTabNavigator';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Views
|
|
8
|
-
*/
|
|
9
|
-
export { NativeBottomTabView } from './NativeBottomTabView';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Types
|
|
13
|
-
*/
|
|
14
|
-
export type {
|
|
15
|
-
NativeBottomTabBarProps,
|
|
16
|
-
NativeBottomTabIcon,
|
|
17
|
-
NativeBottomTabNavigationEventMap,
|
|
18
|
-
NativeBottomTabNavigationOptions,
|
|
19
|
-
NativeBottomTabNavigationProp,
|
|
20
|
-
NativeBottomTabNavigatorProps,
|
|
21
|
-
NativeBottomTabOptionsArgs,
|
|
22
|
-
NativeBottomTabScreenProps,
|
|
23
|
-
} from './types';
|