react-native-anchor-carousel icon indicating copy to clipboard operation
react-native-anchor-carousel copied to clipboard

scrollToIndex not working correctly

Open Eya08 opened this issue 5 years ago • 1 comments

I have a large list of local images. when reaching 10 images I load 10 new ones. and I scrollToIndex(0). at first it works perfectly, but at the last list (<10 images) it doesn't scrollToIndex(0) but it still at the last one.


onPress={() => { this.loadmore(index); }}


loadmore= (ind) =>{

var nxt=ind+1

if(nxt<10 ){this._carousel.scrollToIndex(nxt);
  console.log("ind=",ind+1);

}

else{

console.log("EndReached ind=", nxt);
console.log("last_page",this.state.last_page);
    
    var j=this.state.last_page +10;

    this.setState({
      last_page:j      
    });
    
    if(j<long){
    this.setState({ animating: true})
    
    var temp = [];
    
    for (let i = j; i < long && i<j+10 ; ++i) {
      temp.push(Slidesdata[bab_id].images[i]);
      console.log('i=',i);
    }
    this.setState({
      data: temp,
            
    });
          console.log(temp);
    
    this.closeActivityIndicator();
    this._carousel.scrollToIndex({index:0});
    console.log("loaded");
  }

} }


<Carousel data={this.state.data} keyExtractor={(item, index) => index.toString()} renderItem={this._renderItem.bind(this)} itemWidth={wp('100%')} containerWidth={wp('100%')} itemContainerStyle={{height:hp('80%'),}} separatorWidth={0} ref={(c) => { this._carousel = c; }} initialIndex={0} initialScrollIndex={0} onScrollEnd={() => console.log("scrolling")} initialNumToRender={10}

        />

How to fix it?

Eya08 avatar Jul 19 '20 21:07 Eya08

puedes especificar un poco mas de lo que quieres para poder ayudarte

DanielSuarezDev avatar Aug 09 '21 17:08 DanielSuarezDev