@@ -21,26 +21,16 @@ import {
2121} from './reducer' ;
2222import { RNSLog } from 'react-native-screens/private' ;
2323import { TabsContainerItem } from './TabsContainerItem' ;
24+ import { useComponentsByName } from '../shared/use-components-by-name' ;
2425
2526export function TabsContainer ( props : TabsContainerProps ) {
2627 RNSLog . info ( 'TabsContainer render' ) ;
2728
28- const {
29- routeConfigs,
30- defaultRouteName,
31- onTabSelected,
32- ...restProps
33- } = props ;
29+ const { routeConfigs, defaultRouteName, onTabSelected, ...restProps } = props ;
3430
3531 useSanitizeRouteConfigs ( routeConfigs ) ;
3632
37- const componentsByName = React . useMemo ( ( ) => {
38- const map = new Map < string , TabRouteConfig [ 'Component' ] > ( ) ;
39- for ( const config of routeConfigs ) {
40- map . set ( config . name , config . Component ) ;
41- }
42- return map ;
43- } , [ routeConfigs ] ) ;
33+ const componentsByName = useComponentsByName ( routeConfigs ) ;
4434
4535 const [ tabsNavState , dispatch ] : [
4636 TabsContainerState ,
@@ -142,7 +132,9 @@ function useSanitizeRouteConfigs(routeConfigs: TabRouteConfig[]) {
142132 }
143133}
144134
145- function useTabsNavigationMethods ( dispatch : React . Dispatch < TabsNavigationAction > ) : TabsNavigationMethods {
135+ function useTabsNavigationMethods (
136+ dispatch : React . Dispatch < TabsNavigationAction > ,
137+ ) : TabsNavigationMethods {
146138 const setRouteOptions = React . useCallback (
147139 ( routeKey : string , options : Partial < TabRouteOptions > ) => {
148140 dispatch ( { type : 'set-options' , routeKey, options } ) ;
@@ -153,14 +145,20 @@ function useTabsNavigationMethods(dispatch: React.Dispatch<TabsNavigationAction>
153145 const selectTab : SelectTabMethod = React . useCallback (
154146 ( routeKey : string , forceAction ?: boolean ) => {
155147 const shouldForceAction = forceAction ?? false ;
156- dispatch ( { type : 'tab-select' , routeKey, forceAction : shouldForceAction } ) ;
148+ dispatch ( {
149+ type : 'tab-select' ,
150+ routeKey,
151+ forceAction : shouldForceAction ,
152+ } ) ;
157153 } ,
158154 [ dispatch ] ,
159155 ) ;
160156
161-
162- return React . useMemo ( ( ) => ( {
163- setRouteOptions,
164- selectTab
165- } ) , [ setRouteOptions , selectTab ] ) ;
157+ return React . useMemo (
158+ ( ) => ( {
159+ setRouteOptions,
160+ selectTab,
161+ } ) ,
162+ [ setRouteOptions , selectTab ] ,
163+ ) ;
166164}
0 commit comments