-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Incorrect types for createMaterialBottomTabNavigator #4572
Comments
I have opened a corresponding issue with |
A reply on the other issue confirmsthis is a breaking change and is something to be fixed in react-native-paper. |
I've just realised that the latest version of react-native-paper is v5.12.5 which has a dependency on @react-navigation/native ^6.1.2 So this is not technically broken, but it is very disappointing that react-navigation say in v7 they deprecated material bottom tabs and moved it to react-paper when it is not ready/compatible. |
I think what we need is a v6 of react-native-paper which has updated dependency on the latest v7 of react-navigation. |
I faced the same issue a few weeks ago after I updated React Navigation to v7 and spent quite some time checking the types between v6 and v7 and this is how I got the type checking working again with the latest version of RN Paper and React Navigation v7: import {
DefaultNavigatorOptions,
EventMapBase,
NavigationState,
ParamListBase,
RouteConfig,
RouteGroupConfig,
TabNavigationState
} from '@react-navigation/native'
import {
MaterialBottomTabNavigationEventMap,
MaterialBottomTabNavigationOptions
} from 'react-native-paper'
import {
MaterialBottomTabNavigatorProps
} from 'react-native-paper/lib/typescript/react-navigation/navigators/createMaterialBottomTabNavigator'
type LegacyTypedNavigator<
ParamList extends ParamListBase,
State extends NavigationState,
ScreenOptions extends {},
EventMap extends EventMapBase,
Navigator extends React.ComponentType<any>
> = {
Navigator: React.ComponentType<
Omit<React.ComponentProps<Navigator>, keyof DefaultNavigatorOptions<any, any, any, any, any, any>> &
DefaultNavigatorOptions<ParamList, any, State, ScreenOptions, EventMap, any>
>
Group: React.ComponentType<RouteGroupConfig<ParamList, ScreenOptions, any>>
Screen: <RouteName extends keyof ParamList>(
_: RouteConfig<ParamList, RouteName, State, ScreenOptions, EventMap, any>
) => null
}
export type MaterialBottomTabNavigator<T extends ParamListBase> = LegacyTypedNavigator<
T,
TabNavigationState<ParamListBase>,
MaterialBottomTabNavigationOptions,
MaterialBottomTabNavigationEventMap,
(_: MaterialBottomTabNavigatorProps) => React.JSX.Element
> While it may work, I'm not sure if I missed something, hopefully someone can improve it in that case. And this an example of how I use it: type TabsStack = {
Tab1: undefined
Tab2: undefined
Tab3: undefined
Tab4: undefined
}
const Tabs: MaterialBottomTabNavigator<TabsStack> = createMaterialBottomTabNavigator() Although I'm planning to use another implementation and get rid of this workaround, I hope someone find this useful. Tested with:
|
Current behaviour
The types are incorrect when creating a material bottom tab navigator:
This makes it impossible to get typescript support when trying to add config or options to the TabNavigation.Navigator:
Looking at the types there are issues with the
createNavigatorFactory
andDefaultNavigatorOptions
generics in this file: https://github.com/callstack/react-native-paper/blob/main/src/react-navigation/navigators/createMaterialBottomTabNavigator.tsxThe
createNavigatorFactory
does not expect any generic arguments andDefaultNavigatorOptions
expects 6 but only 4 are provided.The issues is also
createNavigatorFactory
comes from@react-navigation/[email protected]
and the type there is actuallyany
Expected behaviour
I expect to get typescript intellisense when using the TabNavigation returned from createMaterialBottomTabNavigator
Preview
Your Environment
The text was updated successfully, but these errors were encountered: