Skip to content

Commit d205eb0

Browse files
committed
Fix TabController RTL support
1 parent 6628685 commit d205eb0

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/components/tabController/TabBar.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,16 +231,17 @@ class TabBar extends PureComponent {
231231
}
232232
};
233233

234-
onItemLayout = ({width, x}, itemIndex) => {
234+
onItemLayout = ({width}, itemIndex) => {
235235
this._itemsWidths[itemIndex] = width;
236-
this._itemsOffsets[itemIndex] = x;
237236
if (!_.includes(this._itemsWidths, null)) {
238237
this.setItemsLayouts();
239238
}
240239
};
241240

242241
setItemsLayouts = () => {
243242
const {selectedIndex} = this.context;
243+
// It's important to calculate itemOffsets for RTL support
244+
this._itemsOffsets = _.times(this._itemsWidths.length, (i) => _.chain(this._itemsWidths).take(i).sum().value());
244245
const itemsOffsets = _.map(this._itemsOffsets, (offset) => offset + INDICATOR_INSET);
245246
const itemsWidths = _.map(this._itemsWidths, (width) => width - INDICATOR_INSET * 2);
246247
this.contentWidth = _.sum(this._itemsWidths);

src/components/tabController/TabBarItem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export default class TabBarItem extends PureComponent {
127127
this.itemWidth = width;
128128
this.itemRef.current.setNativeProps({style: {width, paddingHorizontal: null, flex: null}});
129129
if (onLayout) {
130-
onLayout({width, x}, index);
130+
onLayout({width}, index);
131131
}
132132
}
133133
};

0 commit comments

Comments
 (0)