When I chance the imageIndex the ImageView closes and opens again. why is this?
Opened this issue · 7 comments
JcbPrn commented
When I chance the imageIndex the ImageView closes and opens again. why is this?
xclidongbo commented
same error. 改了源码,已经解决. 感谢提供这样的组件.
swwintels commented
Same here
daankauwenberg commented
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>
swiersyoram commented
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}
/>
Parmar-Bansi commented
any solution ??
same issue here..
lively-krishnan commented
怎么改的
XHFkindergarten commented