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

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

Open srichallamalla935 opened this issue 5 years ago • 45 comments

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"

srichallamalla935 avatar Oct 23 '19 12:10 srichallamalla935

Same thing happening for me. It is swipe first and last item.

alexaung avatar Oct 27 '19 15:10 alexaung

Did u got any solution for infinte loop in android ?? it important for me to work it on android

srichallamalla935 avatar Oct 28 '19 04:10 srichallamalla935

useScrollView={true}
firstItem={data.length}
initialScrollIndex={data.length}
getItemLayout={(data, index) => (
          {length: width, offset: width * index, index}
)}
horizontal={true}
loop={true}
loopClonesPerSide={data.length}
data={data.banners}

This worked for me

har2008preet avatar Nov 01 '19 07:11 har2008preet

@har2008preet ⚠️ I strongly advise against that because you're basically rendering thrice your data set. Meaning if you have 10 items in your data prop, you're now rendering 30 items all at once!

bd-arc avatar Nov 01 '19 11:11 bd-arc

@bd-arc noted. Will look for other option.

har2008preet avatar Nov 02 '19 12:11 har2008preet

@har2008preet Have you found another option for infinite loop?

Ericky14 avatar Nov 22 '19 23:11 Ericky14

Loop does not work in android. It either gets stuck or does some really odd index hopping resulting in some insane visuals.

TomJKlug avatar Jan 16 '20 22:01 TomJKlug

same issue

Yaolegol avatar Jan 30 '20 08:01 Yaolegol

same issue

qiaoyixuan avatar Feb 03 '20 06:02 qiaoyixuan

initialScrollIndex={this.props.store.banners.length-3}
                    firstItem={this.props.store.banners.length-3}
                    data={this.props.store.banners}

Working for me, without any overhead. How's this for a hack? @bd-arc 😄

har2008preet avatar Feb 10 '20 08:02 har2008preet

what does the number 3 mean?

发自我的iPhone

在 2020年2月10日,16:23,Harpreet Singh [email protected] 写道:

 initialScrollIndex={this.props.store.banners.length-3} firstItem={this.props.store.banners.length-3} data={this.props.store.banners} Working for me, without any overhead. How's this for a hack? @bd-arc 😄

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

qiaoyixuan avatar Feb 10 '20 15:02 qiaoyixuan

3 is the default loopClonePerSide value

har2008preet avatar Feb 10 '20 15:02 har2008preet

Same problem in Android

alessandrofc avatar Feb 12 '20 00:02 alessandrofc

Same problem in Android

Leehee1on avatar May 08 '20 09:05 Leehee1on

Same problem in Android

ghost avatar Jun 30 '20 15:06 ghost

I have similar experience. Loop works inconsistently.

  1. It stops at the end of the last item
  2. When you scroll back in the reverse direction after reaching to last item as in step # 1, the loop looks like working in both the direction

I think we need some attention to this issue.

ThatMate avatar Jul 24 '20 05:07 ThatMate

I have created a video showing the inconsistency in loop behavior:

Inconsistent Looping

ThatMate avatar Jul 24 '20 06:07 ThatMate

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.

ThatMate avatar Jul 24 '20 06:07 ThatMate

@ThatMate it might fix in the future release #678

har2008preet avatar Jul 24 '20 07:07 har2008preet

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

Tejaswini-PD avatar Aug 06 '20 03:08 Tejaswini-PD

@Tejaswini-PD I'm having the same problem as you. Did you find any work around?

Thanks in advance.

JoaoCEAlmeida avatar Aug 25 '20 13:08 JoaoCEAlmeida

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

Tejaswini-PD avatar Aug 25 '20 13:08 Tejaswini-PD

@Tejaswini-PD still doesn't work, the behavior is the same. But thanks for the help.

Can you share the props that you're passing to your carousel?

JoaoCEAlmeida avatar Aug 25 '20 14:08 JoaoCEAlmeida

@JoaoCEAlmeida These are the optional props I am using. Data, renderItem, etc are anyways needed. layout={‘default’} sliderWidth={SCREEN_WIDTH} itemWidth={SCREEN_WIDTH} loop autoplay inactiveSlideOpacity={1} inactiveSlideScale={1}

Tejaswini-PD avatar Aug 25 '20 14:08 Tejaswini-PD

@Tejaswini-PD what version are you currently using?

JoaoCEAlmeida avatar Aug 25 '20 14:08 JoaoCEAlmeida

@JoaoCEAlmeida I am using version 3.9.1

Tejaswini-PD avatar Aug 25 '20 17:08 Tejaswini-PD

@Tejaswini-PD Can't make it work, but thanks for the help.

JoaoCEAlmeida avatar Aug 26 '20 12:08 JoaoCEAlmeida

+1

JoaoCEAlmeida avatar Aug 26 '20 12:08 JoaoCEAlmeida

@ThatMate Did it work for you? I've tested in a real device and still does not work.

Thanks in advance.

JoaoCEAlmeida avatar Aug 26 '20 13:08 JoaoCEAlmeida

@Tejaswini-PD how many items are you showing on the screen? I'm showing 4. Can you test your version with 4 items? You just need to divide "itemWidth" prop by 4. image

JoaoCEAlmeida avatar Aug 27 '20 11:08 JoaoCEAlmeida