0

In my application, I use the react-native-swiper component. Initially it worked properly, but recently it has a strange behaviour. It has 5 windows and it swipes like this. 5-1-2-3-4-5-1

it swipes 7 times and the items are like this. starts from the first one. I can swipe left once. Swipe right 5 times. Thats all.

How can I solve this issue? I use the version 1.5.6

import React from "react";
import { Dimensions } from "react-native";
import Swiper from "react-native-swiper";
import SwiperWindow from "../SwiperWindow/SwiperWindow";

const height = Dimensions.get("window").height * 0.3;

const swiperContainer = props => (
  <Swiper height={height} 
    showsButtons={true}
    showsPagination={false}>

    {props.featuredWorkouts.map(featuredWorkout => {
      return(
      <SwiperWindow
        key={featuredWorkout.featuredWorkoutId}
        imageSource={featuredWorkout.postImage}
        workoutTitle={featuredWorkout.title}
      />)
    })}
  </Swiper>
);

export default swiperContainer;
Shashika Virajh
  • 8,497
  • 17
  • 59
  • 103

3 Answers3

0

From this thread, https://github.com/leecade/react-native-swiper/issues/569,

It seems this problem could be solved by,


I observed that if call setState in parent component, componentWillReceiveProps of the swiper component gets triggered, and nextProps is exactly as the same as props of current swiper component. And further setState and initState of the swiper component get called, so the swiper state gets messed up.

I temporarily added if (nextProps.index === this.props.index) return; in componentWillReceiveProps to solve this issue.


and this solution is provided by HuiSF in this thread.

eisbehr
  • 12,243
  • 7
  • 38
  • 63
0

add key={allPins.length}. inside the Swiper as below and it worked for me

<Swiperkey={allPins.length}}>
</Swiper>

allPins.length here is nothing but dynamicArray.length.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
satish
  • 157
  • 1
  • 2
0
loop={false} will solve this as i had the same issue

there is a bug in swiper component when setting loop to true ,since there must me a "starting slide" prop

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 30 '22 at 02:28