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 Gallery seems to break after removing the last image #161

Closed
DontBeEvilBen opened this issue Feb 2, 2022 · 1 comment
Closed

The Gallery seems to break after removing the last image #161

DontBeEvilBen opened this issue Feb 2, 2022 · 1 comment

Comments

@DontBeEvilBen
Copy link

DontBeEvilBen commented Feb 2, 2022

I have the gallery with a button to remove the current image off the list. It works well usually. if I remove any of images other than the last one, it automatically scrolls to the next one. But when I remove the nth item, it shows a blank gallery and the swipes don't work anymore, when there are other images on the list. There is no warning or error in the console.
I am using this with react native expo.

Sample code:

  const removeAsset = () => {
    let updatedListing = { ...listing };
    updatedListing.assets.splice(currentAsset, 1);
    setListing(updatedListing);

    let updatedIndex = currentAsset;
    if(updatedIndex == listing.assets.length) {
        updatedIndex = 0;
    } else {
        updatedIndex += 1;
    }

    setCurrentAsset(updatedIndex);
  };

....

 {
    listing.assets?.length > 0 ?
      <View style={styles.gallery}>
        <TransparentView style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', paddingHorizontal: 5 }}>
          <FontAwesome name="times-circle" size={20} color={Colors.purple} onPress={removeAsset} />
          <PoppinsText style={{ color: Colors.purple, fontSize: 10 }}>{currentAsset + 1 || 1} of {listing.assets?.length}</PoppinsText>
        </TransparentView>
        <Gallery style={{ height: 200 }} initialPage={currentAsset} images={listing.assets} onPageSelected={(index) => setCurrentAsset(index)} />
      </View>
      : null
  }
@DontBeEvilBen
Copy link
Author

I am able to fix this by using the gallery reference and scroll to a certain page in the gallery.
#125 (comment)

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