Steal the createBottomNavigaton from react-navigation

This commit is contained in:
2024-01-06 13:05:34 +01:00
committed by Clément Le Bihan
parent b1727b7838
commit fa60fc65a9

77
front/utils/navigator.tsx Normal file
View 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);