@@ -11,7 +11,6 @@ import {asBaseComponent, forwardRef, BaseComponentInjectedProps, ForwardRefInjec
11
11
import View from '../../components/view' ;
12
12
import { Colors , Spacings , Typography } from '../../style' ;
13
13
import { Constants } from '../../helpers' ;
14
- import { LogService } from '../../services' ;
15
14
import FadedScrollView from './FadedScrollView' ;
16
15
17
16
import { useScrollToItem } from '../../hooks' ;
@@ -114,11 +113,7 @@ export interface TabControllerBarProps {
114
113
testID ?: string ;
115
114
}
116
115
117
- type ChildProps = React . ReactElement < TabControllerItemProps > ;
118
-
119
- interface Props extends TabControllerBarProps , BaseComponentInjectedProps , ForwardRefInjectedProps {
120
- children ?: ChildProps [ ] | ChildProps ;
121
- }
116
+ interface Props extends TabControllerBarProps , BaseComponentInjectedProps , ForwardRefInjectedProps { }
122
117
123
118
/**
124
119
* @description : TabController's TabBar component
@@ -144,47 +139,27 @@ const TabBar = (props: Props) => {
144
139
containerWidth : propsContainerWidth ,
145
140
centerSelected,
146
141
containerStyle,
147
- testID,
148
- children : propsChildren
142
+ testID
149
143
} = props ;
150
144
151
145
const context = useContext ( TabBarContext ) ;
152
146
// @ts -ignore // TODO: typescript
153
147
const { itemStates, items : contextItems , currentPage, targetPage, registerTabItems, selectedIndex} = context ;
154
148
155
- const children = useRef < Props [ 'children' ] > ( _ . filter ( propsChildren , ( child : ChildProps ) => ! ! child ) ) ;
156
-
157
149
const _registerTabItems = ( ) => {
158
150
const ignoredItems : number [ ] = [ ] ;
159
- let itemsCount ;
160
-
161
- if ( propsItems ) {
162
- itemsCount = _ . size ( propsItems ) ;
163
- _ . forEach ( propsItems , ( item , index ) => {
164
- if ( item . ignore ) {
165
- ignoredItems . push ( index ) ;
166
- }
167
- } ) ;
168
- // TODO: deprecate with props.children
169
- } else {
170
- itemsCount = React . Children . count ( children . current ) ;
171
- // @ts -ignore TODO: typescript - not sure if this can be solved
172
- React . Children . toArray ( children . current ) . forEach ( ( child : ChildProps , index : number ) => {
173
- if ( child . props . ignore ) {
174
- ignoredItems . push ( index ) ;
175
- }
176
- } ) ;
177
- }
151
+ const itemsCount = _ . size ( propsItems ) ;
152
+ _ . forEach ( propsItems , ( item , index ) => {
153
+ if ( item . ignore ) {
154
+ ignoredItems . push ( index ) ;
155
+ }
156
+ } ) ;
178
157
179
158
registerTabItems ( itemsCount , ignoredItems ) ;
180
159
} ;
181
160
182
161
useEffect ( ( ) => {
183
- if ( propsChildren ) {
184
- LogService . warn ( 'uilib: Please pass the "items" prop to TabController.TabBar instead of children' ) ;
185
- }
186
-
187
- if ( ( propsItems || children . current ) && ! contextItems ) {
162
+ if ( propsItems && ! contextItems ) {
188
163
_registerTabItems ( ) ;
189
164
}
190
165
} , [ ] ) ;
@@ -196,7 +171,7 @@ const TabBar = (props: Props) => {
196
171
return contextItems || propsItems ;
197
172
} , [ contextItems , propsItems ] ) ;
198
173
199
- const itemsCount = useRef < number > ( items ? _ . size ( items ) : React . Children . count ( children . current ) ) ;
174
+ const itemsCount = useRef < number > ( _ . size ( items ) ) ;
200
175
201
176
const { scrollViewRef : tabBar , onItemLayout, itemsWidths, focusIndex} = useScrollToItem ( {
202
177
itemsCount : itemsCount . current ,
@@ -216,7 +191,11 @@ const TabBar = (props: Props) => {
216
191
return offsets ;
217
192
} , [ itemsWidths ] ) ;
218
193
219
- const _renderTabBarItems = useMemo ( ( ) : ReactNode => {
194
+ const renderTabBarItems = useMemo ( ( ) : ReactNode => {
195
+ if ( _ . isEmpty ( itemStates ) ) {
196
+ return null ;
197
+ }
198
+
220
199
return _ . map ( items , ( item , index ) => {
221
200
return (
222
201
< TabBarItem
@@ -239,6 +218,7 @@ const TabBar = (props: Props) => {
239
218
) ;
240
219
} ) ;
241
220
} , [
221
+ items ,
242
222
labelColor ,
243
223
selectedLabelColor ,
244
224
labelStyle ,
@@ -252,46 +232,6 @@ const TabBar = (props: Props) => {
252
232
onItemLayout
253
233
] ) ;
254
234
255
- // TODO: Remove once props.children is deprecated
256
- const _renderTabBarItemsFromChildren = useMemo ( ( ) : ReactNode | null => {
257
- return ! children . current
258
- ? null
259
- : React . Children . map ( children . current , ( child : Partial < ChildProps > , index : number ) => {
260
- // @ts -ignore TODO: typescript - not sure if this can be easily solved
261
- return React . cloneElement ( child , {
262
- labelColor,
263
- selectedLabelColor,
264
- labelStyle,
265
- selectedLabelStyle,
266
- uppercase,
267
- iconColor,
268
- selectedIconColor,
269
- activeBackgroundColor,
270
- ...child . props ,
271
- ...context ,
272
- index,
273
- state : itemStates [ index ] ,
274
- onLayout : centerSelected ? onItemLayout : undefined
275
- } ) ;
276
- } ) ;
277
- } , [
278
- labelColor ,
279
- selectedLabelColor ,
280
- labelStyle ,
281
- selectedLabelStyle ,
282
- uppercase ,
283
- iconColor ,
284
- selectedIconColor ,
285
- activeBackgroundColor ,
286
- itemStates ,
287
- centerSelected ,
288
- onItemLayout
289
- ] ) ;
290
-
291
- const renderTabBarItems = useMemo ( ( ) => {
292
- return _ . isEmpty ( itemStates ) ? null : items ? _renderTabBarItems : _renderTabBarItemsFromChildren ;
293
- } , [ itemStates , items , _renderTabBarItems , _renderTabBarItemsFromChildren ] ) ;
294
-
295
235
const _indicatorWidth = new Value ( 0 ) ; // TODO: typescript?
296
236
const _indicatorOffset = new Value ( 0 ) ; // TODO: typescript?
297
237
0 commit comments