@@ -20,7 +20,6 @@ const {Code, Value, interpolate: _interpolate, interpolateNode, block, set} = Re
20
20
const interpolate = interpolateNode || _interpolate ;
21
21
22
22
const DEFAULT_HEIGHT = 48 ;
23
- const INDICATOR_INSET = Spacings . s4 ;
24
23
const DEFAULT_BACKGROUND_COLOR = Colors . white ;
25
24
26
25
const DEFAULT_LABEL_STYLE = {
@@ -40,6 +39,10 @@ export interface TabControllerBarProps {
40
39
* The list of tab bar items
41
40
*/
42
41
items ?: TabControllerItemProps [ ] ;
42
+ /**
43
+ * Whether the tabBar should be spread (default: true)
44
+ */
45
+ spreadItems ?: boolean ;
43
46
/**
44
47
* Tab Bar height
45
48
*/
@@ -60,6 +63,10 @@ export interface TabControllerBarProps {
60
63
* custom style for the selected indicator
61
64
*/
62
65
indicatorStyle ?: StyleProp < ViewStyle > ;
66
+ /**
67
+ * Whether the indicator should be wide (as the item)
68
+ */
69
+ wideIndicator ?: boolean ;
63
70
/**
64
71
* custom label style
65
72
*/
@@ -128,11 +135,13 @@ interface Props extends TabControllerBarProps, BaseComponentInjectedProps, Forwa
128
135
const TabBar = ( props : Props ) => {
129
136
const {
130
137
items : propsItems ,
138
+ spreadItems,
131
139
height,
132
140
enableShadow,
133
141
shadowStyle : propsShadowStyle ,
134
142
// minTabsForScroll,
135
143
indicatorStyle,
144
+ wideIndicator,
136
145
labelStyle,
137
146
selectedLabelStyle,
138
147
labelColor,
@@ -149,6 +158,7 @@ const TabBar = (props: Props) => {
149
158
children : propsChildren
150
159
} = props ;
151
160
161
+ const indicatorInset = wideIndicator ? 0 : Spacings . s4 ;
152
162
const context = useContext ( TabBarContext ) ;
153
163
// @ts -ignore // TODO: typescript
154
164
const { itemStates, items : contextItems , currentPage, targetPage, registerTabItems, selectedIndex} = context ;
@@ -307,7 +317,7 @@ const TabBar = (props: Props) => {
307
317
308
318
const selectedIndicator =
309
319
itemsWidths && itemsWidths . length > 0 ? (
310
- < Reanimated . View style = { [ styles . selectedIndicator , indicatorStyle , _indicatorTransitionStyle ] } />
320
+ < Reanimated . View style = { [ styles . selectedIndicator , { marginHorizontal : indicatorInset } , indicatorStyle , _indicatorTransitionStyle ] } />
311
321
) : undefined ;
312
322
313
323
const renderCodeBlock = _ . memoize ( ( ) => {
@@ -321,7 +331,7 @@ const TabBar = (props: Props) => {
321
331
nodes . push ( set ( _indicatorWidth ,
322
332
interpolate ( currentPage , {
323
333
inputRange : itemsWidths . map ( ( _v , i ) => i ) ,
324
- outputRange : itemsWidths . map ( v => v - 2 * INDICATOR_INSET )
334
+ outputRange : itemsWidths . map ( v => v - 2 * indicatorInset )
325
335
} ) ) ) ;
326
336
327
337
nodes . push ( Reanimated . onChange ( targetPage , Reanimated . call ( [ targetPage ] , focusIndex as any ) ) ) ;
@@ -339,7 +349,7 @@ const TabBar = (props: Props) => {
339
349
} , [ shadowStyle , containerWidth , containerStyle ] ) ;
340
350
341
351
const indicatorContainerStyle = useMemo ( ( ) => {
342
- return [ styles . tabBar , ! _ . isUndefined ( height ) && { height} , { backgroundColor} ] ;
352
+ return [ styles . tabBar , { flex : spreadItems ? 1 : undefined } , ! _ . isUndefined ( height ) && { height} , { backgroundColor} ] ;
343
353
} , [ height , backgroundColor ] ) ;
344
354
345
355
const scrollViewContainerStyle = useMemo ( ( ) => {
@@ -371,7 +381,8 @@ TabBar.displayName = 'TabController.TabBar';
371
381
TabBar . defaultProps = {
372
382
labelStyle : DEFAULT_LABEL_STYLE ,
373
383
selectedLabelStyle : DEFAULT_SELECTED_LABEL_STYLE ,
374
- backgroundColor : DEFAULT_BACKGROUND_COLOR
384
+ backgroundColor : DEFAULT_BACKGROUND_COLOR ,
385
+ spreadItems : true
375
386
376
387
// containerWidth: Constants.screenWidth
377
388
} ;
@@ -381,7 +392,6 @@ const styles = StyleSheet.create({
381
392
zIndex : 100
382
393
} ,
383
394
tabBar : {
384
- flex : 1 ,
385
395
height : DEFAULT_HEIGHT ,
386
396
flexDirection : 'row' ,
387
397
justifyContent : 'space-between'
@@ -400,7 +410,6 @@ const styles = StyleSheet.create({
400
410
left : 0 ,
401
411
width : 70 ,
402
412
height : 2 ,
403
- marginHorizontal : INDICATOR_INSET ,
404
413
backgroundColor : Colors . primary
405
414
} ,
406
415
containerShadow : {
0 commit comments