react-native-snap-carousel: Infinite loop is not working using loop={true} enableSnap ={true} in android
Infinite loop is not working using loop={true} , enableSnap ={true} list is not scrolling infinte mode in android
Actual Behavior
i m displaying the list in card and the card is not scrolling in the infinite mode it get strucked in middle in android
Expected Behavior
Card should be scroll in the infinite mode while scrolling
Code
<Carousel
ref={c => {
this._carousel = c;
}}
carouselRef={this.props._slider1Ref}
data={this.props.data}
renderItem={this._renderItem}
sliderWidth={this.props.sliderWidth}
itemWidth={this.props.itemWidth}
loop={true}
loopClonesPerSide={this.props.loopClonesPerSide}
firstItem={this.props.firstItem}
onSnapToItem={index => this.onSnap(index)}
layout={this.props.layout}
layoutCardOffset={this.props.layoutCardOffset}
showSpinner={this.props.showSpinner}
activeSlideAlignment="start"
useScrollView={false}
activeSlideOffset={this.props.activeSlideOffset}
lockScrollWhileSnapping={true}
enableSnap={true}
enableMomentum={false}
activeSlideOffset={this.props.activeSlideOffset}
decelerationRate="fast"
// removeClippedSubviews={true}
removeClippedSubviews={false}
/>
Environment
“react-native”: “0.61.1”, “react-native-snap-carousel”: “^3.8.1”
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 2
- Comments: 45 (1 by maintainers)
Hi all, I have solved that issue in my app. sliderWidth and itemWidth must be integers.
<Carousel loop={true} data={products} renderItem={renderItem} inactiveSlideScale={1} inactiveSlideOpacity={1} sliderWidth={Math.round(deviceWidth)} itemWidth={Math.round(deviceWidth * 0.37)} />
This worked for me
@JoaoCEAlmeida In line number ~820 in Carousel.js file, we have this code -
if (nextActiveItem === this._itemToSnapTo && scrollOffset === this._scrollOffsetRef) { this._repositionScroll(nextActiveItem); }
So scrollOffset and this._scrollOffsetRef didn’t have same numbers after the decimal. Not sure what causes this. But truncating the decimal part of it before checking equality fixed this issue for me -
Math.trunc(scrollOffset) === Math.trunc(this._scrollOffsetRef)
.Hope this helps !
quick swipe will not work
I have created a video showing the inconsistency in loop behavior:
Inconsistent Looping
@ThatMate I am facing the same issue where the scroll stops to the right at 3rd slide during second loop. When we scroll to left, infinite scroll is working properly. Have you found any fix for it ?
comment out this line under Crousel.js return this._carouselRef && this._carouselRef.getNode && this._carouselRef.getNode();
Thanks me later!
I think I might be overreacting, it maybe just the standard issue in emulator as mentioned here: https://github.com/archriss/react-native-snap-carousel#important-note-regarding-android
I will have a check. Sorry for the noise.