pavelbabenko / react-native-awesome-gallery

Performant, native-like, and well-customizable gallery for React Native.
MIT License
468 stars 51 forks source link

fix: out of sync onIndexChange #30

Closed felippepuhle closed 3 years ago

felippepuhle commented 3 years ago

Description

We have a bug currently where the onIndexChange function is always binded to the first reference because it's not included on the useAnimatedReaction deps array, so the following code does not work as expected:

const [index, setIndex] = useState(0)

return (
  <Gallery
    data={images}
    initialIndex={index}
    onIndexChange={(newIndex) => {
      // will always show "0" even if we call the dispatcher on the following line
      console.log(index)
      setIndex(newIndex)
    }}
  />
);

We had the exact same bug on our project today (we're starting using this library), we added patch package for now (with the same change) and it's working now.

pavelbabenko commented 3 years ago

@felippepuhle Thanks for your pull request

pavelbabenko commented 3 years ago

v0.2.5 is released with your change

felippepuhle commented 3 years ago

Thanks for the quick merge/release! ❤️