dev-yakuza / react-native-image-modal

the simple image modal for React Native
https://dev-yakuza.github.io/en/react-native/react-native-image-modal/
MIT License
551 stars 46 forks source link

ref.current.isOpen does not update to false when closed. #391

Closed felixchan closed 4 weeks ago

felixchan commented 1 month ago

When I drag the image to close (or push X), the state does not update to false.

 <ImageModal
                                            ref={imageRef}
                                            renderImageComponent={(props) => {
                                                console.log('IS OPEN', imageRef?.current?.isOpen)
                                                return (
                                                    <View
                                                        style={{
                                                            paddingTop: imageRef?.current?.isOpen ? 120 : 0,
                                                        }}
                                                    >
                                                        <FlexImage
                                                            source={{ uri }}
                                                            style={{
                                                                width: winWidth,
                                                            }}
                                                            width={winWidth}
                                                            loadingComponent={<Fragment />}
                                                            loadingMethod="progressive"
                                                        />
                                                    </View>
                                                )
                                            }}
                                        />
dev-yakuza commented 4 weeks ago

@felixchan Sorry for the late reply.

I investigated the issue. The problem is renderImageComponent function is called before updating the isOpen of ref.

To solve this, I have two options.

  1. Call the renderImageComponent function again after updating isOpen.
  2. Add the parameter named isOpen in the renderImageComponent.

I think the first option is not good because of the performance. So, I decide to add the parameter to the renderImageComponent.

I will do it asap.

If you have any opinions or idea, please let me know it.

Thanks.