react-native-swiper icon indicating copy to clipboard operation
react-native-swiper copied to clipboard

Starts with last page, not First Page when set loop to true

Open devStar9211 opened this issue 6 years ago • 14 comments

Which OS ?

iOS

Version

Which versions are you using:

  • react-native-swiper v1.5.13
  • react-native v0.49.3

Expected behaviour

Starts with First Page.

Actual behaviour

When I set loop to true, it starts with first page, but after updating content of first page, it shows last page. When I set loop to false, no problem. I already looked at same issue when setting loop to true, but mine is not working either.

The first page has got RefreshControl with ScrollView. When RefreshControl is called, the Swiper gets back to last page.

devStar9211 avatar Feb 12 '18 17:02 devStar9211

me too,

windydang26 avatar Feb 23 '18 08:02 windydang26

I solved this problem by removing componentWillReceiveProps function. But I am not sure why this happens, anybody has got idea about this?

devStar9211 avatar Feb 23 '18 14:02 devStar9211

I ran into this issue while writing my own Custom pagination thingy. It has to do with a bug if the loop prop is set to true.

it renders the last screen briefly before switching over to the first. Really crappy. Here is a fix specific to how my custom component is configured. Maybe it will help others.

  renderPagination = (index, total, context) => {
    return (
      <CustomPagination
        index={index}
        total={total}
        context={context}
        handleSkip={this.handleSkip}
        handleNext={() =>
          // Stupid fix because the native loop implement is shitty/buggy
          index === total - 1
            ? context.scrollBy(-1 * (total - 1))
            : context.scrollBy(1)
        }
      />
    );
  };

Here is how I am using the component

  render() {
    return (
      <Swiper
        style={styles.wrapper}
        showsButtons={false}
        showsPagination={true}
        renderPagination={this.renderPagination}
        loop={false}>
        <SlideOne />
        <SlideTwo />
        <SlideThree />
      </Swiper>
    );
  }

As you can see I had to set the loop={false} to prevent that rendering issue but then used custom access to the context of the component to still get the loop effect. Hope this library is updated soon... Otherwise, I will rebuild without it in the future.

VolkRiot avatar Feb 27 '18 01:02 VolkRiot

Same issue here.

adouceur avatar Mar 01 '18 21:03 adouceur

Same issue. Need some help.

Elenionl avatar Mar 09 '18 07:03 Elenionl

me too!

ai4code avatar Mar 13 '18 02:03 ai4code

You should find this in .../node_modules/react-native-swiper/src/index.js

componentWillReceiveProps (nextProps) {
    if (!nextProps.autoplay && this.autoplayTimer) clearTimeout(this.autoplayTimer)
    this.setState(this.initState(nextProps, this.props.index !== nextProps.index))
}

plz remove this and try again, it will be run correctly.

devStar9211 avatar Mar 13 '18 02:03 devStar9211

this line is causing this behaviour this.setState(this.initState(nextProps, this.props.index !== nextProps.index))

Not sure what is purpose of calling initState in componentWillReceiveProps

AbhishekCode avatar Mar 15 '18 13:03 AbhishekCode

this bug is still there,does anyone know why?

guziyu001 avatar Jul 07 '18 07:07 guziyu001

You should find this in .../node_modules/react-native-swiper/src/index.js

componentWillReceiveProps (nextProps) {
    if (!nextProps.autoplay && this.autoplayTimer) clearTimeout(this.autoplayTimer)
    this.setState(this.initState(nextProps, this.props.index !== nextProps.index))
}

plz remove this and try again, it will be run correctly.

it is not use

shenwangjie avatar Sep 20 '19 06:09 shenwangjie

Same issue here

Yvette14 avatar Apr 02 '20 03:04 Yvette14

Considering this library has almost 9k stars, it boggles my mind that such a basic loop={true} feature isn't implemented correctly. Shame for such a library.

Djordjes995 avatar Apr 22 '20 14:04 Djordjes995

@Djordjes995 - tried this one coming from react-native-snap-carousel - which also doesn't work very well. Seems there is no industry standard open source library for such a basic component. I'm about to do it with just custom javascript and native React Native components at this point.

princefishthrower avatar Jul 27 '21 09:07 princefishthrower

Hi! i've met the same issue. i fixed it by changing slidesPerView from auto to a number. slidesPerView={'auto'} to slidesPerView={1.46}

Rexfortiz avatar Dec 15 '23 08:12 Rexfortiz