React-native-swiper: Swiper does not start at initial index, unless I set loop to false

Created on 18 Aug 2017  路  21Comments  路  Source: leecade/react-native-swiper

Which OS ?

iOS

Version

Which versions are you using: React 16.0.0-alpha.12

  • react-native-swiper v? 1.5.9
  • react-native v0.?.? 0.46.0

Expected behaviour

Upon launch, start at the first page

Actual behaviour

Upon launch, starts at the last page

How to reproduce it>

export default class App extends Component {
constructor(props) {
super(props);
this.state = {
};
}
render() {
return (



)
}
}
AppRegistry.registerComponent('AwesomeProject', () => App);

Steps to reproduce

1.Create App Component using the above code
2.Add styles variable from the README
3.Do not set the loop property

When I set Swiper loop={false}, there is no issue. In that case, it correctly starts at the initial page.

All 21 comments

@thesubway I ran into this too. This is indeed a bug. Do you have flex: 1 on the Swiper as a style? If so, try and remove it. That fixed it for me.

Do you still have the bug @thesubway ?
If yes, can you fork the project and reproduce the bug? I have not enough time to do it on my own.
Thanks

Here is an example of my issue, reproduced, where page 2 shows up first:
https://github.com/thesubway/IssueTester

I'm also experiencing a variant of this issue, except on initial render the index is fine but on subsequent renders, the last slide is shown even though the index is still 0. Setting loop to false fixes this, so I imagine there's something wrong with how offset is calculated in relation to looping.

It looks like this is the same bug than #570.
Can you try again with the last version released yesterday, 1.5.13.
This PR https://github.com/leecade/react-native-swiper/pull/572 has been merged and should fixed this bug.
If not, reopen this issue. Thanks!

its still not working on 1.5.13. does anyone have a fix ?

I don't know if it's exactly the same issue but when loop is set to TRUE and I reach the last slide : the old state is display (of the page) before displaying the current one which create a glitch.

I think the problem is located in the updateIndex method and more particularly in the setState method.

if (loopJump) {
      // when swiping to the beginning of a looping set for the third time,
      // the new offset will be the same as the last one set in state.
      // Setting the offset to the same thing will not do anything,
      // so we increment it by 1 then immediately set it to what it should be,
      // after render.
      if (offset[dir] === this.internals.offset[dir]) {
        newState.offset = { x: 0, y: 0 }
        newState.offset[dir] = offset[dir] + 1
        this.setState(newState, () => {                     <========== here
          this.setState({ offset: offset }, cb) 
        })
      } else {
        newState.offset = offset
        this.setState(newState, cb)
      }
    } else {
      this.setState(newState, cb)
    }

Here you can see what I mean. Changing something on the page scrolling left/right to come back and you see the glitch

Any ideas @leecade?

2014-10-22 11_35_09

init offset is set in onLayout function, and onLayout is not called when view update.
So, your problem was content loaded after page rendered, and all you layout was still set up as you have no children.
Quick work around: do not render swiper until all image loaded.

but still I think is fair to ask a swiper library to handle content update.

version 1.5.13 still not working. index changed to 0 but screen still is last screen.

@windydang26 Still not working for me either. I have just set loop to false, since looping isn't critical for me, and that fixes it, but it would be nice if we could find the solution. I believe it only happens upon touch events in which setState is called, as someone hinted to previously. If at index 0, when setState is called it remains at index 0 but displays the content of the final index. It also prevents you from swiping right (looping back to the final index) when this occurs. Then when you swipe left it returns to the proper display of the 0 index. Maybe that helps someone better understand the problem, not sure. But if looping isn't critical then turning it off is an easy fix

still can't work.help me

I think this issue should be re-opened. I am experiencing a similar issue:

  • it shows my second page briefly, then goes to my first page

Setting loop to false resolves the issue, but certainly isn't ideal.

I have the same bug on 1.5.13 version

same issue on 1.5.13 and 1.5.14

For me this issue occurs on second render. version 1.5.14. Doing something that triggers a render like pressing a button outside of this component makes it go from index 0 to last index.

Same here

Same Here

same here.
on ios , it wont swipe left at the first swipe.

same here

same here

Anyone find solution for this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kliuj picture kliuj  路  3Comments

diegolmello picture diegolmello  路  3Comments

wrannaman picture wrannaman  路  3Comments

gwhite-dayspring picture gwhite-dayspring  路  3Comments

AndrewSouthpaw picture AndrewSouthpaw  路  3Comments