Skip to content

Commit f6617be

Browse files
authored
Fix issue on Android+RTL with focusing selected item (#851)
1 parent 5f2e2d7 commit f6617be

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/components/tabController/TabBar.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,26 @@ class TabBar extends PureComponent {
219219
const itemWidth = this._itemsWidths[index];
220220
const screenCenter = this.containerWidth / 2;
221221

222+
let targetOffset;
223+
222224
if (itemOffset && itemWidth) {
223225
if (centerSelected) {
224-
this.tabBar.current.scrollTo({x: itemOffset - screenCenter + itemWidth / 2, animated});
226+
targetOffset = itemOffset - screenCenter + itemWidth / 2;
225227
} else if (itemOffset < this.tabBarScrollOffset) {
226-
this.tabBar.current.scrollTo({x: itemOffset - itemWidth, animated});
228+
targetOffset = itemOffset - itemWidth;
227229
} else if (itemOffset + itemWidth > this.tabBarScrollOffset + this.containerWidth) {
228230
const offsetChange = Math.max(0, itemOffset - (this.tabBarScrollOffset + this.containerWidth));
229-
this.tabBar.current.scrollTo({x: this.tabBarScrollOffset + offsetChange + itemWidth, animated});
231+
targetOffset = this.tabBarScrollOffset + offsetChange + itemWidth;
232+
}
233+
234+
if (!_.isUndefined(targetOffset)) {
235+
236+
if (Constants.isRTL && Constants.isAndroid) {
237+
const scrollingWidth = Math.max(0, this.contentWidth - this.containerWidth);
238+
targetOffset = scrollingWidth - targetOffset;
239+
}
240+
241+
this.tabBar.current.scrollTo({x: targetOffset, animated});
230242
}
231243
}
232244
};
@@ -254,6 +266,10 @@ class TabBar extends PureComponent {
254266
onScroll = ({nativeEvent: {contentOffset}}) => {
255267
const {fadeLeft, fadeRight} = this.state;
256268
this.tabBarScrollOffset = contentOffset.x;
269+
if (Constants.isRTL && Constants.isAndroid) {
270+
const scrollingWidth = Math.max(0, this.contentWidth - this.containerWidth);
271+
this.tabBarScrollOffset = scrollingWidth - this.tabBarScrollOffset;
272+
}
257273
const stateUpdate = {};
258274
// TODO: extract this logic to scrollbar presenter or something
259275
const leftThreshold = 50;

0 commit comments

Comments
 (0)