Skip to content

Commit

Permalink
Close modal on backdrop press (#340)
Browse files Browse the repository at this point in the history
Fixes #299
  • Loading branch information
jp30566347 authored May 6, 2024
1 parent 3366641 commit 8c1b2ea
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/components/modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isIOS } from '@consts'
import { useKeyboardCtx } from '@src/context/Keyboard'
import { useThemeContext } from '@src/context/Theme'
import { highlight as hi, HighlightKey, mainColors, Theme } from '@styles'
import { KeyboardAvoidingView, Modal, StyleSheet, View } from 'react-native'
import { KeyboardAvoidingView, Modal, StyleSheet, TouchableOpacity, TouchableWithoutFeedback, View } from 'react-native'
import { useSafeAreaInsets } from 'react-native-safe-area-context'

interface IMyModalProps {
Expand All @@ -12,6 +12,7 @@ interface IMyModalProps {
success?: boolean
hasNoPadding?: boolean
close?: () => void
onBackdropPress?: () => void
children: React.ReactNode
}

Expand All @@ -22,11 +23,12 @@ export default function MyModal({
success,
hasNoPadding,
close,
onBackdropPress,

Check warning on line 26 in src/components/modal/index.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'onBackdropPress' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 26 in src/components/modal/index.tsx

View workflow job for this annotation

GitHub Actions / build (21.x)

'onBackdropPress' is defined but never used. Allowed unused args must match /^_/u
children
}: IMyModalProps) {

const { color, highlight } = useThemeContext()
const { isKeyboardOpen} = useKeyboardCtx()
const { isKeyboardOpen } = useKeyboardCtx()
const insets = useSafeAreaInsets()

const getCorrectStyle = () => {
Expand Down Expand Up @@ -69,14 +71,22 @@ export default function MyModal({
onRequestClose={close}
testID='testCoinSelectionModal'
>
<KeyboardAvoidingView
style={getCorrectStyle()}
behavior={isIOS ? 'height' : undefined}
<TouchableOpacity
style={styles(color, highlight).modalContainer}
activeOpacity={1}
onPressOut={close}
>
<View style={[getViewStyle(), success ? { backgroundColor: hi[highlight] } : {}]}>
{children}
</View>
</KeyboardAvoidingView>
<KeyboardAvoidingView
style={getCorrectStyle()}
behavior={isIOS ? 'height' : undefined}
>
<TouchableWithoutFeedback>
<View style={[getViewStyle(), success ? { backgroundColor: hi[highlight] } : {}]}>
{children}
</View>
</TouchableWithoutFeedback>
</KeyboardAvoidingView>
</TouchableOpacity>
</Modal>
</View>
: null
Expand All @@ -92,6 +102,9 @@ const styles = (pref: Theme, h: HighlightKey) => StyleSheet.create({
left: 0,
backgroundColor: 'rgba(0, 0, 0, .5)',
},
modalContainer: {
flex: 1,
},
common: {
backgroundColor: pref.BACKGROUND,
alignItems: 'center',
Expand Down

0 comments on commit 8c1b2ea

Please sign in to comment.