Skip to content

Fix TabController issue on Android+RTL with focusing selected item #851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/components/tabController/TabBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,26 @@ class TabBar extends PureComponent {
const itemWidth = this._itemsWidths[index];
const screenCenter = this.containerWidth / 2;

let targetOffset;

if (itemOffset && itemWidth) {
if (centerSelected) {
this.tabBar.current.scrollTo({x: itemOffset - screenCenter + itemWidth / 2, animated});
targetOffset = itemOffset - screenCenter + itemWidth / 2;
} else if (itemOffset < this.tabBarScrollOffset) {
this.tabBar.current.scrollTo({x: itemOffset - itemWidth, animated});
targetOffset = itemOffset - itemWidth;
} else if (itemOffset + itemWidth > this.tabBarScrollOffset + this.containerWidth) {
const offsetChange = Math.max(0, itemOffset - (this.tabBarScrollOffset + this.containerWidth));
this.tabBar.current.scrollTo({x: this.tabBarScrollOffset + offsetChange + itemWidth, animated});
targetOffset = this.tabBarScrollOffset + offsetChange + itemWidth;
}

if (!_.isUndefined(targetOffset)) {

if (Constants.isRTL && Constants.isAndroid) {
const scrollingWidth = Math.max(0, this.contentWidth - this.containerWidth);
targetOffset = scrollingWidth - targetOffset;
}

this.tabBar.current.scrollTo({x: targetOffset, animated});
}
}
};
Expand Down Expand Up @@ -254,6 +266,10 @@ class TabBar extends PureComponent {
onScroll = ({nativeEvent: {contentOffset}}) => {
const {fadeLeft, fadeRight} = this.state;
this.tabBarScrollOffset = contentOffset.x;
if (Constants.isRTL && Constants.isAndroid) {
const scrollingWidth = Math.max(0, this.contentWidth - this.containerWidth);
this.tabBarScrollOffset = scrollingWidth - this.tabBarScrollOffset;
}
const stateUpdate = {};
// TODO: extract this logic to scrollbar presenter or something
const leftThreshold = 50;
Expand Down