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

index value will be out of reange after updating the UseState #1368

Open
Ankush-Hegde opened this issue Feb 8, 2024 · 0 comments
Open

index value will be out of reange after updating the UseState #1368

Ankush-Hegde opened this issue Feb 8, 2024 · 0 comments

Comments

@Ankush-Hegde
Copy link

Which OS ?

Android

  • react-native-swiper v?

"react-native-swiper": "^1.6.0",

Expected behaviour

there are 3 buttons, when the button is clicked the "activeComponent " state is updated, it must update the index of the swiper based on the activeComponent state. and when we swipe it must work normally from the updated index.

Actual behaviour

swiper works normally in the beginning.
even the clicking on the button changes the index of the swiper.
But after clicking on the button if we swipe we get the unexpected behaviour.when we swipe we get the blank screen.whene we swipe again we will be jumped to the another screen etc.

How to reproduce it>

To help us, please fork this component, modify one example in examples folder to reproduce your issue and include link here.

const [activeComponent, setActiveComponent] = useState("teachingRequests");
<Pressable
onPress={() => {
setActiveComponentAndResetPage("zero");
}}
>

zero

<Pressable
onPress={() => {
setActiveComponentAndResetPage("one");
}}
>

one


<Pressable
onPress={() => {
setActiveComponentAndResetPage("two");
}}
>

two




<Swiper
showsButtons={false}
showsPagination={false}
loop={false}
horizontal={true}
index={
activeComponent === "zero"
? 0
: activeComponent === "one"
? 1
: 2
}
onIndexChanged={(index) => {
const components = [
"zero",
"one",
"two",
];

        console.log(index);
        console.log(components[index])

        setActiveComponent(components[index]);
        
        if (components[index] === "zero") {
          setCurrentPage(1);
          ZeroHandler(1);
        } else if (components[index] === "one") {
          setCurrentPage(1);
          OneHandler(1);
        } else if (components[index] === "two") {
          setCurrentPage(1);
          TwoHandler1);
        }
      }}
    >

Steps to reproduce

1.swipe to the last scrollview
2.then click on first button "zero"
3. then swipe u will get the blank screen
4. the console log of the index will be in negative and sometimes will be out of range as here the index must be 0,1,2 but it goes to 3, -1 , -2 etc
5. this is console log
LOG 1
LOG one
//above is the first right swipe
LOG 2
LOG two
//above is second right swipe
LOG 0
LOG zero
//above log is when clicked on zero button
LOG -1
LOG undefined
LOG 2
LOG two
//above log is when swiped right

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