Steal the createBottomNavigaton from react-navigation
This commit is contained in:
77
front/utils/navigator.tsx
Normal file
77
front/utils/navigator.tsx
Normal file
@@ -0,0 +1,77 @@
|
||||
import {
|
||||
createNavigatorFactory,
|
||||
type DefaultNavigatorOptions,
|
||||
type ParamListBase,
|
||||
type TabActionHelpers,
|
||||
type TabNavigationState,
|
||||
TabRouter,
|
||||
type TabRouterOptions,
|
||||
useNavigationBuilder,
|
||||
} from '@react-navigation/native';
|
||||
import * as React from 'react';
|
||||
|
||||
import type { BottomTabNavigationConfig } from '@react-navigation/bottom-tabs/src/types';
|
||||
import type {
|
||||
BottomTabNavigationEventMap,
|
||||
BottomTabNavigationOptions,
|
||||
} from '@react-navigation/bottom-tabs';
|
||||
import { BottomTabView } from '@react-navigation/bottom-tabs';
|
||||
|
||||
import ScaffoldMobileCC from '../components/UI/ScaffoldMobileCC';
|
||||
|
||||
type Props = DefaultNavigatorOptions<
|
||||
ParamListBase,
|
||||
TabNavigationState<ParamListBase>,
|
||||
BottomTabNavigationOptions,
|
||||
BottomTabNavigationEventMap
|
||||
> &
|
||||
TabRouterOptions &
|
||||
BottomTabNavigationConfig & { layout?: unknown };
|
||||
|
||||
function BottomTabNavigator({
|
||||
id,
|
||||
initialRouteName,
|
||||
backBehavior,
|
||||
children,
|
||||
layout,
|
||||
screenListeners,
|
||||
screenOptions,
|
||||
sceneContainerStyle,
|
||||
...rest
|
||||
}: Props) {
|
||||
const { state, descriptors, navigation, NavigationContent } = useNavigationBuilder<
|
||||
TabNavigationState<ParamListBase>,
|
||||
TabRouterOptions,
|
||||
TabActionHelpers<ParamListBase>,
|
||||
BottomTabNavigationOptions,
|
||||
BottomTabNavigationEventMap
|
||||
>(TabRouter, {
|
||||
id,
|
||||
initialRouteName,
|
||||
backBehavior,
|
||||
children,
|
||||
// @ts-expect-error The layout property has been added after the last release of react-navigation.
|
||||
layout,
|
||||
screenListeners,
|
||||
screenOptions,
|
||||
});
|
||||
|
||||
return (
|
||||
<NavigationContent>
|
||||
<BottomTabView
|
||||
{...rest}
|
||||
state={state}
|
||||
navigation={navigation}
|
||||
descriptors={descriptors}
|
||||
sceneContainerStyle={sceneContainerStyle}
|
||||
/>
|
||||
</NavigationContent>
|
||||
);
|
||||
}
|
||||
|
||||
export const createCustomNavigator = createNavigatorFactory<
|
||||
TabNavigationState<ParamListBase>,
|
||||
BottomTabNavigationOptions,
|
||||
BottomTabNavigationEventMap,
|
||||
typeof BottomTabNavigator
|
||||
>(BottomTabNavigator);
|
||||
Reference in New Issue
Block a user