chore: use TS generics for BottomTab types#3741
Conversation
|
The mobile version of example app from this branch is ready! You can see it here. |
|
Hey @tjaniczek, thank you for your pull request 🤗. The documentation from this branch can be viewed here. |
|
State for now:
|
| * export default MyComponent; | ||
| * ``` | ||
| * | ||
| * ## Usage with TypeScript |
There was a problem hiding this comment.
The ultimate goal for new docs is to introduce tabs JS and TS similar to npm and yarn so users can switch between those two and check which fit more for them.
cc: @DimitarNestorov (as far as I remember you were asking for that)
At the moment, since it's not available, maybe we can take advantage of my other PR introducing "More Examples" , wdyt?
There was a problem hiding this comment.
Agreed, will change it as soon as Portal docs land in main 👍
There was a problem hiding this comment.
Done: https://snack.expo.dev/@react-native-paper/bottomnavigation---usage-with-typescript
Please note that this snack will show warning at the moment, since this change is not merged yet. We'll need to update dependency in the snack when this change gets released 👍
Summary
This PR switches
BottomNavigationimplementation to use generic type instead of hardcodedRoute.Due to the fact that
BottomNavigation.Barmay be used with any router, we should not force users to adhere to Material'sgenericdefault types. As long as all methods passed toBottomNavigation.Barare type safe the user should be able to define (or import from chosen router) the type himself.This change is also required as a preparation for integration with React Navigation 7, that has two breaking changes related to
MaterialBottomTabView:useLinkBuilderkeyinonTabPresseventsThere should be no changes to JS users. For TS users
BottomNavigationshould now correctly infer types in handlers (onTabPress,getLabelTextand so on) - but if they used customRoutetype previously - they had to disable type checking in their code anyway 🤷Tested in both React Native 6 & 7, docs updated, added test to document the behaviour.
Test plan
It would be nice to install it on real-world app and see if everything works as expected.