likashefqet / react-native-image-zoom

A performant and customizable image zoom component built with Reanimated v2+ and TypeScript. 🌃 🚀
https://www.npmjs.com/package/@likashefqet/react-native-image-zoom
MIT License
352 stars 46 forks source link

Feature Request: onSwipeDown handler? #64

Open IroncladDev opened 2 months ago

IroncladDev commented 2 months ago

This package saved my life. Huge thanks to the creator and all the contributors.

Is your feature request related to a problem? Please describe. The feature request isn't related to a necessary problem. It would be nice to have for better UX.

Describe the solution you'd like I want an onSwipeDown handler/callback I can pass to the component. A common use case of this feature is to close a dialog/modal with an image you're inspecting.

Describe alternatives you've considered I'm not super familiar with React Native just yet, so I'm not aware of any alternate solutions to cover this use case with

Additional context N/A

artem-bq commented 1 month ago

I'm also interested in this. The absence of this feature is what makes me look for an alternative package. Perhaps there is some approach (I need to implement closing the modal by swiping down)

keuvy commented 3 weeks ago

It is a feature that I would like too.

I achieved it this way, I hope it works for you:

import { ImageZoom } from '@likashefqet/react-native-image-zoom';
import { Animated } from 'react-native';
import { Directions, Gesture, GestureDetector } from 'react-native-gesture-handler';
import { runOnJS } from 'react-native-reanimated';

const [closable, setClosable] = useState(true);

const fling = Gesture.Fling()
    .direction(Directions.DOWN | Directions.UP)
    .onEnd((evt) => {
        if (closable) {
            runOnJS(router.back())();
        }
    });

return (
    <GestureDetector gesture={fling}>
        <Animated.View>
            <ImageZoom
                    uri={url}
                    isDoubleTapEnabled
                    doubleTapScale={3}
                    onPinchStart={() => {
                        if (setClosable) setClosable(false);
                    }}
                    onDoubleTap={(zoomType) => {
                        if (setClosable) setClosable(false);
                    }}
                    onResetAnimationEnd={(finished, values) => {
                        if (finished) {
                            setClosable(true);
                        }
                    }}
                />
        </Animated.View>
    </GestureDetector>
)