Skip to content

Commit

Permalink
fix(swap): modal swip down gesture (#2877)
Browse files Browse the repository at this point in the history
  • Loading branch information
banklesss authored Nov 7, 2023
1 parent 6b24668 commit 21f097f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
11 changes: 9 additions & 2 deletions apps/wallet-mobile/src/components/Modal/ModalContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react'

type ModalState = {
height: number
isOpen: boolean
title: string
content: React.ReactNode
}
Expand Down Expand Up @@ -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}
Expand All @@ -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})
18 changes: 6 additions & 12 deletions apps/wallet-mobile/src/components/Modal/ModalScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 21f097f

Please sign in to comment.