@@ -62,40 +62,34 @@ const TabViewComponent: React.FC<React.PropsWithChildren<TabViewProps>> = ({
6262} ) => {
6363 const [ index , setIndex ] = React . useState ( initialTabIndex ) ;
6464 const [ routes , setRoutes ] = React . useState < Route [ ] > ( [ ] ) ;
65- const [ tabScenes , setTabScenes ] = React . useState < { [ key : string ] : any } > ( { } ) ;
6665
6766 const { textStyles, viewStyles } = extractStyles ( style ) ;
6867
6968 const children : React . ReactNode [ ] = React . useMemo (
7069 ( ) =>
7170 flattenReactFragments (
7271 React . Children . toArray ( childrenProp ) as React . ReactElement [ ]
72+ ) . filter (
73+ ( child ) => React . isValidElement ( child ) && child . type === TabViewItem
7374 ) ,
7475 [ childrenProp ]
7576 ) ;
7677
7778 //Populate routes and scenes based on children
7879 React . useEffect ( ( ) => {
7980 const newRoutes : Route [ ] = [ ] ;
80- const scenes : { [ key : string ] : React . ReactElement } = { } ;
8181
82- children
83- . filter (
84- ( child ) => React . isValidElement ( child ) && child . type === TabViewItem
85- )
86- . forEach ( ( item : any , idx ) => {
87- const child = item as React . ReactElement ;
88- newRoutes . push ( {
89- key : idx . toString ( ) ,
90- title : child . props . title ,
91- icon : child . props . icon ,
92- accessibilityLabel : child . props . accessibilityLabel ,
93- } ) ;
94- scenes [ idx ] = child ;
82+ children . forEach ( ( item : any , idx ) => {
83+ const child = item as React . ReactElement ;
84+ newRoutes . push ( {
85+ key : idx . toString ( ) ,
86+ title : child . props . title ,
87+ icon : child . props . icon ,
88+ accessibilityLabel : child . props . accessibilityLabel ,
9589 } ) ;
90+ } ) ;
9691
9792 setRoutes ( newRoutes ) ;
98- setTabScenes ( scenes ) ;
9993 } , [ children ] ) ;
10094
10195 const indexChangeHandler = ( i : number ) => {
@@ -131,7 +125,8 @@ const TabViewComponent: React.FC<React.PropsWithChildren<TabViewProps>> = ({
131125 } ;
132126
133127 const renderScene = ( { route } : SceneProps ) => {
134- return tabScenes [ route . key ] ;
128+ const index = Number ( route . key ) ;
129+ return children [ index ] ;
135130 } ;
136131
137132 //Cannot render TabView without at least one tab
0 commit comments