forked from callstack/react-native-bottom-tabs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeBottomTabView.tsx
More file actions
121 lines (113 loc) · 3.38 KB
/
NativeBottomTabView.tsx
File metadata and controls
121 lines (113 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import {
type ParamListBase,
type TabNavigationState,
type Route,
CommonActions,
} from '@react-navigation/native';
import type {
NativeBottomTabDescriptorMap,
NativeBottomTabNavigationConfig,
NativeBottomTabNavigationHelpers,
} from '../types';
import TabView from 'react-native-bottom-tabs';
type Props = NativeBottomTabNavigationConfig & {
state: TabNavigationState<ParamListBase>;
navigation: NativeBottomTabNavigationHelpers;
descriptors: NativeBottomTabDescriptorMap;
};
export default function NativeBottomTabView({
state,
layoutDirection,
navigation,
descriptors,
tabBar,
...rest
}: Props) {
return (
<TabView
{...rest}
navigationState={state}
renderScene={({ route }) => descriptors[route.key]?.render()}
getActiveTintColor={({ route }) => {
return descriptors[route.key]?.options.tabBarActiveTintColor;
}}
getLabelText={({ route }) => {
const options = descriptors[route.key]?.options;
return options?.tabBarLabel !== undefined
? options.tabBarLabel
: options?.title !== undefined
? options.title
: (route as Route<string>).name;
}}
getBadge={({ route }) => descriptors[route.key]?.options.tabBarBadge}
getBadgeBackgroundColor={({ route }) =>
descriptors[route.key]?.options.tabBarBadgeBackgroundColor
}
getBadgeTextColor={({ route }) =>
descriptors[route.key]?.options.tabBarBadgeTextColor
}
getHidden={({ route }) => {
const options = descriptors[route.key]?.options;
return options?.tabBarItemHidden === true;
}}
getTestID={({ route }) =>
descriptors[route.key]?.options.tabBarButtonTestID
}
getRole={({ route }) => descriptors[route.key]?.options.role}
tabBar={
tabBar ? () => tabBar({ state, descriptors, navigation }) : undefined
}
getIcon={({ route, focused }) => {
const options = descriptors[route.key]?.options;
if (options?.tabBarIcon) {
const { tabBarIcon } = options;
return tabBarIcon({ focused });
}
return null;
}}
getLazy={({ route }) => descriptors[route.key]?.options.lazy ?? true}
getFreezeOnBlur={({ route }) =>
descriptors[route.key]?.options.freezeOnBlur
}
getSceneStyle={({ route }) => descriptors[route.key]?.options.sceneStyle}
onTabLongPress={(index) => {
const route = state.routes[index];
if (!route) {
return;
}
navigation.emit({
type: 'tabLongPress',
target: route.key,
});
}}
getPreventsDefault={({ route }) =>
descriptors[route.key]?.options.preventsDefault
}
onIndexChange={(index) => {
const focused = index === state.index;
const route = state.routes[index];
if (!route) {
return;
}
const event = navigation.emit({
type: 'tabPress',
target: route.key,
canPreventDefault: true,
});
if (
focused ||
event.defaultPrevented ||
descriptors[route.key]?.options.preventsDefault
) {
return;
} else {
navigation.dispatch({
...CommonActions.navigate(route),
target: state.key,
});
}
}}
layoutDirection={layoutDirection}
/>
);
}