Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setState on onMomentumScrollEnd (or onIndexChanged) goes wrong at 2nd slide #850

Closed
yangnana11 opened this issue Aug 22, 2018 · 1 comment

Comments

@yangnana11
Copy link

Which OS ?

OS: macOS High Sierra 10.13.5

Version

Which versions are you using:
Node: 8.9.1
Yarn: 1.6.0
npm: 6.3.0
Watchman: 4.9.0
Xcode: Xcode 9.4.1 Build version 9F2000
Android Studio: 3.1 AI-173.4819257

react: 16.3.1 => 16.3.1
react-native: 0.55.1 => 0.55.1
react-native-swiper: "^1.5.13"

Expected behaviour

Get the current active index for a button outside of swiper

Actual behaviour

Every thing works fine except:

  • The 2nd slide (it shows 2nd slide -> last slide -> 3rd slide)
  • First dot becomes last slide

How to reproduce it>

Change the code of first Swiper (link: https://github.com/leecade/react-native-swiper/blob/master/examples/components/Swiper/index.js) to this

         <Swiper style={styles.wrapper} height={200} autoplay
                onMomentumScrollEnd={(e, state, context) => this.setState({index: state.index})}>
          <View style={styles.slide1}>
            <Text style={styles.text}>Hello Swiper</Text>
          </View>
          <View style={styles.slide2}>
            <Text style={styles.text}>Beautiful</Text>
          </View>
          <View style={styles.slide3}>
            <Text style={styles.text}>And simple</Text>
          </View>
          <View style={styles.slide1}>
              <Text style={styles.text}>4</Text>
          </View>
          <View style={styles.slide2}>
              <Text style={styles.text}>5</Text>
          </View>
          <View style={styles.slide3}>
              <Text style={styles.text}>6</Text>
          </View>
        </Swiper>

And the state construct:

constructor (props) {
    super(props);
    this.state={
      index: 0
    }
  }

Steps to reproduce

  1. Create Swiper as normal
  2. Add onMomentumScrollEnd
  3. Allow it to set state

image

If it is just console.log, nothing wrong, but once it set state, it goes wrong for any names

Please help,

Thanks

@yangnana11
Copy link
Author

I found the problem, it is cause of setState and loop={true} can't work together.
Duplicate to #569
Close this~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant