Skip to content

Commit

Permalink
fix tab not scrolled to correct position when index > 0 on android
Browse files Browse the repository at this point in the history
Because `contentOffset` on ScrollView is not implemented on android. See facebook/react-native#6849
  • Loading branch information
jackyzhen committed Mar 13, 2019
1 parent 389a4cc commit 3aa7dd2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ const ScrollableTabView = createReactClass({
return child.props.tabLabel + '_' + idx;
},

_handleContentSizeChange() {
this._handleContentSizeChange = null;

if (Platform.OS === "android" && this.scrollView) {
const { currentPage, containerWidth } = this.state;
const offset = currentPage * this.state.containerWidth;
this.scrollView.scrollTo({x: offset, y: 0, animated: false });
}
},

renderScrollableContent() {
const scenes = this._composeScenes();
return <ScrollView
Expand All @@ -149,6 +159,7 @@ const ScrollableTabView = createReactClass({
directionalLockEnabled
alwaysBounceVertical={false}
keyboardDismissMode="on-drag"
onContentSizeChange={this._handleContentSizeChange}
{...this.props.contentProps}
>
{scenes}
Expand Down

0 comments on commit 3aa7dd2

Please sign in to comment.