question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onIndexChanged not called, wrong screen rendered

See original GitHub issue

Version

Which versions are you using:

  • react-native-swiper v1.5.8
  • react-native v0.47.1

Expected behavior

  1. onIndexChanged should be called when I swipe
  2. first View should be rendered as the first screen

Actual behavior

  1. not called
  2. third View (with “And simple” message) is rendered as first

Code example

export default class AppIntro extends PureComponent {

  onSwipe = (index) => {
    console.log('index changed', index);
  }

  render() {
    return (
      <Swiper style={styles.wrapper} onIndexChanged={this.onSwipe}>
        <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>
      </Swiper>
    );
  }
}

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:20
  • Comments:31 (1 by maintainers)

github_iconTop GitHub Comments

18reactions
lancesnidercommented, Jun 23, 2020

I know this is a really old thread, but I was having the same issue and none of the above solutions seemed to work… because it was just me being dumb. 🤦

tldr; you don’t appear to be able to change the number of slides on the fly my and on first render, I had zero.

My problem:

  • My slides were being created based on data from an API call.
  • The Slider existed before the API got its response

Basically I was creating a Swiper with zero slides, then a second later updating it with multiple slides. All I had to do was wait until I had the data to render the Swiper:

slides.length > 0 && (
          <Swiper
16reactions
milindagrawalcommented, Aug 23, 2017

If onIndexChanged is not working than try to use

            onMomentumScrollEnd={(event, state) => {
              this.setState({
                selectedIndex: state.index,
              });
            }}
Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native swiper not working in StackNavigator for IOS
I Have found the solution. Add removeClippedSubviews={false} props to swiper. Then It will work.
Read more >
Gridview's SelectedIndexChanged Event handler no longer ...
The ajax code is working, the selected row does highlight, ... but there is no longer a pop up details window when the...
Read more >
T90752 Blender popup windows open on the wrong screen
open on the wrong monitor while the main screen of blender opens on the primary. ... Fix T88552: Cycles changing Render Passes in...
Read more >
DataGrid controls display incorrectly in pages - ASP.NET
The data grid does not appear at all if: You do not set the DataSource property of the DataGrid control. Or. You do...
Read more >
react-native-swiper-ajusted - npm
There are no other projects in the npm registry using ... correct the wrong types #1000; Add missing scrollBy TypeScript definition #931.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found