React-native-swiper: Starts with last page, not First Page when set loop to true

Created on 12 Feb 2018  ·  12Comments  ·  Source: leecade/react-native-swiper

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.

Most helpful comment

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.

All 12 comments

me too,

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

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.

Same issue here.

Same issue.
Need some help.

me too!

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.

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

this bug is still there,does anyone know why?

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

Same issue here

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

agzuniverse picture agzuniverse  ·  3Comments

kylehagler picture kylehagler  ·  3Comments

tokict picture tokict  ·  3Comments

commit-master picture commit-master  ·  3Comments

gwhite-dayspring picture gwhite-dayspring  ·  3Comments