@@ -435,20 +435,38 @@ export default class extends Component {
435435 * @param {string } dir 'x' || 'y'
436436 */
437437 updateIndex = ( offset , dir , cb ) => {
438+ const state = this . state
438439 // Android ScrollView will not scrollTo certain offset when props change
439- const callback = ( ) => {
440+ const callback = async ( ) => {
440441 cb ( )
441442 if ( Platform . OS === 'android' ) {
442- this . state . index === 0 &&
443- this . scrollView . scrollTo ( { x : state . width , y : 0 , animated : false } )
444- this . state . index === this . state . total - 1 &&
445- this . scrollView . scrollTo ( {
446- x : state . width * this . state . total ,
447- animated : false
448- } )
443+ if ( this . state . index === 0 ) {
444+ this . props . horizontal
445+ ? this . scrollView . scrollTo ( {
446+ x : state . width ,
447+ y : 0 ,
448+ animated : false
449+ } )
450+ : this . scrollView . scrollTo ( {
451+ x : 0 ,
452+ y : state . height ,
453+ animated : false
454+ } )
455+ } else if ( this . state . index === this . state . total - 1 ) {
456+ this . props . horizontal
457+ ? this . scrollView . scrollTo ( {
458+ x : state . width * this . state . total ,
459+ y : 0 ,
460+ animated : false
461+ } )
462+ : this . scrollView . scrollTo ( {
463+ x : 0 ,
464+ y : state . height * this . state . total ,
465+ animated : false
466+ } )
467+ }
449468 }
450469 }
451- const state = this . state
452470 let index = state . index
453471 if ( ! this . internals . offset )
454472 // Android not setting this onLayout first? https://github.com/leecade/react-native-swiper/issues/582
0 commit comments