forked from callstack/react-native-bottom-tabs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateNativeBottomTabNavigator.tsx
More file actions
113 lines (106 loc) · 3.07 KB
/
createNativeBottomTabNavigator.tsx
File metadata and controls
113 lines (106 loc) · 3.07 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
import {
createNavigatorFactory,
type DefaultNavigatorOptions,
type NavigatorTypeBagBase,
type ParamListBase,
type StaticConfig,
type TabActionHelpers,
type TabNavigationState,
TabRouter,
type TabRouterOptions,
type TypedNavigator,
useNavigationBuilder,
useTheme,
} from '@react-navigation/native';
import Color from 'color';
import type {
NativeBottomTabNavigationConfig,
NativeBottomTabNavigationEventMap,
NativeBottomTabNavigationOptions,
NativeBottomTabNavigationProp,
} from '../types';
import NativeBottomTabView from '../views/NativeBottomTabView';
export type NativeBottomTabNavigatorProps = DefaultNavigatorOptions<
ParamListBase,
string | undefined,
TabNavigationState<ParamListBase>,
NativeBottomTabNavigationOptions,
NativeBottomTabNavigationEventMap,
NativeBottomTabNavigationProp<ParamListBase>
> &
TabRouterOptions &
NativeBottomTabNavigationConfig;
function NativeBottomTabNavigator({
id,
initialRouteName,
backBehavior,
children,
layout,
screenListeners,
screenOptions,
tabBarActiveTintColor: customActiveTintColor,
tabBarInactiveTintColor: customInactiveTintColor,
layoutDirection = 'locale',
...rest
}: NativeBottomTabNavigatorProps) {
const { colors } = useTheme();
const activeTintColor =
customActiveTintColor === undefined
? colors.primary
: customActiveTintColor;
const inactiveTintColor =
customInactiveTintColor === undefined
? Color(colors.text).mix(Color(colors.card), 0.5).hex()
: customInactiveTintColor;
const { state, descriptors, navigation, NavigationContent } =
useNavigationBuilder<
TabNavigationState<ParamListBase>,
TabRouterOptions,
TabActionHelpers<ParamListBase>,
NativeBottomTabNavigationOptions,
NativeBottomTabNavigationEventMap
>(TabRouter, {
id,
initialRouteName,
backBehavior,
children,
layout,
screenListeners,
screenOptions,
});
return (
<NavigationContent>
<NativeBottomTabView
{...rest}
layoutDirection={layoutDirection}
tabBarActiveTintColor={activeTintColor}
tabBarInactiveTintColor={inactiveTintColor}
state={state}
navigation={navigation}
descriptors={descriptors}
/>
</NavigationContent>
);
}
export default function createNativeBottomTabNavigator<
const ParamList extends ParamListBase,
const NavigatorID extends string | undefined = undefined,
const TypeBag extends NavigatorTypeBagBase = {
ParamList: ParamList;
NavigatorID: NavigatorID;
State: TabNavigationState<ParamList>;
ScreenOptions: NativeBottomTabNavigationOptions;
EventMap: NativeBottomTabNavigationEventMap;
NavigationList: {
[RouteName in keyof ParamList]: NativeBottomTabNavigationProp<
ParamList,
RouteName,
NavigatorID
>;
};
Navigator: typeof NativeBottomTabNavigator;
},
const Config extends StaticConfig<TypeBag> = StaticConfig<TypeBag>,
>(config?: Config): TypedNavigator<TypeBag, Config> {
return createNavigatorFactory(NativeBottomTabNavigator)(config);
}