Skip to content

Commit 77e9de3

Browse files
committed
2 parents bffc165 + 110ae01 commit 77e9de3

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/components/tabController/TabBarItem.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,19 @@ export default class TabBarItem extends PureComponent {
106106
onPress: _.noop
107107
};
108108

109-
state = {};
110-
itemWidth = this.props.width;
111-
itemRef = React.createRef();
109+
constructor(props) {
110+
super(props);
111+
112+
this.itemWidth = this.props.width;
113+
this.state = {};
114+
this.itemRef = React.createRef();
115+
116+
if (this.itemWidth) {
117+
const {index, onLayout} = this.props;
118+
onLayout({width: this.itemWidth}, index);
119+
}
120+
}
121+
112122

113123
onStateChange = event([
114124
{
@@ -148,11 +158,11 @@ export default class TabBarItem extends PureComponent {
148158
opacity
149159
};
150160

151-
// if (this.itemWidth) {
152-
// style.flex = undefined;
153-
// style.width = this.itemWidth;
154-
// style.paddingHorizontal = undefined;
155-
// }
161+
if (this.props.width) {
162+
style.flex = undefined;
163+
style.width = this.itemWidth;
164+
style.paddingHorizontal = undefined;
165+
}
156166

157167
return style;
158168
}
@@ -234,7 +244,7 @@ export default class TabBarItem extends PureComponent {
234244
onPress={this.onPress}
235245
testID={testID}
236246
>
237-
{icon && <Reanimated.Image source={icon} style={[styles.tabItemIcon, this.getIconStyle()]}/>}
247+
{icon && <Reanimated.Image source={icon} style={[label && styles.tabItemIconWithLabel, this.getIconStyle()]}/>}
238248
{!_.isEmpty(label) && (
239249
<Reanimated.Text style={[styles.tabItemLabel, this.getLabelStyle()]}>
240250
{uppercase ? _.toUpper(label) : label}
@@ -257,7 +267,7 @@ const styles = StyleSheet.create({
257267
tabItemLabel: {
258268
...Typography.text80
259269
},
260-
tabItemIcon: {
270+
tabItemIconWithLabel: {
261271
marginRight: 10
262272
},
263273
badge: {

0 commit comments

Comments
 (0)