From ba3ea0ef837d9ce484e1822e58a965b5879eb379 Mon Sep 17 00:00:00 2001 From: Jacky Zhen Date: Wed, 13 Mar 2019 14:40:58 +1300 Subject: [PATCH] fix tab not scrolled to correct position when index > 0 on android Because `contentOffset` on ScrollView is not implemented on android. See https://github.com/facebook/react-native/issues/6849 --- index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/index.js b/index.js index 64d6c5a1..fee9de0c 100644 --- a/index.js +++ b/index.js @@ -128,6 +128,17 @@ const ScrollableTabView = createReactClass({ return child.props.tabLabel + '_' + idx; }, + _handleContentSizeChange() { + this._handleContentSizeChange = null; + + if (Platform.OS === "android" && this.scrollView) { + const { currentPage, containerWidth } = this.state; + console.log(currentPage, containerWidth); + const offset = currentPage * this.state.containerWidth; + this.scrollView.scrollTo({x: offset, y: 0, animated: false }); + } + }, + renderScrollableContent() { const scenes = this._composeScenes(); return {scenes}