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

the dots were not changing when using map to display data #637

Open
bacancy-swaroopa opened this issue Oct 31, 2017 · 9 comments · May be fixed by #646
Open

the dots were not changing when using map to display data #637

bacancy-swaroopa opened this issue Oct 31, 2017 · 9 comments · May be fixed by #646

Comments

@bacancy-swaroopa
Copy link

Hi I am using your module and I wrote like this :


          <Swiper index={this.state.index} style={styles.swipe} autoplay={false} horizontal={true}
            dotColor="transparent"
            activeDotColor="transparent"
            onIndexChanged={(index) => {
              alert("hi")
              this.setState({
                index: index,
              })
            }}>
            {swiperList.map((res,i)=>{
              let durationMinutes = res.duration / 60
              let durationText
              if (durationMinutes < 1) {
                durationText = res.duration + ' sec'
              } else if (isNaN(durationMinutes)) {
                durationText = ''
              } else {
                durationText = durationMinutes + ' min'
              }
              return(
                <View style={styles.swiperView}>
                  <View style={styles.addRoutineMainCardViewMainMorning}>
                    <Thumbnail large source={{uri : 'https:'+res.backgroundImage.file.url , cache: 'force-cache'}} style={styles.routineCreatedCardlogoimage} />
                    <Thumbnail source={Images.createroutinetimeButton['morning']} style={styles.routineCreatedCardOverlayimage} />
                  </View>
                  <Text style={styles.swiperText}>{res.title}</Text>
                  <Text style={styles.swipertimetext}>{durationText}</Text>
                </View>
              )
            }
            )}
          </Swiper>

here when I swiper the onIndexChanged is not at all calling
And I did not use lopp but my data is showing twice
Can you tell me how to fix this..

@Tennen
Copy link

Tennen commented Oct 31, 2017

@bacancy-swaroopa loop is true by default,
I think you are trying to render swiperList from http request,
this is a bug, you cant change the number of children from <= 1 to > 1, otherwise onIndexChanged would never be triggered until next onLayout().
A simple way to solve this problem is to set a default array to swiperList, which length should be larger than 1.
if this cant solve your problem, you may try the way in my fork.

@bacancy-swaroopa
Copy link
Author

Hi
The swiper list arrray is of length 2
and the dots were not displaying corectly when I swipe

@kevindavee
Copy link

I got the same problem too. The dots were not moving while i'm swiping the pages. I also map the page from an array.

Please help. Thanks

@kevindavee
Copy link

renderSlides() {
        if(this.state.fetching) {
            this.fetchData()
        }

        const {slides} = this.state

        return(
            <Swiper style={[styles.wrapper]} showsButtons={false} loop={false}>
                {slides.map((slide, index) => {
                    return(
                        <View style={styles.slide1}>
                            <Text style={styles.titleText}>{slide.title}</Text>
                            <Text style={styles.descriptionText}>{slide.content}</Text>
                            <Image source={{ uri: slide.image }} style={{ width: IMAGE_WIDTH, height: IMAGE_HEIGHT }}/>
                        </View>
                    )
                })}
            </Swiper> 
        )
    }

    render() {
        return(
            <View style={{flex:1}}>    
                 {this.renderSlides()} 
            </View>
        )
    }

The above is my code

@controversialUser
Copy link

i had the same issue and solved it after seeing this post https://github.com/leecade/react-native-swiper/issues/635

@kevindavee
Copy link

I already solve my code issue. I remove the style tag from swiper and it works. I hope @bacancy-swaroopa can try and get the expected result as well.

Thanks !

@frankiewonghk
Copy link

I got the same issue and I solved it by the following code:

`class Slider extends Component{
componentWillMount(){
this.props.getSliderThunk();
}

render(){ 
    if(this.props.slider.length == 0){
        return(
        <View><Text>Loading...</Text></View>
        )
    }
    else{
        return(
            <View style={styles.container}>
                <Swiper style={styles.wrapper} loop={true}>
                { 
                    this.props.slider.map((item, key) => {
                        return (
                            <View key = { key } style = { styles.slide }>                             
                            <Image style={styles.slide_image} source = {{ uri: item.image }}/>
                            </View>
                        )
                    })
                }
                </Swiper>
            </View>
        );
    }
    
}

}`

@demogar
Copy link

demogar commented Aug 5, 2018

@frankiewonghk thanks man, this gave me an idea.

@andresihombing
Copy link

@frankiewonghk thanks bro, this is solve to me

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

Successfully merging a pull request may close this issue.

7 participants