jobtoday/react-native-image-viewing

The image is in a zoom-in state when swiping back

cuongdo926 opened this issue · 7 comments

I used the code in the example. Step to produce:

  1. Image 1: zoom in and then zoom out
  2. Swipe to image 2
  3. Swipe back to image 1
  4. Image 1 is in a zoom-in state
    Expect: Image 1 is in a zoom-out/normal state.

I've had this issue too, is there any fix for it?

This project is awesome unless this bug🤦‍♂️
BTW if you swipe to image 3 then go back to image 1 then you find it in normal state.
*we can say it is an Android problem, since I tested it on 2 different iPhones and this issue did not happen.

@LimitedDani Thanks for taking the time to do this.

@LimitedDani Thanks bro, hope they evaluate your pull request and approve it soon!

same too.

in ImageItem.android.js:
replace initialScale: scale || 1, to initialScale: scale

in usePanResponder.js:
replace const scaleValue = new Animated.Value(initialScale);
to

    const scaleValue = useRef(new Animated.Value(initialScale ?? 0));
    const initialScaleRef = useRef(initialScale);

    useEffect(() => {
        if (initialScaleRef.current == null && initialScale != null) {
            initialScaleRef.current = initialScale;
            scaleValue.current.setValue(initialScale);
        }
    }, [initialScale]);

and add ".current" to all scaleValue