leecade / react-native-swiper

The best Swiper component for React Native.
MIT License
10.42k stars 2.34k forks source link

Swiper calculating index incorrectly when children count changes #1060

Open fabcall opened 5 years ago

fabcall commented 5 years ago

Which OS ?

Both Android and iOS.

Version

Which versions are you using:

Expected behaviour

Expect the component to calculate the correct index.

Actual behaviour

The component wrongly updates the index.

How to reproduce it>

To help us, please fork this component, modify one example in examples folder to reproduce your issue and include link here.

Steps to reproduce

  1. Create a react-native-swiper with n children components and place some dot navigation markers.
  2. Swipe to the last component of the swiper.
  3. Update the swiper children with (n-1) components.
  4. The component will render correctly.
  5. Try to swipe back. The component will navigate accordingly, but the dots aren't updated correctly, because index is calculated wrongly.

Additional Notes

I've supposedly found the bug. I can make a PR if requested.

ipandz00 commented 5 years ago

Hi! Can you provide your PR or whatever have you changed in the package?

fabcall commented 5 years ago

For sure, its pretty simple to fix actually. In initState, find this:

this.internals = { ...this.internals, isScrolling: false };

And replace with this:

this.internals = { ...this.internals, offset: initState.offset, isScrolling: false };