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 errors

See original GitHub issue

Which OS

IOS

Version

Which versions are you using:

  • react-native-swiper 1.15.13
  • react-native v0.39

Expected behaviour

The onIndexChanged should return correct values

Actual behaviour

I’m currently moving from one swiper to another and by doing this, functionality is broken

 onIndexChanged={(index) => {
   console.log('index >>> ', index);
   this.setState({
      currentPage: index
   })
}}
'index >>> ', 1
'index >>> ', 2
'index >>> ', 0
'index >>> ', 3 // HERE JUMPS

ezgif-5-3c7d2a6856

jumps from 0 to 3, seems to try to continue from the value that was just before restarting the swiper


I have found other error scenarios

Examples:

ezgif-5-12ebc7eab1

in this case i have a fixed bottom view

let bottomView = <View style={{ flex: 0.08, backgroundColor: theme.colors.transparent }} />;


ezgif-5-b321244a31

In this case the bottom view only appear when last active dot comes in.

bottomView = null


I get the impression that every time the NEXT button appears and updates the ui, the swiper breaks

Example code:

buildOnboardingSteps(currentSection) {
  let { lastPage, title, baseText, swiperImages } = this.applyViewRenderValidations(currentSection);
  let bottomView = null; // Second Gif
  // let bottomView = <View style={{ flex: 0.08, backgroundColor: theme.colors.transparent }} />; // First gif

  if (this.state.currentPage === lastPage) {
    bottomView = (
      <TouchableOpacity style={[styles.bottomView]} onPress={() => { this.passToNextSection() }}>
        <Text style={[styles.baseText, styles.nextText]}>{'NEXT'}</Text>
      </TouchableOpacity>
    )
  }
  return (
    <Animatable.Image style={styles.container} source={undefined} animation={'slideInRight'} duration={500}>
      <View style={[styles.topView, styles.topViewAddItem]}>
        <Text style={styles.baseTitle}>{title}</Text>
        <Text style={styles.baseText}>{baseText}</Text>
        <Swiper
          style={styles.wrapper}
          activeDotColor={theme.colors.swiperDotColor}
          showsPagination={true}
          scrollsToTop={true}
          loop={false}
          onIndexChanged={(index) => {
            console.log('index >>> ', index);
            this.setState({
              currentPage: index
            })
          }}
        >
          {swiperImages}
        </Swiper>
      </View>
      {bottomView}
    </Animatable.Image>
  )
}

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:5
  • Comments:7

github_iconTop GitHub Comments

9reactions
wkoutrecommented, Nov 22, 2017

Using state, onIndexChange/setState, and index prop, AND giving the Swiper an explicit width prop that’s not falsy fixed this for me, as well.

handleSwipeIndexChange = index => {
    this.setState({ index });
  };
<Swiper
    autoplay={false}
    loop={false}
    removeClippedSubviews={false}
    dotColor={Colors.lightGray}
    activeDotColor={Colors.darkGray}
    onIndexChanged={this.handleSwipeIndexChange}
    height={250}
    width={WIDTH}
    index={this.state.index}
>
    {swipeableStuff}
</Swiper>
3reactions
jose920405commented, Nov 22, 2017

hi @chixpc123 .

I found a solution, but in a very unorthodox way.

Clearly, as is the code of my example, it should be enough for it to work, but I had to resort to 3 things:

  1. Use the basic prop index, so every time I was updating the index with the onIndexChange that value put it as the index prop of the swiper.

  2. Give it a width. As a direct prop in the swiper instead a width inside style. You can see it in Custom basic style & content.

  3. In my code the view container of the swiper had a paddingLeft I had to remove it and give the margins to the left to each child in the swiper

Read more comments on GitHub >

github_iconTop Results From Across the Web

OnSelectedIndexChanged error - MSDN - Microsoft
Hi guys. I am getting this error in my DDL. Could someone please help me with this? Compiler Error Message: CS1061: 'ASP.shopping_cart_aspx' ...
Read more >
C# ASP.Net - ListBox - onSelectedIndexChanged causes error
I am quite new to ASP.Net and I am trying to create a DataList on one of the pages, feed it from code...
Read more >
RadListBox OnSelectedIndexChanged JS Error - Telerik
OnSelectedIndexChanged does not fire an event at all and OnClientSelectedIndexChanged gives a JS error. I'm using the RadListBoxes to move ...
Read more >
Populating C1Combbox with Data Using the ... - GrapeCity
To populate the C1ComboBox with data once a specific index in the combo box has been selected, use the SelectedIndexChanged event like the...
Read more >
ASPxCallbackPanel - A script error occurs when calling ...
I have a page with a combo box on it. It is wrapped in an ASPxCallback panel. I reference the callback in the...
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