From 9e58a54f04a210d9f5ffc21d125894c028367f3f Mon Sep 17 00:00:00 2001 From: "HYUNGU, KANG" Date: Fri, 24 Jul 2020 21:21:10 +0900 Subject: [PATCH] fix: onTabChange called twice on Android (#1093) `onPageSelected={this._updateSelectedPage}` ViewPager prop causes onTabChange to be called twice when change tabs without any gesture actions this will fix duplicated tab updates on android #### when user clicked tab buttons `goToPage -> updateSceneKeys(onTabChange) -> Screen Update -> onPageSelected={_updateSelectedPage} -> updateSceneKeys(onTabChange) -> Screen Update` #### when user swiped tab views `Swipe -> onPageSelected={_updateSelectedPage} -> updateSceneKeys(onTabChange) -> Screen Update` #### when user clicked tab buttons with this patch `goToPage -> set tabWillChangeWithoutGesture -> updateSceneKeys(onTabChange) -> Screen Update -> onPageSelected={_updateSelectedPage} -> ignore updateSceneKeys(onTabChange) -> remove tabWillChangeWithoutGesture` --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 36213dd8..5996ff71 100644 --- a/index.js +++ b/index.js @@ -32,6 +32,7 @@ const ScrollableTabView = createReactClass({ ScrollableTabBar, }, scrollOnMountCalled: false, + tabWillChangeWithoutGesture: false, propTypes: { tabBarPosition: PropTypes.oneOf(['top', 'bottom', 'overlayTop', 'overlayBottom', ]), @@ -141,6 +142,7 @@ const ScrollableTabView = createReactClass({ } } else { if (this.scrollView) { + this.tabWillChangeWithoutGesture = true; if (this.props.scrollWithoutAnimation) { this.scrollView.setPageWithoutAnimation(pageNumber); } else { @@ -305,10 +307,11 @@ const ScrollableTabView = createReactClass({ } const currentPage = this.state.currentPage; - this.updateSceneKeys({ + !this.tabWillChangeWithoutGesture && this.updateSceneKeys({ page: localNextPage, callback: this._onChangeTab.bind(this, currentPage, localNextPage), }); + this.tabWillChangeWithoutGesture = false; }, _onChangeTab(prevPage, currentPage) {