@@ -59,7 +59,11 @@ class TabController extends Component {
59
59
/**
60
60
* When using TabController.PageCarousel this should be turned on
61
61
*/
62
- asCarousel : PropTypes . bool
62
+ asCarousel : PropTypes . bool ,
63
+ /**
64
+ * Pass for custom carousel page width
65
+ */
66
+ carouselPageWidth : PropTypes . number
63
67
} ;
64
68
65
69
static defaultProps = {
@@ -74,16 +78,21 @@ class TabController extends Component {
74
78
selectedIndex : this . props . selectedIndex ,
75
79
asCarousel : this . props . asCarousel ,
76
80
itemStates : [ ] ,
81
+ pageWidth : this . pageWidth ,
77
82
// animated values
78
83
targetPage : new Value ( this . props . selectedIndex ) ,
79
84
currentPage : new Value ( this . props . selectedIndex ) ,
80
- carouselOffset : new Value ( this . props . selectedIndex * Math . round ( Constants . screenWidth ) ) ,
85
+ carouselOffset : new Value ( this . props . selectedIndex * Math . round ( this . pageWidth ) ) ,
81
86
// // callbacks
82
87
registerTabItems : this . registerTabItems ,
83
88
onChangeIndex : this . props . onChangeIndex
84
89
} ;
85
90
}
86
91
92
+ get pageWidth ( ) {
93
+ return this . props . carouselPageWidth || Constants . screenWidth ;
94
+ }
95
+
87
96
registerTabItems = ( tabItemsCount , ignoredItems ) => {
88
97
const itemStates = _ . times ( tabItemsCount , ( ) => new Value ( State . UNDETERMINED ) ) ;
89
98
this . setState ( { itemStates, ignoredItems} ) ;
@@ -127,11 +136,11 @@ class TabController extends Component {
127
136
128
137
/* Page change by Carousel scroll */
129
138
onChange ( carouselOffset , [
130
- set ( isScrolling , lessThan ( round ( abs ( diff ( carouselOffset ) ) ) , round ( Constants . screenWidth ) ) ) ,
139
+ set ( isScrolling , lessThan ( round ( abs ( diff ( carouselOffset ) ) ) , round ( this . pageWidth ) ) ) ,
131
140
cond ( and ( not ( isAnimating ) ) , [
132
141
set ( currentPage ,
133
142
interpolate ( round ( carouselOffset ) , {
134
- inputRange : itemStates . map ( ( v , i ) => Math . round ( i * Constants . screenWidth ) ) ,
143
+ inputRange : itemStates . map ( ( v , i ) => Math . round ( i * this . pageWidth ) ) ,
135
144
outputRange : itemStates . map ( ( v , i ) => i )
136
145
} ) ) ,
137
146
set ( toPage , currentPage )
0 commit comments