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

onClose, Carousel index jumps back to "currentIndex" defined in prop #365

Open
ndimatteo opened this issue Apr 24, 2020 · 4 comments
Open

Comments

@ndimatteo
Copy link

Steps to reproduce the behavior:
I'm explicitly defining the currentIndex based on state so that when an image is clicked it opens at that index. However, if you navigate to other images from the Modal and then close the Modal it "jumps" the index back to the one set from the state when initially opened, causing a brief image swap while the Modal fades out.

Expected behavior:
The index of the Carousel to remain the same onClose

Actual behavior:
Index "jumps" onClose, showing wrong image during modal closing animation.

wtf

@ndimatteo
Copy link
Author

Any chance you have some input on this @jossmac ? Would love to know what is going wrong here!

@ndimatteo
Copy link
Author

bump...

@linxianxi
Copy link

linxianxi commented Oct 22, 2020

I avoided the problem in this way

.react-images__positioner {
    transition: none !important;
  }

// if you used styled-components

const GlobalStyle = createGlobalStyle`
  .react-images__positioner {
    transition: none !important;
  }
`;

<>
  <GlobalStyle />
  <ModalGateway>
     ......
  </ModalGateway>
</>

@Abrikosa1
Copy link

Abrikosa1 commented Aug 4, 2022

.react-images__positioner {
transition: none !important;
}

Helped for me.

Else we can change currentIndex when navigate between images with onViewChange prop

const [currentIndex, setCurrentIndex] = useState(0);
...
<Carousel
 views={images}
 currentIndex={currentIndex}
 trackProps={{
   onViewChange: (index) => {
     setCurrentIndex(index);
   },
 }}
/>

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

3 participants