-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
createMaterialBottomTabNavigator return type is any #4671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Comments
I created a Pull Request all about this issue but it is not merge. Until PR is not merge, you can use my workaround. Just create a import {
createNavigatorFactory,
DefaultNavigatorOptions,
NavigatorTypeBagBase,
ParamListBase,
StaticConfig,
TabActionHelpers,
TabNavigationState,
TabRouter,
TabRouterOptions,
TypedNavigator,
useNavigationBuilder,
} from "@react-navigation/native";
import {
MaterialBottomTabNavigationEventMap,
MaterialBottomTabNavigationOptions,
MaterialBottomTabView,
} from "react-native-paper/react-navigation";
import { BottomNavigation } from "react-native-paper";
import { withLayoutContext } from "expo-router";
type MaterialBottomTabNavigationConfig = Partial<
Omit<
React.ComponentProps<typeof BottomNavigation>,
| "navigationState"
| "onIndexChange"
| "onTabPress"
| "onTabLongPress"
| "renderScene"
| "renderLabel"
| "renderIcon"
| "getAccessibilityLabel"
| "getBadge"
| "getColor"
| "getLabelText"
| "getTestID"
| "getLazy"
>
>;
export type MaterialBottomTabNavigatorProps = DefaultNavigatorOptions<
ParamListBase,
undefined,
TabNavigationState<ParamListBase>,
MaterialBottomTabNavigationOptions,
MaterialBottomTabNavigationEventMap,
typeof MaterialBottomTabView
> &
TabRouterOptions &
MaterialBottomTabNavigationConfig;
function MaterialBottomTabNavigator({
id,
initialRouteName,
backBehavior,
children,
screenListeners,
screenOptions,
...rest
}: MaterialBottomTabNavigatorProps) {
const { state, descriptors, navigation, NavigationContent } =
useNavigationBuilder<
TabNavigationState<ParamListBase>,
TabRouterOptions,
TabActionHelpers<ParamListBase>,
MaterialBottomTabNavigationOptions,
MaterialBottomTabNavigationEventMap
>(TabRouter, {
id,
initialRouteName,
backBehavior,
children,
screenListeners,
screenOptions,
});
return (
<NavigationContent>
<MaterialBottomTabView
{...rest}
state={state}
navigation={navigation}
descriptors={descriptors}
/>
</NavigationContent>
);
}
function createMaterialBottomTabs<
const ParamList extends ParamListBase,
const NavigatorID extends string | undefined,
const TypeBag extends NavigatorTypeBagBase = {
ParamList: ParamList;
NavigatorID: NavigatorID;
State: TabNavigationState<ParamList>;
ScreenOptions: MaterialBottomTabNavigationOptions;
EventMap: MaterialBottomTabNavigationEventMap;
NavigationList: {
[RouteName in keyof ParamList]: MaterialBottomTabNavigatorProps;
};
Navigator: typeof MaterialBottomTabNavigator;
},
const Config extends StaticConfig<TypeBag> = StaticConfig<TypeBag>
>(config?: Config): TypedNavigator<TypeBag, Config> {
return createNavigatorFactory(MaterialBottomTabNavigator)(config);
}
export default createMaterialBottomTabs; If you're using expo, you can use the const { Navigator } = createMaterialBottomTabs();
export const MaterialBottomTabs = withLayoutContext<
MaterialBottomTabNavigationOptions,
typeof Navigator,
TabNavigationState<ParamListBase>,
MaterialBottomTabNavigationEventMap
>(Navigator); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Current behaviour
Using
createMaterialBottomTabNavigator
from"react-native-paper/react-navigation"
returns fully functional Tab navigator, but withany
type, making it impossible to work with using Typescript.Expected behaviour
It should return something which will allow Intelisense to work as it should: e.g. it should instruct user to use
<Tabs.Navigator>
or to usecomponent
prop in<Tabs.Screen/>
How to reproduce?
Preview
What have you tried so far?
There is no easy solution for that. I tried installing
react-navigation
and importing types, but it didn't help.Your Environment
The text was updated successfully, but these errors were encountered: