question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Infinite loop is not working using loop={true} enableSnap ={true} in android

See original GitHub issue

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”

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:43 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
Tejaswini-PDcommented, Aug 25, 2020

@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 !

9reactions
alextyshchenkocommented, Dec 24, 2021

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)} />

Read more comments on GitHub >

github_iconTop Results From Across the Web

infinite loop is not working using loop={true} , enableSnap ...
Go to node_modules/react-native-snap-carousel/src/carousel/Carousel.js and edit line 820 if (nextActiveItem === this.
Read more >
How to test that a function doesn't infinite loop - Elm Discourse
I have a bunch of functions designed for navigating a 2d grid: up, down, ... to run the function to ensure it doesn't...
Read more >
Loops in Java – Ultimate Guide - Funnel Garden
An infinite while loop will occur when the boolean condition is always true. This loop could still be broken out of if inside...
Read more >
Android Things Infinite Loop ( DIRECTION_IN ) - B4X
All work in DIRECTION_OUT_INITIALLY_LOW, but if i add DIRECTION_IN i have an infinite loop True - False. In summary Statechanged changes ...
Read more >
Infinite Loop in C - Javatpoint
Infinite Loop in C with Tutorial, C language with programming examples for beginners and professionals covering concepts, c array, c pointers, c structures, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found