From 21f097f0e6af21cbeb94e4ee355a4192cacf4da0 Mon Sep 17 00:00:00 2001 From: banklesss <105349292+banklesss@users.noreply.github.com> Date: Tue, 7 Nov 2023 15:42:43 +0100 Subject: [PATCH] fix(swap): modal swip down gesture (#2877) --- .../src/components/Modal/ModalContext.tsx | 11 +++++++++-- .../src/components/Modal/ModalScreen.tsx | 18 ++++++------------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/apps/wallet-mobile/src/components/Modal/ModalContext.tsx b/apps/wallet-mobile/src/components/Modal/ModalContext.tsx index 40ecc097f6..314c6fc6b6 100644 --- a/apps/wallet-mobile/src/components/Modal/ModalContext.tsx +++ b/apps/wallet-mobile/src/components/Modal/ModalContext.tsx @@ -3,6 +3,7 @@ import React from 'react' type ModalState = { height: number + isOpen: boolean title: string content: React.ReactNode } @@ -53,7 +54,13 @@ type ModalAction = const modalReducer = (state: ModalState, action: ModalAction) => { switch (action.type) { case 'open': - return {...state, content: action.content, height: action.height ?? defaultState.height, title: action.title} + return { + ...state, + content: action.content, + height: action.height ?? defaultState.height, + title: action.title, + isOpen: true, + } case 'close': return {...defaultState} @@ -63,4 +70,4 @@ const modalReducer = (state: ModalState, action: ModalAction) => { } } -const defaultState: ModalState = Object.freeze({content: undefined, height: 350, title: ''}) +const defaultState: ModalState = Object.freeze({content: undefined, height: 350, title: '', isOpen: false}) diff --git a/apps/wallet-mobile/src/components/Modal/ModalScreen.tsx b/apps/wallet-mobile/src/components/Modal/ModalScreen.tsx index 3d4d3846fe..8c4a7df543 100644 --- a/apps/wallet-mobile/src/components/Modal/ModalScreen.tsx +++ b/apps/wallet-mobile/src/components/Modal/ModalScreen.tsx @@ -16,22 +16,16 @@ import {useModal} from './ModalContext' export const ModalScreen = () => { const {current} = useCardAnimation() - const {height, closeModal, content} = useModal() + const {height, closeModal, content, isOpen} = useModal() const [swipeLocationY, setSwipeLocationY] = React.useState(height) - const [downDirectionCount, setDownDirectionCount] = React.useState(0) - - const cleanDirectionCount = () => { - setDownDirectionCount(0) - } const onResponderMove = ({nativeEvent}: GestureResponderEvent) => { - if (swipeLocationY < nativeEvent.locationY) { - const newState = downDirectionCount + 1 - if (newState > 4) { - closeModal() - cleanDirectionCount() - } else setDownDirectionCount(newState) + if (swipeLocationY < nativeEvent.locationY && isOpen) { + setSwipeLocationY(height) + closeModal() + return } + setSwipeLocationY(nativeEvent.locationY) }