Skip to content

Commit 090fa21

Browse files
committed
in TabController use page carousel code only if asCarousel is true
1 parent c2b3d7d commit 090fa21

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/incubator/TabController/index.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,26 @@ class TabController extends Component {
7878
this.setState({itemStates, ignoredItems});
7979
};
8080

81+
getCarouselPageChangeCode() {
82+
const {asCarousel} = this.props;
83+
const {itemStates} = this.state;
84+
85+
if (asCarousel) {
86+
// Rounding on Android, cause it cause issues when comparing values
87+
const screenWidth = Constants.isAndroid ? Math.round(Constants.screenWidth) : Constants.screenWidth;
88+
89+
return _.times(itemStates.length, index => {
90+
return cond(eq(Constants.isAndroid ? round(this._carouselOffset) : this._carouselOffset, index * screenWidth), [
91+
set(this._currentPage, index)
92+
]);
93+
});
94+
}
95+
96+
return [];
97+
}
98+
8199
render() {
82100
const {itemStates, ignoredItems} = this.state;
83-
84-
// Rounding on Android, cause it cause issues when comparing values
85-
const screenWidth = Constants.isAndroid ? Math.round(Constants.screenWidth) : Constants.screenWidth;
86101

87102
return (
88103
<TabBarContext.Provider value={this.getProviderContextValue()}>
@@ -92,11 +107,7 @@ class TabController extends Component {
92107
{() =>
93108
block([
94109
// Carousel Page change
95-
..._.times(itemStates.length, index => {
96-
return cond(eq(Constants.isAndroid ? round(this._carouselOffset) : this._carouselOffset,
97-
index * screenWidth),
98-
[set(this._currentPage, index)]);
99-
}),
110+
...this.getCarouselPageChangeCode(),
100111
// TabBar Page change
101112
..._.map(itemStates, (state, index) => {
102113
return [

0 commit comments

Comments
 (0)