@@ -32,7 +32,8 @@ const {
32
32
block,
33
33
onChange,
34
34
interpolate,
35
- round
35
+ round,
36
+ multiply
36
37
} = Reanimated ;
37
38
38
39
/**
@@ -82,12 +83,28 @@ class TabController extends Component {
82
83
targetPage : new Value ( this . props . selectedIndex ) ,
83
84
currentPage : new Value ( this . props . selectedIndex ) ,
84
85
carouselOffset : new Value ( this . props . selectedIndex * Math . round ( this . pageWidth ) ) ,
86
+ containerWidth : new Value ( this . pageWidth ) ,
85
87
// // callbacks
86
88
registerTabItems : this . registerTabItems ,
87
89
onChangeIndex : this . props . onChangeIndex
88
90
} ;
89
91
}
90
92
93
+ static getDerivedStateFromProps ( nextProps , prevState ) {
94
+ if ( ! _ . isUndefined ( nextProps . carouselPageWidth ) && nextProps . carouselPageWidth !== prevState . pageWidth ) {
95
+ return {
96
+ pageWidth : nextProps . carouselPageWidth
97
+ } ;
98
+ }
99
+ return null ;
100
+ }
101
+
102
+ componentDidUpdate ( prevProps , prevState ) {
103
+ if ( prevState . pageWidth !== this . state . pageWidth ) {
104
+ this . state . containerWidth . setValue ( this . state . pageWidth ) ;
105
+ }
106
+ }
107
+
91
108
get pageWidth ( ) {
92
109
return this . props . carouselPageWidth || Constants . screenWidth ;
93
110
}
@@ -102,7 +119,7 @@ class TabController extends Component {
102
119
} ;
103
120
104
121
renderCodeBlock = ( ) => {
105
- const { itemStates, ignoredItems, currentPage, targetPage, carouselOffset} = this . state ;
122
+ const { itemStates, ignoredItems, currentPage, targetPage, carouselOffset, containerWidth } = this . state ;
106
123
const { selectedIndex} = this . props ;
107
124
const clock = new Clock ( ) ;
108
125
const fromPage = new Value ( selectedIndex ) ;
@@ -135,11 +152,11 @@ class TabController extends Component {
135
152
136
153
/* Page change by Carousel scroll */
137
154
onChange ( carouselOffset , [
138
- set ( isScrolling , lessThan ( round ( abs ( diff ( carouselOffset ) ) ) , round ( this . pageWidth ) ) ) ,
155
+ set ( isScrolling , lessThan ( round ( abs ( diff ( carouselOffset ) ) ) , round ( containerWidth ) ) ) ,
139
156
cond ( and ( not ( isAnimating ) ) , [
140
157
set ( currentPage ,
141
158
interpolate ( round ( carouselOffset ) , {
142
- inputRange : itemStates . map ( ( v , i ) => Math . round ( i * this . pageWidth ) ) ,
159
+ inputRange : itemStates . map ( ( v , i ) => round ( multiply ( i , containerWidth ) ) ) ,
143
160
outputRange : itemStates . map ( ( v , i ) => i )
144
161
} ) ) ,
145
162
set ( toPage , currentPage )
0 commit comments