1
1
// TODO: support commented props
2
2
import React , { PureComponent } from 'react' ;
3
- import { StyleSheet , processColor , Text as RNText } from 'react-native' ;
3
+ import { StyleSheet , /* processColor, */ Text as RNText } from 'react-native' ;
4
4
import PropTypes from 'prop-types' ;
5
5
import _ from 'lodash' ;
6
6
import Reanimated from 'react-native-reanimated' ;
7
7
import { State } from 'react-native-gesture-handler' ;
8
- // import {interpolateColor} from 'react-native-redash';
8
+ import { interpolateColor } from 'react-native-redash' ;
9
9
import { Colors , Typography , Spacings } from '../../style' ;
10
10
import Badge from '../../components/badge' ;
11
11
import { TouchableOpacity } from '../../incubator' ;
@@ -15,6 +15,18 @@ const {cond, eq, call, block, event, and, defined} = Reanimated;
15
15
const DEFAULT_LABEL_COLOR = Colors . black ;
16
16
const DEFAULT_SELECTED_LABEL_COLOR = Colors . blue30 ;
17
17
18
+ const DEFAULT_LABEL_STYLE = {
19
+ ...Typography . text80 ,
20
+ fontWeight : '400' ,
21
+ letterSpacing : 0
22
+ } ;
23
+
24
+ const DEFAULT_SELECTED_LABEL_STYLE = {
25
+ ...Typography . text80 ,
26
+ fontWeight : '700' ,
27
+ letterSpacing : 0
28
+ } ;
29
+
18
30
/**
19
31
* @description : TabController's TabBarItem
20
32
* @example : https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/componentScreens/TabControllerScreen/index.js
@@ -32,6 +44,10 @@ export default class TabBarItem extends PureComponent {
32
44
* custom label style
33
45
*/
34
46
labelStyle : RNText . propTypes . style ,
47
+ /**
48
+ * custom selected label style
49
+ */
50
+ selectedLabelStyle : RNText . propTypes . style ,
35
51
/**
36
52
* the default label color
37
53
*/
@@ -111,7 +127,7 @@ export default class TabBarItem extends PureComponent {
111
127
nativeEvent : { state : this . props . state }
112
128
}
113
129
] ,
114
- { useNativeDriver : true } , ) ;
130
+ { useNativeDriver : true } ) ;
115
131
116
132
onLayout = ( {
117
133
nativeEvent : {
@@ -154,27 +170,45 @@ export default class TabBarItem extends PureComponent {
154
170
155
171
getLabelStyle ( ) {
156
172
const { itemWidth} = this . state ;
157
- const { index, currentPage, labelColor, selectedLabelColor, labelStyle, ignore} = this . props ;
158
- const fontWeight = cond ( and ( eq ( currentPage , index ) , defined ( itemWidth ) ) , '700' , '400' ) ;
159
- const activeColor = selectedLabelColor || DEFAULT_SELECTED_LABEL_COLOR ;
173
+ const {
174
+ index,
175
+ currentPage,
176
+ targetPage,
177
+ labelColor,
178
+ selectedLabelColor,
179
+ ignore
180
+ } = this . props ;
181
+
182
+ const labelStyle = { ...DEFAULT_LABEL_STYLE , ...this . props . labelStyle } ;
183
+ const selectedLabelStyle = { ...DEFAULT_SELECTED_LABEL_STYLE , ...this . props . selectedLabelStyle } ;
184
+
185
+ const fontWeight = cond ( and ( eq ( targetPage , index ) , defined ( itemWidth ) ) ,
186
+ selectedLabelStyle . fontWeight ,
187
+ labelStyle . fontWeight ) ;
188
+ const letterSpacing = cond ( and ( eq ( targetPage , index ) , defined ( itemWidth ) ) ,
189
+ selectedLabelStyle . letterSpacing ,
190
+ labelStyle . letterSpacing ) ;
191
+
160
192
const inactiveColor = labelColor || DEFAULT_LABEL_COLOR ;
161
-
162
- const color = cond ( eq ( currentPage , index ) ,
163
- processColor ( activeColor ) ,
164
- processColor ( ignore ? activeColor : inactiveColor ) , ) ;
193
+ const activeColor = ! ignore ? selectedLabelColor || DEFAULT_SELECTED_LABEL_COLOR : inactiveColor ;
194
+
195
+ // const color = cond(eq(currentPage, index),
196
+ // processColor(activeColor),
197
+ // processColor(ignore ? activeColor : inactiveColor),);
165
198
166
199
// Animated color
167
- /* const color = interpolateColor(currentPage, {
200
+ const color = interpolateColor ( currentPage , {
168
201
inputRange : [ index - 1 , index , index + 1 ] ,
169
202
outputRange : [ inactiveColor , activeColor , inactiveColor ]
170
- }); */
203
+ } ) ;
171
204
172
205
return [
206
+ labelStyle ,
173
207
{
174
208
fontWeight,
209
+ letterSpacing,
175
210
color
176
- } ,
177
- labelStyle
211
+ }
178
212
] ;
179
213
}
180
214
@@ -188,7 +222,7 @@ export default class TabBarItem extends PureComponent {
188
222
// TODO: using processColor here broke functionality,
189
223
// not using it seem to not be very performant
190
224
activeColor ,
191
- ignore ? activeColor : inactiveColor , ) ;
225
+ ignore ? activeColor : inactiveColor ) ;
192
226
193
227
return {
194
228
tintColor
0 commit comments