@@ -88,6 +88,7 @@ export default class Carousel extends BaseComponent {
88
88
89
89
if ( this . carousel ) {
90
90
this . carousel . current . scrollTo ( { x, animated} ) ;
91
+
91
92
if ( Constants . isAndroid ) {
92
93
// this is done to handle onMomentumScrollEnd not being called in Android:
93
94
// https://github.com/facebook/react-native/issues/11693
@@ -98,21 +99,32 @@ export default class Carousel extends BaseComponent {
98
99
}
99
100
100
101
goToPage ( pageIndex , animated = true ) {
101
- this . setState ( { currentPage : pageIndex } , ( ) => this . updateOffset ( animated ) ) ;
102
+ this . setState ( { currentPage : this . getCalcIndex ( pageIndex ) } , ( ) => this . updateOffset ( animated ) ) ;
103
+ }
104
+
105
+ getCalcIndex ( index ) {
106
+ // to handle scrollView index issue in Android's RTL layout
107
+ if ( Constants . isRTL && Constants . isAndroid ) {
108
+ const length = presenter . getChildrenLength ( this . props ) - 1 ;
109
+ return length - index ;
110
+ }
111
+ return index ;
102
112
}
103
113
104
114
onContentSizeChange = ( ) => {
115
+ // this is to handle initial scroll position (content offset)
105
116
if ( Constants . isAndroid ) {
106
117
this . updateOffset ( ) ;
107
118
}
108
119
}
109
120
110
- // finished full page scroll
111
121
onMomentumScrollEnd = ( ) => {
122
+ // finished full page scroll
112
123
const { currentStandingPage, currentPage} = this . state ;
113
- this . setState ( { currentStandingPage : currentPage } ) ;
114
- if ( currentStandingPage !== currentPage ) {
115
- _ . invoke ( this . props , 'onChangePage' , currentPage , currentStandingPage ) ;
124
+ const index = this . getCalcIndex ( currentPage ) ;
125
+ this . setState ( { currentStandingPage : index } ) ;
126
+ if ( currentStandingPage !== index ) {
127
+ _ . invoke ( this . props , 'onChangePage' , index , currentStandingPage ) ;
116
128
}
117
129
}
118
130
@@ -124,7 +136,7 @@ export default class Carousel extends BaseComponent {
124
136
125
137
const { loop} = this . props ;
126
138
const { pageWidth} = this . state ;
127
- const offsetX = presenter . getDirectionOffset ( event . nativeEvent . contentOffset . x , this . props , pageWidth ) ;
139
+ const offsetX = event . nativeEvent . contentOffset . x ;
128
140
129
141
if ( offsetX >= 0 ) {
130
142
const newPage = presenter . calcPageIndex ( offsetX , this . props , pageWidth ) ;
0 commit comments