Skip to content

Commit

Permalink
fix: onTabChange called twice on Android (#1093)
Browse files Browse the repository at this point in the history
`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`
  • Loading branch information
bang9 authored Jul 24, 2020
1 parent 1371236 commit 9e58a54
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const ScrollableTabView = createReactClass({
ScrollableTabBar,
},
scrollOnMountCalled: false,
tabWillChangeWithoutGesture: false,

propTypes: {
tabBarPosition: PropTypes.oneOf(['top', 'bottom', 'overlayTop', 'overlayBottom', ]),
Expand Down Expand Up @@ -141,6 +142,7 @@ const ScrollableTabView = createReactClass({
}
} else {
if (this.scrollView) {
this.tabWillChangeWithoutGesture = true;
if (this.props.scrollWithoutAnimation) {
this.scrollView.setPageWithoutAnimation(pageNumber);
} else {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9e58a54

Please sign in to comment.