From 57606d0219b37f535dbf33dcc6a52c8bedb67fcc Mon Sep 17 00:00:00 2001 From: budowski Date: Thu, 5 Dec 2024 18:22:19 +0100 Subject: [PATCH] Fix #2322 - swipe down to close media viewer (#2497) --- .../MediaViewer/MainMediaDisplay.js | 58 ++++++++++++++----- src/components/MediaViewer/MediaViewer.js | 1 + 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/components/MediaViewer/MainMediaDisplay.js b/src/components/MediaViewer/MainMediaDisplay.js index 1b9f0a056..e501e534e 100644 --- a/src/components/MediaViewer/MainMediaDisplay.js +++ b/src/components/MediaViewer/MainMediaDisplay.js @@ -6,8 +6,15 @@ import { } from "components/SharedComponents"; import { View } from "components/styledComponents"; import type { Node } from "react"; -import React, { useCallback, useMemo, useState } from "react"; +import React, { + useCallback, useMemo, useRef, useState +} from "react"; import { FlatList } from "react-native"; +import { + GestureHandlerRootView, + NativeViewGestureHandler, + PanGestureHandler +} from "react-native-gesture-handler"; import Photo from "realmModels/Photo"; import useDeviceOrientation from "sharedHooks/useDeviceOrientation.ts"; import useTranslation from "sharedHooks/useTranslation"; @@ -22,6 +29,7 @@ type Props = { // $FlowIgnore horizontalScroll: unknown, onDeletePhoto?: Function, + onClose?: Function, onDeleteSound?: Function, photos: Array<{ id?: number, @@ -43,12 +51,15 @@ const MainMediaDisplay = ( { horizontalScroll, onDeletePhoto = ( ) => undefined, onDeleteSound = ( ) => undefined, + onClose = ( ) => undefined, photos, sounds = [], selectedMediaIndex, setSelectedMediaIndex }: Props ): Node => { const { t } = useTranslation( ); + const panRef = useRef(); + const listRef = useRef(); const { screenWidth } = useDeviceOrientation( ); const [displayHeight, setDisplayHeight] = useState( 0 ); const [zooming, setZooming] = useState( false ); @@ -194,6 +205,15 @@ const MainMediaDisplay = ( { selectedMediaIndex ] ); + const onGestureEvent = useCallback( event => { + const { translationY, velocityY } = event.nativeEvent; + + if ( translationY > 50 && velocityY > 500 ) { + // Close media viewer on swipe up + onClose(); + } + }, [onClose] ); + return ( - + + + + + + + ); }; diff --git a/src/components/MediaViewer/MediaViewer.js b/src/components/MediaViewer/MediaViewer.js index fe36bcff1..f0069644a 100644 --- a/src/components/MediaViewer/MediaViewer.js +++ b/src/components/MediaViewer/MediaViewer.js @@ -124,6 +124,7 @@ const MediaViewer = ( { editable={editable} photos={photos} sounds={sounds} + onClose={onClose} selectedMediaIndex={selectedMediaIndex} horizontalScroll={horizontalScroll} setSelectedMediaIndex={setSelectedMediaIndex}