1
1
import _ from 'lodash' ;
2
- import React , { PureComponent } from 'react' ;
3
- import { StyleSheet , Animated , Easing , LayoutChangeEvent , LayoutRectangle , StyleProp , ViewStyle , TextStyle } from 'react-native' ;
2
+ import React , { PureComponent , ReactElement } from 'react' ;
3
+ import {
4
+ StyleSheet ,
5
+ Animated ,
6
+ Easing ,
7
+ LayoutChangeEvent ,
8
+ LayoutRectangle ,
9
+ StyleProp ,
10
+ ViewStyle ,
11
+ TextStyle
12
+ } from 'react-native' ;
4
13
import { LogService } from '../../services' ;
5
14
import { Constants } from '../../helpers' ;
6
15
import { Colors , Typography , Spacings } from '../../style' ;
@@ -11,7 +20,6 @@ import Text from '../text';
11
20
import Image from '../image' ;
12
21
import Badge , { BadgeProps } from '../badge' ;
13
22
14
-
15
23
const INDICATOR_HEIGHT = 2 ;
16
24
const INDICATOR_BG_COLOR = Colors . primary ;
17
25
const HORIZONTAL_PADDING = Constants . isTablet ? Spacings . s7 : Spacings . s5 ;
@@ -42,6 +50,14 @@ export interface TabBarItemProps {
42
50
*/
43
51
badge ?: BadgeProps ; //TODO: remove after deprecation
44
52
badgeProps ?: BadgeProps ;
53
+ /**
54
+ * Pass to render a leading element
55
+ */
56
+ leadingAccessory ?: ReactElement ;
57
+ /**
58
+ * Pass to render a trailing element
59
+ */
60
+ trailingAccessory ?: ReactElement ;
45
61
/**
46
62
* maximum number of lines the label can break
47
63
*/
@@ -178,6 +194,8 @@ class TabBarItem extends PureComponent<TabBarItemProps, State> {
178
194
labelStyle,
179
195
badgeProps,
180
196
badge,
197
+ leadingAccessory,
198
+ trailingAccessory,
181
199
uppercase,
182
200
maxLines,
183
201
selectedLabelStyle,
@@ -193,9 +211,7 @@ class TabBarItem extends PureComponent<TabBarItemProps, State> {
193
211
194
212
const iconTint = iconColor || this . getColorFromStyle ( labelStyle ) || this . getColorFromStyle ( styles . label ) ;
195
213
const iconSelectedTint =
196
- iconSelectedColor ||
197
- this . getColorFromStyle ( selectedLabelStyle ) ||
198
- this . getColorFromStyle ( styles . selectedLabel ) ;
214
+ iconSelectedColor || this . getColorFromStyle ( selectedLabelStyle ) || this . getColorFromStyle ( styles . selectedLabel ) ;
199
215
const badgeFinalProps = badgeProps || badge ;
200
216
const badgeSize = _ . get ( badgeFinalProps , 'size' , 'small' ) ;
201
217
@@ -213,6 +229,7 @@ class TabBarItem extends PureComponent<TabBarItemProps, State> {
213
229
accessibilityLabel = { accessibilityLabel }
214
230
>
215
231
< View row flex center style = { [ showDivider && styles . divider , styles . contentContainer ] } >
232
+ { leadingAccessory }
216
233
{ icon && (
217
234
< Image
218
235
style = { ! _ . isEmpty ( label ) && styles . icon }
@@ -238,6 +255,7 @@ class TabBarItem extends PureComponent<TabBarItemProps, State> {
238
255
containerStyle = { [ styles . badge , badgeFinalProps . containerStyle ] }
239
256
/>
240
257
) }
258
+ { trailingAccessory }
241
259
</ View >
242
260
< Animated . View style = { [ { opacity : indicatorOpacity } , styles . indicator , indicatorStyle ] } />
243
261
</ TouchableOpacity >
@@ -247,7 +265,6 @@ class TabBarItem extends PureComponent<TabBarItemProps, State> {
247
265
248
266
export default asBaseComponent < TabBarItemProps > ( TabBarItem ) ;
249
267
250
-
251
268
const styles = StyleSheet . create ( {
252
269
contentContainer : {
253
270
paddingHorizontal : HORIZONTAL_PADDING
0 commit comments