@@ -19,7 +19,7 @@ import type { IconSource } from '../Icon';
1919import BottomNavigationBar from './BottomNavigationBar' ;
2020import BottomNavigationRouteScreen from './BottomNavigationRouteScreen' ;
2121
22- type Route = {
22+ type BaseRoute = {
2323 key : string ;
2424 title ?: string ;
2525 focusedIcon ?: IconSource ;
@@ -31,7 +31,7 @@ type Route = {
3131 lazy ?: boolean ;
3232} ;
3333
34- type NavigationState = {
34+ type NavigationState < Route extends BaseRoute > = {
3535 index : number ;
3636 routes : Route [ ] ;
3737} ;
@@ -41,7 +41,7 @@ type TabPressEvent = {
4141 preventDefault ( ) : void ;
4242} ;
4343
44- type TouchableProps = TouchableWithoutFeedbackProps & {
44+ type TouchableProps < Route extends BaseRoute > = TouchableWithoutFeedbackProps & {
4545 key : string ;
4646 route : Route ;
4747 children : React . ReactNode ;
@@ -50,7 +50,7 @@ type TouchableProps = TouchableWithoutFeedbackProps & {
5050 rippleColor ?: string ;
5151} ;
5252
53- export type Props = {
53+ export type Props < Route extends BaseRoute > = {
5454 /**
5555 * Whether the shifting style is used, the active tab icon shifts up to show the label and the inactive tabs won't have a label.
5656 *
@@ -100,7 +100,7 @@ export type Props = {
100100 *
101101 * `BottomNavigation` is a controlled component, which means the `index` needs to be updated via the `onIndexChange` callback.
102102 */
103- navigationState : NavigationState ;
103+ navigationState : NavigationState < Route > ;
104104 /**
105105 * Callback which is called on tab change, receives the index of the new tab as argument.
106106 * The navigation state needs to be updated when it's called, otherwise the change is dropped.
@@ -165,7 +165,7 @@ export type Props = {
165165 * Callback which returns a React element to be used as the touchable for the tab item.
166166 * Renders a `TouchableRipple` on Android and `TouchableWithoutFeedback` with `View` on iOS.
167167 */
168- renderTouchable ?: ( props : TouchableProps ) => React . ReactNode ;
168+ renderTouchable ?: ( props : TouchableProps < Route > ) => React . ReactNode ;
169169 /**
170170 * Get accessibility label for the tab button. This is read by the screen reader when the user taps the tab.
171171 * Uses `route.accessibilityLabel` by default.
@@ -267,10 +267,10 @@ const SceneComponent = React.memo(({ component, ...rest }: any) =>
267267) ;
268268
269269/**
270- * Bottom navigation provides quick navigation between top-level views of an app with a bottom navigation bar.
270+ * BottomNavigation provides quick navigation between top-level views of an app with a bottom navigation bar.
271271 * It is primarily designed for use on mobile. If you want to use the navigation bar only see [`BottomNavigation.Bar`](BottomNavigationBar).
272272 *
273- * By default Bottom navigation uses primary color as a background, in dark theme with `adaptive` mode it will use surface colour instead.
273+ * By default BottomNavigation uses primary color as a background, in dark theme with `adaptive` mode it will use surface colour instead.
274274 * See [Dark Theme](https://callstack.github.io/react-native-paper/docs/guides/theming#dark-theme) for more information.
275275 *
276276 * <div class="screenshots">
@@ -318,7 +318,7 @@ const SceneComponent = React.memo(({ component, ...rest }: any) =>
318318 * export default MyComponent;
319319 * ```
320320 */
321- const BottomNavigation = ( {
321+ const BottomNavigation = < Route extends BaseRoute > ( {
322322 navigationState,
323323 renderScene,
324324 renderIcon,
@@ -348,7 +348,7 @@ const BottomNavigation = ({
348348 testID = 'bottom-navigation' ,
349349 theme : themeOverrides ,
350350 getLazy = ( { route } : { route : Route } ) => route . lazy ,
351- } : Props ) => {
351+ } : Props < Route > ) => {
352352 const theme = useInternalTheme ( themeOverrides ) ;
353353 const { scale } = theme . animation ;
354354 const compact = compactProp ?? ! theme . isV3 ;
@@ -439,7 +439,7 @@ const BottomNavigation = ({
439439 // eslint-disable-next-line react-hooks/exhaustive-deps
440440 } , [ ] ) ;
441441
442- const prevNavigationState = React . useRef < NavigationState > ( ) ;
442+ const prevNavigationState = React . useRef < NavigationState < Route > > ( ) ;
443443
444444 React . useEffect ( ( ) => {
445445 // Reset offsets of previous and current tabs before animation
@@ -602,7 +602,7 @@ const BottomNavigation = ({
602602 * Pure components are used to minimize re-rendering of the pages.
603603 * This drastically improves the animation performance.
604604 */
605- BottomNavigation . SceneMap = ( scenes : {
605+ BottomNavigation . SceneMap = < Route extends BaseRoute > ( scenes : {
606606 [ key : string ] : React . ComponentType < {
607607 route : Route ;
608608 jumpTo : ( key : string ) => void ;
0 commit comments