Skip to content

Commit 362a6f2

Browse files
committed
update TabController underline transition, support tabbar item color transition
1 parent 75b76ee commit 362a6f2

File tree

3 files changed

+57
-16
lines changed

3 files changed

+57
-16
lines changed

src/components/tabController/TabBar.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class TabBar extends PureComponent {
5252
* custom label style
5353
*/
5454
labelStyle: RNText.propTypes.style,
55+
/**
56+
* custom selected label style
57+
*/
58+
selectedLabelStyle: RNText.propTypes.style,
5559
/**
5660
* the default label color
5761
*/
@@ -229,6 +233,7 @@ class TabBar extends PureComponent {
229233
labelColor,
230234
selectedLabelColor,
231235
labelStyle,
236+
selectedLabelStyle,
232237
uppercase,
233238
iconColor,
234239
selectedIconColor,
@@ -246,6 +251,7 @@ class TabBar extends PureComponent {
246251
labelColor={labelColor}
247252
selectedLabelColor={selectedLabelColor}
248253
labelStyle={labelStyle}
254+
selectedLabelStyle={selectedLabelStyle}
249255
uppercase={uppercase}
250256
iconColor={iconColor}
251257
selectedIconColor={selectedIconColor}
@@ -270,6 +276,7 @@ class TabBar extends PureComponent {
270276
labelColor,
271277
selectedLabelColor,
272278
labelStyle,
279+
selectedLabelStyle,
273280
uppercase,
274281
iconColor,
275282
selectedIconColor,

src/components/tabController/TabBarItem.js

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// TODO: support commented props
22
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';
44
import PropTypes from 'prop-types';
55
import _ from 'lodash';
66
import Reanimated from 'react-native-reanimated';
77
import {State} from 'react-native-gesture-handler';
8-
// import {interpolateColor} from 'react-native-redash';
8+
import {interpolateColor} from 'react-native-redash';
99
import {Colors, Typography, Spacings} from '../../style';
1010
import Badge from '../../components/badge';
1111
import {TouchableOpacity} from '../../incubator';
@@ -15,6 +15,18 @@ const {cond, eq, call, block, event, and, defined} = Reanimated;
1515
const DEFAULT_LABEL_COLOR = Colors.black;
1616
const DEFAULT_SELECTED_LABEL_COLOR = Colors.blue30;
1717

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+
1830
/**
1931
* @description: TabController's TabBarItem
2032
* @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 {
3244
* custom label style
3345
*/
3446
labelStyle: RNText.propTypes.style,
47+
/**
48+
* custom selected label style
49+
*/
50+
selectedLabelStyle: RNText.propTypes.style,
3551
/**
3652
* the default label color
3753
*/
@@ -111,7 +127,7 @@ export default class TabBarItem extends PureComponent {
111127
nativeEvent: {state: this.props.state}
112128
}
113129
],
114-
{useNativeDriver: true},);
130+
{useNativeDriver: true});
115131

116132
onLayout = ({
117133
nativeEvent: {
@@ -154,27 +170,45 @@ export default class TabBarItem extends PureComponent {
154170

155171
getLabelStyle() {
156172
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+
160192
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),);
165198

166199
// Animated color
167-
/* const color = interpolateColor(currentPage, {
200+
const color = interpolateColor(currentPage, {
168201
inputRange: [index - 1, index, index + 1],
169202
outputRange: [inactiveColor, activeColor, inactiveColor]
170-
}); */
203+
});
171204

172205
return [
206+
labelStyle,
173207
{
174208
fontWeight,
209+
letterSpacing,
175210
color
176-
},
177-
labelStyle
211+
}
178212
];
179213
}
180214

@@ -188,7 +222,7 @@ export default class TabBarItem extends PureComponent {
188222
// TODO: using processColor here broke functionality,
189223
// not using it seem to not be very performant
190224
activeColor,
191-
ignore ? activeColor : inactiveColor,);
225+
ignore ? activeColor : inactiveColor);
192226

193227
return {
194228
tintColor

src/components/tabController/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class TabController extends Component {
128128
cond(neq(currentPage, toPage), [
129129
set(isAnimating, 1),
130130
set(currentPage,
131-
timing({clock, from: fromPage, to: toPage, duration: 300, easing: Easing.bezier(0.34, 1.56, 0.64, 1)}))
131+
timing({clock, from: fromPage, to: toPage, duration: 300, easing: Easing.bezier(0.34, 1.3, 0.64, 1)}))
132132
]),
133133
// Set isAnimating flag off
134134
cond(and(eq(isAnimating, 1), not(clockRunning(clock))), set(isAnimating, 0)),

0 commit comments

Comments
 (0)