React-native-swiper: onIndexChanged not working when dynamic Push data in state

Created on 8 Jan 2019  路  2Comments  路  Source: leecade/react-native-swiper

Which OS ?

Android

Version

Which versions are you using:

"react-native-swiper": "^1.5.14",

react-native-cli: 2.0.1
react-native: 0.55.4

Expected behavior

when swiping the Img call the onIndexChanged function

Actual behavior

onIndexChanged not firing function

How to reproduce it>

** style={style.wrapper}
loop={false} showsPagination ={true}
renderPagination={renderPagination}
key={this.state.gallaryData.length}
onIndexChanged = {(index) => this.changeSlide(index)}
>
{data.map((item, key) => {
return (


)
})}

    </Swiper>**

-

Most helpful comment

@JPeer264 adding key={this.state.gallaryData.length} in swiper it's working Thnks.

All 2 comments

I think you have the same problem as me. I figured that the this.onLayout() is triggered once where your data has the length of 1. Which means the offset is an empty object.

I did a workaround. After I update my data I trigger following (make sure you created an ref to the Swiper component:

const layout = Dimensions.get('window');
const data = await newDate();

this.swiper.current.setState({
  index: 0, // or any other index
  total: data.length,
}, () => {
  this.swiper.current.onLayout({ nativeEvent: { layout } });
});

@JPeer264 adding key={this.state.gallaryData.length} in swiper it's working Thnks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

wrannaman picture wrannaman  路  3Comments

chetanparakh picture chetanparakh  路  3Comments

nomoreboredom picture nomoreboredom  路  3Comments

kliuj picture kliuj  路  3Comments