react-native-image-viewing icon indicating copy to clipboard operation
react-native-image-viewing copied to clipboard

When I chance the imageIndex the ImageView closes and opens again. why is this?

Open JcbPrn opened this issue 2 years ago • 7 comments

JcbPrn avatar Aug 25 '22 10:08 JcbPrn

same error. 改了源码,已经解决. 感谢提供这样的组件.

xclidongbo avatar Sep 05 '22 06:09 xclidongbo

Same here

swwintels avatar Sep 11 '22 04:09 swwintels

To prevent this from happening don't use the onImageIndexChange handler to set a state which is used on the imageIndex.

eg:

const [imageViewImageIndex, setImageViewImageIndex] = React.useState(0);
const [imageViewIsVisible, setImageViewIsVisible] = React.useState(false);

<ImageView
  imageIndex={imageViewImageIndex}
  visible={imageViewIsVisible}
  ...
/>

<Pressable
  onPress={() => {
    setImageViewImageIndex(index);
    setImageViewIsVisible(true);
  }}>
  <Image ...  />
</Pressable>

daankauwenberg avatar Oct 02 '22 07:10 daankauwenberg

I managed to bypass this by using two index states. The startIndex is used when you press an image, it will set the initial index and open the viewer, the imageIndex is used by the ImageView to update the index.

const [imageIndex, setImageIndex] = useState<number>(0); 
const [startIndex, setStartIndex] = useState<number|null>(null);
const showImageView = startIndex === 0 || !!startIndex;

 <ImageView
  images={[]}
  imageIndex={startIndex || 0}
  onImageIndexChange={setImageIndex}
  visible={showImageView}
  />

swiersyoram avatar Oct 27 '22 17:10 swiersyoram

any solution ??

same issue here..

Parmar-Bansi avatar Jul 18 '23 19:07 Parmar-Bansi

怎么改的

lively-krishnan avatar Jul 19 '23 07:07 lively-krishnan

image

sad to see this, you guys can just adjust this part in case to prevent remounting

XHFkindergarten avatar Jul 07 '24 07:07 XHFkindergarten